GameData.ts 86 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491
  1. import Util from "../../before/util/Util";
  2. import LogUtil from "../../mk/utils/LogUtil";
  3. import FunBtns from "../game/FunBtns";
  4. import Game from "../game/Game";
  5. import { RateConfig } from "./AdData";
  6. import { StorageKey } from "./StorageData";
  7. /**
  8. * @description 游戏核心玩法数据
  9. * @author 邹勇
  10. */
  11. export class GameData {
  12. public dataFinish: boolean = false;
  13. public savePropFinish: boolean = false;
  14. public savePropsFinish: boolean = false;
  15. public getPropsFnish: boolean = false;
  16. //是否触摸屏幕
  17. public isTouchScreen: boolean = false;
  18. public configs: any = {};
  19. public adShowConfig: ADShowCfg;
  20. /** 功能开启 */
  21. public funOpenData: string[] = [];
  22. public playerProp: PlayerProp = null;
  23. /** 标志位:刷新主界面货币 */
  24. public init_coin: boolean = false;
  25. public addHb: number = 0;
  26. public updatePiggyBankValue: boolean = false;
  27. /** 标志位:刷新主界面头像 */
  28. public init_head: boolean = false;
  29. public init_add: boolean = false;
  30. /** 标志位:刷新主界面红点 */
  31. public init_red_point: boolean = true;
  32. //标志位,刷新提现界面的红包币
  33. public init_wallet_redMoney = false;
  34. /** 属性存储字典 */
  35. public props: Map<number, any> = new Map<number, any>();
  36. public pools = [
  37. { url: "game/prefab/tips", num: 20 },
  38. { url: "game/prefab/coin", num: 20 }
  39. ];
  40. /** 主页样式脚本 */
  41. public gameStyle: Game = null;
  42. /** 入口按钮 */
  43. public funBtns: FunBtns = null;
  44. /** 剩余可种植次数 */
  45. public leftTimes: number = -1;
  46. /** 最大可种植次数 */
  47. public maxTimes: number = -1;
  48. /** 恢复种植次数间隔 */
  49. public ProductionRecovery: number = 15;
  50. public init_leftTimes: boolean = false;
  51. /** 可生产商品配置 */
  52. public nextCanProduct = null;
  53. /** 按钮生产选中的农田、牧场或工厂 */
  54. public nextMake = null;
  55. /** 类型标识 */
  56. public nextType = 0;
  57. /** 刷新生产按钮信息 */
  58. public init_makeInfo = false;
  59. /** 正在生产 */
  60. public isProducting = false;
  61. /** 标志位 刷新任务描述 */
  62. public init_task = false;
  63. public init_expLevel = false;
  64. //标志位任务跟新
  65. public init_redBagTask = false;
  66. //标志位 生产奖励的任务ui刷新
  67. public init_productTask = false;
  68. public init_order = false;
  69. public init_speedup = false;
  70. 标志位
  71. public init_hideRedBag = false;
  72. public shareUrl = '';
  73. public shareTitle = '';
  74. public shareDes = '';
  75. public shareImgUrl = '';
  76. /** 生虫/生病/停电最多个数 */
  77. public RawInsectArr = [];
  78. /** 生虫/生病/停电当前个数 */
  79. public RawInsectCurArr = [0, 0, 0];
  80. //恢复生产次数
  81. public restoreProductTimes = 0;
  82. /** 最大可种植产品可更新到服务器标识 */
  83. public maxProductToServer = false;
  84. public authUIType = 0;
  85. public prohibiJBAd: string[] = [];
  86. public prohibitProductionAd: string[] = [];
  87. public productionAdMaxTimes = 20;
  88. public popTipCallBack: Function = null;
  89. public orderAinFinishNum = 0;
  90. public welfareOpenLimit = 0;
  91. public showRichBankIconLimit = 0;
  92. //富翁银行登陆增加参数
  93. richBankAddLoginDays = 0;
  94. //富翁银行教学
  95. richBankTeachTag = false;
  96. //订单奖励类型
  97. orderRewardType = 1;
  98. //提现X次后显示任务红包
  99. taskRedBagAutoShowLimit = 0;
  100. //提现x次后显示生虫
  101. insectAutoShowLimit = 0;
  102. public insertAdLimit = 0;
  103. public insertAdSwitch: string[] = [];
  104. /**
  105. * 初始化游戏数据:网络配置信息,用户信息
  106. * @returns
  107. */
  108. public async init() {
  109. let data: any = { "versionCode": gData.appData.version };
  110. let response = await mk.http.sendData('getAllConfigInfo', data);
  111. if (response.errcode != 0) {
  112. if (response.errcode == -10003 || response.errcode == -20003) {
  113. //清除缓存
  114. gData.loginData.reload();
  115. }
  116. return;
  117. }
  118. mk.console.logSingle("getAllConfigInfo", response.data);
  119. this.initConfigs(response.data);
  120. data = {};
  121. response = await mk.http.sendData('getInfoCrypt', data);
  122. if (response.errcode != 0) {
  123. return;
  124. }
  125. mk.console.logSingle("getInfoCrypt", response.data);
  126. this.initPlayerProp(response.data)
  127. this.initProps(response.data.gameUserData);
  128. if (gData.warnTipData.curSolution == 4) {
  129. if (response.data.isSystemRisk == 0) {
  130. //拉白后重置
  131. gData.warnTipData.setSolution(0);
  132. }
  133. }
  134. await this.uploadAverageEcpm();
  135. gData.adData.initEcpmData();
  136. // data = {};
  137. // response = await mk.http.sendData('noviceWeFare/getNoviceWeFareInfo', data);
  138. // if (response.errcode != 0) {
  139. // return;
  140. // }
  141. // this.playerProp.userTuCaoInfo = response.data.userWelFareTaskInfo;
  142. // mk.console.logSingle("welFare/getUserWelFareTaskInfo", response.data);
  143. gData.guideData.init();
  144. gData.guideWeakData.init();
  145. gData.moduleData.forEach(element => {
  146. element.init();
  147. });
  148. this.dataFinish = true;
  149. }
  150. public async uploadAverageEcpm(){
  151. let response = await mk.http.sendData('user/adShowConfig', {});
  152. if (response.errcode != 0) {
  153. return;
  154. }
  155. this.adShowConfig = response.data;
  156. mk.data.setTAEventUser(0, "average_ecpm", this.adShowConfig.average_ecpm);
  157. mk.console.logSingle("user/adShowConfig", response.data);
  158. }
  159. private initConfigs(data) {
  160. // console.log('config ', data);
  161. this.configs = data;
  162. this.funOpenData = this.configs.ServerConfig.Functionswitch.split(",");
  163. //从服务器解析配置
  164. this.setProductMapFromJson();
  165. gData.loginData.popIdentifySwitch = this.configs.ServerConfig.popIdentifySwitch.split(";");
  166. this.prohibiJBAd = this.configs.ServerConfig.ProhibitJBAd.split(";");
  167. this.prohibitProductionAd = this.configs.ServerConfig.ProhibitProductionAd.split(";");
  168. this.productionAdMaxTimes = this.configs.ServerConfig.ProductionAdMax;
  169. gData.gameData.shareUrl = this.configs.ServerConfig.shareUrl;
  170. gData.gameData.shareTitle = this.configs.ServerConfig.shareTitle;
  171. gData.gameData.shareDes = this.configs.ServerConfig.shareDes;
  172. gData.gameData.shareImgUrl = this.configs.ServerConfig.shareImgUrl;
  173. gData.gameData.RawInsectArr = this.configs.ServerConfig.RawInsect.split(',');
  174. //富翁银行
  175. gData.safeDepositBoxData.richBankConfig = this.configs.NewBankTask;
  176. gData.gameData.welfareOpenLimit = parseInt(this.configs.ServerConfig.welfareOpen);
  177. gData.gameData.showRichBankIconLimit = parseInt(this.configs.ServerConfig.bankIcon);
  178. console.log(`showRichBankIconLimit=====${gData.gameData.showRichBankIconLimit}`);
  179. let logSwitch = parseInt(this.configs.ServerConfig.logSwitch);
  180. if(logSwitch){
  181. LogUtil.ifShowLog = true;
  182. }else{
  183. LogUtil.ifShowLog = false;
  184. }
  185. gData.gameData.orderRewardType = parseInt(this.configs.ServerConfig.OrderReward);
  186. //gData.gameData.taskRedBagAutoShowLimit = parseInt(this.configs.ServerConfig.harvestSwitch);
  187. gData.gameData.insectAutoShowLimit = parseInt(this.configs.ServerConfig.StopProductionSwitch);
  188. gData.gameData.insertAdLimit = parseInt(this.configs.ServerConfig.InsertAdCash);
  189. gData.gameData.insertAdSwitch = this.configs.ServerConfig.InsertAdScene.split(",");
  190. }
  191. /**
  192. * 初始化玩家数据
  193. */
  194. private initPlayerProp(res_data) {
  195. this.playerProp = new PlayerProp();
  196. this.playerProp.cashIndex = res_data.cashIndex;
  197. this.playerProp.gameUserData = res_data.gameUserData;
  198. this.playerProp.isSignInToday = res_data.isSignInToday;
  199. this.playerProp.isWithdrawable = res_data.isWithdrawable;
  200. this.playerProp.lastTime = res_data.lastTime;
  201. this.playerProp.loginDays = res_data.loginDays;
  202. this.playerProp.newPlayer = res_data.newPlayer;
  203. this.playerProp.initPiggyBank(res_data.piggyBank);
  204. this.playerProp.piggyBankCashTimes = res_data.piggyBankCashTimes;
  205. this.playerProp.redMoney = res_data.redMoney == null ? 0 : res_data.redMoney;
  206. this.playerProp.signInDay = res_data.signInDay;
  207. this.playerProp.totalPiggyBankCashTimes = res_data.totalPiggyBankCashTimes;
  208. this.playerProp.turntableTimes = res_data.turntableTimes;
  209. this.playerProp.versioncfg = res_data.versioncfg;
  210. this.playerProp.isFirstRedMoney = res_data.isFirstRedMoney;
  211. gData.adData.watchNumToday = res_data.dayVideoTimesForRedMoney == null ? 0 : res_data.dayVideoTimesForRedMoney;
  212. console.log(`watchNumToday============${gData.adData.watchNumToday}`);
  213. this.playerProp.gradeLevel = res_data.farmLevel
  214. this.playerProp.userTuCaoInfo = res_data.userWelFareTaskInfo;
  215. this.playerProp.farmExpValue = res_data.userExp;
  216. this.playerProp.farmGradeData = res_data.userFarmGrageRewardInfo;
  217. this.playerProp.userNoviceWeFareInfo = res_data.userNoviceWeFareInfo;
  218. this.playerProp.redMoneyCashPayRecordList = res_data.redMoneyCashPayRecordList;
  219. this.playerProp.userFarmTaskInfo = res_data.userFarmTaskInfo;
  220. this.playerProp.speedUpLeftTimes = res_data.speedUpLeftTimes;
  221. this.playerProp.completeFarmTaskTimes = res_data.completeFarmTaskTimes;
  222. if(res_data.userOrderTaskInfo){
  223. this.playerProp.orderData = res_data.userOrderTaskInfo;
  224. console.log("============userOrderTaskInfo123");
  225. }
  226. this.playerProp.lineRedMoney = res_data.lineRedMoney;
  227. this.playerProp.groupCode = parseInt(res_data.groupCode);
  228. //this.playerProp.orderData.overTimes = 3;
  229. //this.cloneOrderData();
  230. this.playerProp.curProductionAdTimes = res_data.dailyProductionTimes;
  231. mk.data.setTAUserID(gData.loginData.uin);
  232. mk.data.setTAEventUser(0, 'logindays_total', this.playerProp.loginDays);
  233. if (this.playerProp.completeFarmTaskTimes == 0) {
  234. mk.data.setTAEventUser(0, 'Cumulative_task', gData.gameData.playerProp.completeFarmTaskTimes);
  235. }
  236. if (gData.loginData.isFirstIn) {
  237. gData.loginData.isFirstIn = false;
  238. mk.data.setTAEventRegister();
  239. mk.data.sendDataEvent('ABTest', `触发${this.playerProp.groupCode}方案`);
  240. console.log(`ABTest=====${this.playerProp.groupCode}`);
  241. //注册时版本号
  242. mk.data.setTAEventUserStr(0, 'regtime_app_id', gData.appData.appVersion);
  243. //星云uid
  244. mk.data.setTAEventUserStr(0, 'xy_uid', gData.loginData.uin);
  245. mk.data.setTAEventUser(0, 'farm_lv', gData.gameData.playerProp.gradeLevel);
  246. }
  247. //当前版本号
  248. mk.data.setTAEventUserStr(0, 'now_app_id', gData.appData.appVersion);
  249. //渠道号
  250. mk.data.setTAEventUserStr(0, 'channel_id', gData.appData.umengChannel);
  251. //富翁银行
  252. gData.safeDepositBoxData.richBankCashAmount = res_data.richBankCashAmount;
  253. if(res_data.currentRichBankCashTaskIndex){
  254. gData.safeDepositBoxData.currentRichBankCashTaskIndex = res_data.currentRichBankCashTaskIndex;
  255. console.log(`currentRichBankCashTaskIndex ======== ${res_data.currentRichBankCashTaskIndex}`);
  256. }
  257. //gData.safeDepositBoxData.addRichBankFinishIndex = res_data.addRichBankFinishIndex;
  258. // if (gData.safeDepositBoxData.currentRichBankCashTaskIndex > 0) {
  259. // gData.safeDepositBoxData.addRichBankFinishIndex = gData.safeDepositBoxData.currentRichBankCashTaskIndex;
  260. // }
  261. gData.safeDepositBoxData.isStartBankTask = res_data.isStartRichBankTask;
  262. gData.safeDepositBoxData.richBankDailyVideoTimes = res_data.richBankDailyVideoTimes;
  263. gData.safeDepositBoxData.richbankLoginDays = res_data.richbankLoginDays;
  264. gData.safeDepositBoxData.richBankDailyTotelVideoTimes = res_data.richBankDailyTotelVideoTimes;
  265. gData.safeDepositBoxData.richBankTotelLoginDays = res_data.richBankTotelLoginDays;
  266. console.log(`richBankDailyVideoTimes ======== ${res_data.richBankDailyVideoTimes}`);
  267. console.log(`richBankDailyTotelVideoTimes ======== ${res_data.richBankDailyTotelVideoTimes}`);
  268. // //test
  269. // this.playerProp.completeFarmTaskTimes = 3;
  270. }
  271. public cloneOrderData(isRefresh = false) {
  272. let value = mk.storage.getStorage(StorageKey.copyOrderData);
  273. if (value && !isRefresh) {
  274. this.playerProp.copyOrderData = [];
  275. let v = value.split(",");
  276. for (let i = 0; i != v.length; ++i) {
  277. this.playerProp.copyOrderData.push(parseInt(v[i]));
  278. }
  279. } else {
  280. let orderData = this.playerProp.orderData;
  281. if (orderData) {
  282. this.playerProp.copyOrderData = [];
  283. if (orderData && orderData.orderTaskList) {
  284. let len = orderData.orderTaskList.length;
  285. for (let i = 0; i != len; ++i) {
  286. this.playerProp.copyOrderData.push(this.playerProp.orderData.orderTaskList[i].completeCount);
  287. }
  288. mk.storage.setStorage(StorageKey.copyOrderData, this.playerProp.copyOrderData);
  289. }
  290. }
  291. }
  292. mk.console.logSingle('cloneOrderData', this.playerProp.copyOrderData);
  293. }
  294. public updateOrderTaskCopyData(id: number) {
  295. if (this.playerProp.orderData && this.playerProp.orderData.orderTaskList) {
  296. let productJson = this.configs.Product;
  297. let orderData = this.playerProp.orderData.orderTaskList;
  298. let len = orderData.length;
  299. for (let i = 0; i != len; ++i) {
  300. let dataE = orderData[i];
  301. if (dataE.Id <= productJson.length) {
  302. let productData = productJson[dataE.Id - 1];
  303. if (productData.picture == id) {
  304. this.playerProp.copyOrderData[i]++;
  305. mk.storage.setStorage(StorageKey.copyOrderData, this.playerProp.copyOrderData);
  306. break;
  307. }
  308. }
  309. }
  310. } else {
  311. this.playerProp.copyOrderData = [];
  312. cc.sys.localStorage.removeItem(StorageKey.copyOrderData);
  313. }
  314. }
  315. public setOrderAniFinishNum()
  316. {
  317. ++this.orderAinFinishNum;
  318. if(this.orderAinFinishNum >= 3){
  319. this.orderAinFinishNum = 0;
  320. setTimeout(() => {
  321. mk.event.emit("flyOrderAni");
  322. }, 500)
  323. }
  324. }
  325. /**
  326. * 保存单个数据
  327. */
  328. public async setProp(key: GameProp, value: any) {
  329. let data = {
  330. key: key + '',
  331. value: value
  332. };
  333. this.props.set(key, value);
  334. await mk.http.sendData('savePlayerProp', data);
  335. this.savePropFinish = true;
  336. }
  337. /**
  338. * 保存多个数据
  339. */
  340. public async setProps(arr: { key: GameProp, value: any }[]) {
  341. let needProp = {};
  342. for (let i = 0; i < arr.length; i++) {
  343. needProp[arr[i].key + ''] = arr[i].value;
  344. }
  345. let data = {
  346. needProp: needProp
  347. };
  348. for (let i = 0; i < arr.length; i++) {
  349. this.props.set(arr[i].key, arr[i].value);
  350. }
  351. await mk.http.sendData('saveAllPlayerProp', data);
  352. this.savePropsFinish = true;
  353. }
  354. /** 获取属性 */
  355. public getProp(key: GameProp): any {
  356. if (this.props == null) {
  357. return 0;
  358. }
  359. let value = this.props.get(key);
  360. return value;
  361. }
  362. /**
  363. * 向服务器请求所有属性后更新
  364. */
  365. public async getAllProps() {
  366. let response = await mk.http.sendData('getAllPlayerProp', {});
  367. if (response.errcode != 0) {
  368. return;
  369. }
  370. this.initProps(response.data);
  371. this.getPropsFnish = true;
  372. }
  373. private initProps(data) {
  374. if (data == null) {
  375. return;
  376. }
  377. for (let key in data) {
  378. this.props.set(parseInt(key), data[key]);
  379. }
  380. this.setFramDataMapByServer();
  381. this.setPastureDataMapByServer();
  382. this.setFactoryDataMapByServer();
  383. this.initProductTimes();
  384. this.initLeftTimes();
  385. this.initFarmMapGetRewardData();
  386. //this.initCashOutTimes();
  387. // let isNewTask = this.getProp(GameProp.redBagTaskRefresh);
  388. // if (isNewTask != undefined) {
  389. // this.init_redBagTask = isNewTask;
  390. // }
  391. }
  392. private initLeftTimes() {
  393. let lefttimes = this.getProp(GameProp.leftTimes);
  394. if (lefttimes == undefined) {
  395. this.leftTimes = parseInt(this.configs.ServerConfig.FreeProduction);
  396. this.setProp(GameProp.leftTimes, this.leftTimes);
  397. }
  398. else {
  399. this.leftTimes = lefttimes;
  400. }
  401. this.maxTimes = parseInt(this.configs.ServerConfig.ProductionMax);
  402. this.ProductionRecovery = parseInt(this.configs.ServerConfig.ProductionRecovery);
  403. // //test
  404. // this.leftTimes = 1;
  405. // this.maxTimes = 20;
  406. // this.ProductionRecovery = 1;
  407. }
  408. /** 增加减少生产次数
  409. * @param add 增减变量
  410. */
  411. public async changeLeftTimes(add, isIgnoreMaxTimes = false, isRefresh = true) {
  412. gData.gameData.leftTimes += add;
  413. if (add > 0 && !isIgnoreMaxTimes) {
  414. gData.gameData.leftTimes = (gData.gameData.leftTimes > gData.gameData.maxTimes ? gData.gameData.maxTimes : gData.gameData.leftTimes);
  415. }
  416. if (gData.gameData.leftTimes < 0) {
  417. gData.gameData.leftTimes = 0;
  418. }
  419. await gData.gameData.setProp(GameProp.leftTimes, gData.gameData.leftTimes);
  420. if (isRefresh) {
  421. gData.gameData.init_leftTimes = true;
  422. }
  423. }
  424. //图鉴领取数据
  425. private _farmMapRewardData = [];
  426. public getFarmMapRewardState(index) {
  427. if (index.i < this._farmMapRewardData.length) {
  428. if (index.j < this._farmMapRewardData[index.i].length) {
  429. return this._farmMapRewardData[index.i][index.j];
  430. }
  431. }
  432. return 1;
  433. }
  434. public setFarmMapRewardState(index, state) {
  435. if (index.i < this._farmMapRewardData.length) {
  436. if (index.j < this._farmMapRewardData[index.i].length) {
  437. this._farmMapRewardData[index.i][index.j] = state;
  438. this.setProp(GameProp.farmMapGetRewardData, this._farmMapRewardData);
  439. }
  440. }
  441. }
  442. private initFarmMapGetRewardData() {
  443. this._farmMapRewardData = this.getProp(GameProp.farmMapGetRewardData);
  444. if (!this._farmMapRewardData) {
  445. this._farmMapRewardData = [];
  446. }
  447. let needSync = false;
  448. let index = 0;
  449. this._productTypeMap.forEach((value, key) => {
  450. if (this._farmMapRewardData.length <= index) {
  451. let len = value.length;
  452. let arr = [];
  453. for (let i = 0; i != len; ++i) {
  454. arr.push(0);
  455. }
  456. this._farmMapRewardData.push(arr);
  457. needSync = true;
  458. } else {
  459. let data = this._farmMapRewardData[index];
  460. let len = value.length;
  461. for (let i = 0; i != len; ++i) {
  462. if (i >= data.length) {
  463. data.push(0);
  464. needSync = true;
  465. }
  466. }
  467. }
  468. ++index;
  469. });
  470. if (needSync) {
  471. this.setProp(GameProp.farmMapGetRewardData, this._farmMapRewardData);
  472. }
  473. }
  474. //提现次数
  475. public _cashOutTimes = 0;
  476. public initCashOutTimes() {
  477. let v = this.getProp(GameProp.cashOutTimes);
  478. if (v) {
  479. this._cashOutTimes = v;
  480. } else {
  481. this._cashOutTimes = 0;
  482. }
  483. }
  484. public addCashOutTimes() {
  485. this._cashOutTimes += 1;
  486. this.setProp(GameProp.cashOutTimes, this._cashOutTimes);
  487. }
  488. /** 是否是新用户 */
  489. public isNewPlayer(): boolean {
  490. let v = this.getProp(GameProp.newPlayer);
  491. return v == 0;
  492. }
  493. //*********** ================= 农场数据 ================== */
  494. /** 农田数据 服务器数据 */
  495. private _farmData = [];
  496. /** 农田字典 本地数据,方便操作*/
  497. private _farmDataMap: Map<number, any> = new Map();
  498. //刷新农田
  499. public needFreshArr = [];
  500. /** 随机获取可种植物品 */
  501. getRandomPlantConfig(out?: any) {
  502. let id = 0;
  503. let isNoHaveCurTab = true;
  504. let isNoAllComplete = false;
  505. let isOrderDataInvalid = false;
  506. let isMatchSuccess = false;
  507. let productType = [];
  508. let animalId = [];
  509. let data = this.playerProp.orderData;
  510. if (data) {
  511. let orderData = data.orderTaskList;
  512. let productJson = this.configs.Product;
  513. for (let i = 0; i != orderData.length; ++i) {
  514. let dataE = orderData[i];
  515. if (dataE.completeCount < dataE.taskCount) {
  516. if (dataE.Id <= productJson.length) {
  517. isNoAllComplete = true;
  518. let productData = productJson[dataE.Id - 1];
  519. if (productData.tab == ProductType.nzw) {
  520. let max = this.getMaxProductExtra(ProductType.nzw);
  521. if (max && productData.picture <= max) {
  522. id = productData.picture;
  523. isNoHaveCurTab = false;
  524. isMatchSuccess = true;
  525. this.nextType = 1;
  526. mk.console.logSingle("getRandomPlantConfig=>", id);
  527. break;
  528. }
  529. } else if (productData.tab == ProductType.dw) {
  530. animalId.push(productData.picture);
  531. } else {
  532. productType.push(productData.tab);
  533. }
  534. } else {
  535. isOrderDataInvalid = true;
  536. break;
  537. }
  538. }
  539. }
  540. if (!isMatchSuccess) {
  541. // let picId = this.doFarmMapDataCheck(0);
  542. // if (picId) {
  543. // id = picId;
  544. // } else
  545. {
  546. id = Util.rnd(10001, this.getMaxProductExtra(ProductType.nzw));
  547. this.nextType = 1
  548. }
  549. }
  550. } else {
  551. isOrderDataInvalid = true;
  552. // let picId = this.doFarmMapDataCheck(0);
  553. // if (picId) {
  554. // id = picId;
  555. // } else
  556. {
  557. id = Util.rnd(10001, this.getMaxProductExtra(ProductType.nzw));
  558. this.nextType = 1
  559. }
  560. }
  561. //选择逻辑处理
  562. if (isOrderDataInvalid) {
  563. return this.getProductMap(id);
  564. } else {
  565. if (isNoHaveCurTab) {
  566. if (isNoAllComplete) {
  567. let isHaveEmpty = false;
  568. for (let i = 0; i != productType.length; ++i) {
  569. let factoryIcon = gData.factorySystem.factoryIcons;
  570. let len = factoryIcon.length;
  571. for (var j = 0; j < len; j++) {
  572. let tab = this.getTabByConfigID(factoryIcon[j].configID);
  573. if (tab == productType[i] && factoryIcon[j].data.state == FactroyState.Empty) {
  574. isHaveEmpty = true;
  575. out.state = 1;
  576. break;
  577. }
  578. }
  579. }
  580. if (!isHaveEmpty) {
  581. for (let i = 0; i != animalId.length; ++i) {
  582. let pastureIcon = gData.pastureSystem.pastureIcons;
  583. let len = pastureIcon.length;
  584. for (var j = 0; j < len; j++) {
  585. if (pastureIcon[j].data.productID == animalId[i] && pastureIcon[j].data.state == PastureState.Empty) {
  586. isHaveEmpty = true;
  587. out.state = 2;
  588. break;
  589. }
  590. }
  591. }
  592. }
  593. if (isHaveEmpty) {
  594. return null;
  595. } else {
  596. return this.getProductMap(id);
  597. }
  598. } else {
  599. return this.getProductMap(id);
  600. }
  601. } else {
  602. return this.getProductMap(id);
  603. }
  604. }
  605. //id = Util.rnd(10001, this.getMaxProduct(ProductType.nzw));
  606. //return this.getProductMap(id);
  607. }
  608. getRandomPlantConfigExtra(out: any) {
  609. let id = 0;
  610. let cropArray = [];
  611. let factoryArray = [];
  612. let animalArray = [];
  613. let data = this.playerProp.orderData;
  614. if (data) {
  615. let orderData = data.orderTaskList;
  616. let productJson = this.configs.Product;
  617. for (let i = 0; i != orderData.length; ++i) {
  618. let dataE = orderData[i];
  619. if (dataE.completeCount < dataE.taskCount) {
  620. if (dataE.Id <= productJson.length) {
  621. let productData = productJson[dataE.Id - 1];
  622. if (productData.tab == ProductType.nzw) {
  623. let max = this.getMaxProductExtra(ProductType.nzw);
  624. if (max && productData.picture <= max) {
  625. cropArray.push(productData.picture);
  626. }
  627. } else if (productData.tab == ProductType.dw) {
  628. animalArray.push(productData.picture);
  629. } else {
  630. factoryArray.push(productData);
  631. }
  632. }
  633. }
  634. }
  635. //从三种类型随机选择逻辑
  636. let typeArr = [];
  637. let matchSuccessFactorys = null;
  638. let matchSuccessPastures = null;
  639. if (cropArray.length > 0) {
  640. typeArr.push(0);
  641. }
  642. if (factoryArray.length > 0) {
  643. matchSuccessFactorys = gData.factorySystem.isHaveEmptyFactory(factoryArray);
  644. if(matchSuccessFactorys.length > 0){
  645. typeArr.push(1);
  646. }
  647. }
  648. if (animalArray.length > 0) {
  649. matchSuccessPastures = gData.pastureSystem.isHaveEmptyPasture(animalArray);
  650. if(matchSuccessPastures.length > 0){
  651. typeArr.push(2);
  652. }
  653. }
  654. if(typeArr.length > 0)
  655. {
  656. let rand = mk.math.random(0, typeArr.length-1);
  657. let type = typeArr[rand];
  658. if (type == 0) {
  659. let randCrop = mk.math.random(0, cropArray.length-1);
  660. id = cropArray[randCrop];
  661. this.nextType = 1
  662. return this.getProductMap(id);
  663. } else if (type == 1) {
  664. let randFactory = mk.math.random(0, matchSuccessFactorys.length-1);
  665. let factory = matchSuccessFactorys[randFactory];
  666. this.nextCanProduct = this.getProductMap(factory.picture);
  667. this.nextMake = factory.key;
  668. this.nextType = 3;
  669. return this.nextMake;
  670. } else if (type == 2) {
  671. let randPasture = mk.math.random(0, matchSuccessPastures.length-1);
  672. let pasture = matchSuccessPastures[randPasture];
  673. this.nextCanProduct = this.getProductMap(pasture.data.productID);
  674. this.nextMake = pasture
  675. this.nextType = 2;
  676. return pasture;
  677. }
  678. }else
  679. {
  680. id = Util.rnd(10001, this.getMaxProductExtra(ProductType.nzw));
  681. this.nextType = 1
  682. return this.getProductMap(id);
  683. }
  684. } else {
  685. id = Util.rnd(10001, this.getMaxProductExtra(ProductType.nzw));
  686. this.nextType = 1
  687. return this.getProductMap(id);
  688. }
  689. }
  690. public doJudgeOrderLogic(out?: any) {
  691. let data = this.playerProp.orderData;
  692. if (data) {
  693. let orderData = data.orderTaskList;
  694. let productJson = this.configs.Product;
  695. for (let i = 0; i != orderData.length; ++i) {
  696. let dataE = orderData[i];
  697. if (dataE.completeCount < dataE.taskCount) {
  698. if (dataE.Id <= productJson.length) {
  699. let productData = productJson[dataE.Id - 1];
  700. if (productData.tab == ProductType.nzw) {
  701. continue;
  702. } else if (productData.tab == ProductType.dw) {
  703. let pastureIcon = gData.pastureSystem.pastureIcons;
  704. let len = pastureIcon.length;
  705. for (var j = 0; j < len; j++) {
  706. if (pastureIcon[j].data.productID == productData.picture && pastureIcon[j].data.state == PastureState.Empty) {
  707. out.state = 2;
  708. return;
  709. }
  710. }
  711. } else {
  712. let factoryIcon = gData.factorySystem.factoryIcons;
  713. let len = factoryIcon.length;
  714. for (var j = 0; j < len; j++) {
  715. let tab = this.getTabByConfigID(factoryIcon[j].configID);
  716. if (tab == productData.tab && factoryIcon[j].data.state == FactroyState.Empty) {
  717. out.state = 1;
  718. return;
  719. }
  720. }
  721. }
  722. }
  723. }
  724. }
  725. }
  726. }
  727. /** 随机获取可生产产品 */
  728. getRandomFactoryConfig(configID) {
  729. let tab = gData.gameData.getTabByConfigID(configID);
  730. let arr = this.getProductArrByType(tab);
  731. let max = this.getMaxProductExtra(tab);
  732. let canArr = [];
  733. let len = arr.length;
  734. for (var i = 0; i < len; i++) {
  735. if (arr[i].picture <= max) {
  736. canArr.push(arr[i].picture);
  737. if (arr[i].picture == max) {
  738. break;
  739. }
  740. }
  741. }
  742. let index = Util.rnd(0, canArr.length - 1);
  743. let id = canArr[index];
  744. return this.getProductMap(id);
  745. }
  746. public doFarmMapDataCheck(startIndex: number, isHaveEmpty?: any) {
  747. let value = 0;
  748. for (let key in ProductType) {
  749. if (startIndex <= value) {
  750. let max = this.getMaxProductExtra(ProductType[key]);
  751. if (max) {
  752. let list_data = this.getProductArrByType(ProductType[key]);
  753. for (let i = 0; i != list_data.length; ++i) {
  754. let picId = list_data[i].picture - 1;
  755. if (list_data[i].unlock == 1 && picId == max) {
  756. let state = this.getFarmMapRewardState(this.getIndex(list_data[i]));
  757. if (state == 0) {
  758. switch (ProductType[key]) {
  759. case ProductType.nzw:
  760. this.nextType = 1
  761. return picId;
  762. case ProductType.dw:
  763. {
  764. let pastureIconsData = gData.pastureSystem.pastureIcons;
  765. let len = pastureIconsData.length;
  766. for (let index = 0; index < len; index++) {
  767. if (pastureIconsData[index].data.state == PastureState.Empty) {
  768. if (isHaveEmpty && startIndex == value) {
  769. isHaveEmpty.state = true;
  770. }
  771. if (picId == pastureIconsData[index].data.productID) {
  772. this.nextCanProduct = this.getProductMap(pastureIconsData[index].data.productID);
  773. this.nextMake = pastureIconsData[index];
  774. this.nextType = 2;
  775. return picId;
  776. }
  777. }
  778. }
  779. }
  780. break;
  781. default:
  782. {
  783. let factoryIconsData = gData.factorySystem.factoryIcons;
  784. let len = factoryIconsData.length;
  785. for (let index = 0; index < len; index++) {
  786. if (factoryIconsData[index].data.state == FactroyState.Empty) {
  787. if (isHaveEmpty) {
  788. isHaveEmpty.state = true;
  789. }
  790. let tab = this.getTabByConfigID(factoryIconsData[index].configID);
  791. if (tab == ProductType[key]) {
  792. this.nextCanProduct = this.getProductMap(picId);
  793. this.nextMake = factoryIconsData[index];
  794. this.nextType = 3;
  795. return picId;
  796. }
  797. }
  798. }
  799. }
  800. break;
  801. }
  802. }
  803. }
  804. }
  805. }
  806. }
  807. ++value;
  808. }
  809. return null;
  810. }
  811. /** 自动生产选中下一个 */
  812. setNextProduct(sel = true) {
  813. if (this.nextMake) {
  814. return;
  815. }
  816. //-1无效,0:有空地,1:工厂有空位,2:饲养厂有空位
  817. let haveEmpty = { state: -1 };
  818. let next = gData.farmSystem.selectNextFarm(haveEmpty, sel);
  819. if (!next) {
  820. //订单随机种植此处可注释掉
  821. // if (haveEmpty.state == -1) {
  822. // this.doJudgeOrderLogic(haveEmpty);
  823. // }
  824. //let next1 = gData.pastureSystem.nextPasture(haveEmpty);
  825. let next1 = gData.pastureSystem.nextPastureExtra();
  826. if (!next1) {
  827. //let next2 = gData.factorySystem.nextFactory(haveEmpty);
  828. let next2 = gData.factorySystem.nextFactoryExtra();
  829. if (!next2) {
  830. this.nextType = 0;
  831. //gData.gameData.nextMake = null;
  832. }
  833. else {
  834. //this.nextType = 3;
  835. }
  836. }
  837. else {
  838. //this.nextType = 2;
  839. }
  840. }
  841. else {
  842. //this.nextType = 1;
  843. }
  844. this.init_makeInfo = true;
  845. }
  846. hasFirstCheck = false;
  847. firstCheckNext() {
  848. if (!this.hasFirstCheck && gData.farmSystem.farms.length >= 18
  849. && gData.pastureSystem.pastureIcons.length >= 3 && gData.factorySystem.factoryIcons.length >= 6) {
  850. this.hasFirstCheck = true;
  851. Util.objSortByKey(gData.farmSystem.farms, 'sortID');
  852. Util.objSortByKey(gData.pastureSystem.pastureIcons, 'sortID');
  853. Util.objSortByKey(gData.factorySystem.factoryIcons, 'sortID');
  854. gData.gameData.setNextProduct(false);
  855. }
  856. }
  857. async makeProduct() {
  858. let flyRed = true;
  859. switch (this.nextType) {
  860. case 0:
  861. //mk.tip.pop('农场已满,无法继续生产');
  862. //弹出收获、生虫、加速
  863. if (!this.checkCanHarvest()) {
  864. if (!this.checkCanClearSick()) {
  865. this.checkCanSpeedUp(true);
  866. }
  867. }
  868. flyRed = false;
  869. break;
  870. case 1:
  871. if(this.popSpeedUpByRate()){
  872. flyRed = false;
  873. }else{
  874. flyRed = await gData.farmSystem.btnMake();
  875. gData.adData.checkPopRed();
  876. }
  877. break;
  878. case 2:
  879. if(this.popSpeedUpByRate()){
  880. flyRed = false;
  881. }else{
  882. flyRed = await gData.pastureSystem.btnMake();
  883. gData.adData.checkPopRed();
  884. }
  885. break;
  886. case 3:
  887. if(this.popSpeedUpByRate()){
  888. flyRed = false;
  889. }else{
  890. flyRed = await gData.factorySystem.btnMake();
  891. gData.adData.checkPopRed();
  892. }
  893. break;
  894. }
  895. return flyRed;
  896. }
  897. public async updateNewTaskProgress(isNeedRefresh = false) {
  898. if (gData.gameData.funOpenData[4] == "0") {
  899. return false;
  900. }
  901. if (this.playerProp.userFarmTaskInfo) {
  902. let com = this.playerProp.userFarmTaskInfo.completeCount;
  903. let count = this.playerProp.userFarmTaskInfo.taskCount;
  904. if (com >= count) {
  905. if (!this.gameStyle.getIsCanGetOrderReward()) {
  906. mk.tip.pop('任务红包进度已满,快去提现');
  907. } else {
  908. mk.tip.pop("订单已完成,快领奖吧!");
  909. }
  910. return false;
  911. }
  912. }
  913. let data = {};
  914. let response = await mk.http.sendData('farmTask/updateUserFarmTaskInfo', data);
  915. mk.console.logSingle('refrehTask=>', response);
  916. if (response.errcode != 0) {
  917. return false;
  918. }
  919. gData.gameData.init_task = true;
  920. this.playerProp.userFarmTaskInfo = response.data.userFarmTaskInfo;
  921. if (this.playerProp.userFarmTaskInfo.completeCount >= this.playerProp.userFarmTaskInfo.taskCount) {
  922. //mk.ui.closeAllUI();
  923. //mk.guide.open(4);
  924. }
  925. // if (isNeedRefresh) {
  926. // gData.gameData.init_task = true;
  927. // }
  928. return true;
  929. }
  930. public setFarmDataMap(id, data, sendToServer = true) {
  931. this._farmDataMap.set(id, data);
  932. let len = this._farmData.length;
  933. for (var i = 0; i < len; i++) {
  934. if (this._farmData[i].id == id) {
  935. this._farmData[i].state = data.state;
  936. this._farmData[i].productID = data.productID;
  937. this._farmData[i].growSpan = data.growSpan;
  938. break;
  939. }
  940. }
  941. this.needFreshArr.push(id);
  942. //更新到服务器
  943. if (sendToServer) {
  944. this.freshSendToServer(1);
  945. }
  946. }
  947. public getFarmDataMap(id) {
  948. return this._farmDataMap.get(id);
  949. }
  950. /** 服务器数据设置到本地 */
  951. public setFramDataMapByServer() {
  952. this._farmData = this.getProp(GameProp.farmData);
  953. if (!this._farmData) {
  954. this._farmData = [];
  955. }
  956. let len = this._farmData.length;
  957. //新玩家初始化农田数据
  958. if (len < 18) {
  959. let id = 31000;
  960. let data = null;
  961. let unluckNum = parseInt(gData.gameData.configs.ServerConfig.unluckNum);
  962. for (var i = 0; i < 18; i++) {
  963. if (i < unluckNum) {
  964. data = { id: id, state: FarmState.Empty, productID: 0, growSpan: 0 };
  965. }
  966. else if (i == unluckNum) {
  967. data = { id: id, state: FarmState.CanUnlock, productID: 0, growSpan: 0 };
  968. }
  969. else {
  970. data = { id: id, state: FarmState.Lock, productID: 0, growSpan: 0 };
  971. }
  972. this._farmData.push(data);
  973. this._farmDataMap.set(id, data);
  974. id++;
  975. }
  976. //第一次初始数据
  977. // this.setMaxProduct(10003);
  978. //更新到服务器
  979. this.setProp(GameProp.farmData, this._farmData);
  980. }
  981. else {
  982. let sickTimes = 0;
  983. for (var i = 0; i < len; i++) {
  984. this._farmDataMap.set(this._farmData[i].id, this._farmData[i]);
  985. if (this._farmData[i].state == FarmState.Sick) {
  986. sickTimes++;
  987. }
  988. }
  989. this.RawInsectCurArr[0] = sickTimes;
  990. }
  991. //this.setMaxProduct(10003, true);
  992. }
  993. /** puduct配置数据 <picture, config> */
  994. private _productMap: Map<number, any> = new Map();
  995. /** puduct类型配置数据 <tab, 类型数组> */
  996. private _productTypeMap: Map<string, any> = new Map();
  997. /** 设置puduct配置数据 */
  998. public setProductMapFromJson() {
  999. let productJson = this.configs.Product;
  1000. // // 先用本地数据
  1001. // let productJson = gData.configData.configMap.get('product');
  1002. let len = productJson.length;
  1003. let product = null;
  1004. let tab = '';
  1005. let arr = [];
  1006. for (var i = 0; i < len; i++) {
  1007. product = productJson[i];
  1008. this._productMap.set(product.picture, product);
  1009. if (tab != product.tab) {
  1010. arr = [];
  1011. this._productTypeMap.set(product.tab, arr);
  1012. tab = product.tab;
  1013. }
  1014. arr.push(product);
  1015. }
  1016. }
  1017. /** 根据id获取单个数据 */
  1018. public getProductMap(id) {
  1019. return this._productMap.get(id);
  1020. }
  1021. /** 根据tab获取数组 */
  1022. public getProductArrByType(type: ProductType) {
  1023. return this._productTypeMap.get(type);
  1024. }
  1025. //根据tab获取最大id的数据
  1026. public getMaxProductDataByType(type: ProductType, id) {
  1027. let arr = this._productTypeMap.get(type);
  1028. let len = arr.length;
  1029. if (arr[len - 1].picture >= id) {
  1030. return this.getProductMap(id);
  1031. } else {
  1032. return null;
  1033. }
  1034. }
  1035. /** 产品生产/种植次数 服务器数据 */
  1036. private _productMakeTimesData: any = {};
  1037. /** 产品生产/种植次数 */
  1038. private _productMakeTimesMap: Map<number, number> = new Map();
  1039. //产品解锁最大id
  1040. private _productUnlockMaxId: Map<string, number> = new Map();
  1041. private initProductTimes() {
  1042. let needUpdate = false;
  1043. let value = this.getProp(GameProp.productMakeTimes);
  1044. if (!value) {
  1045. this._productMakeTimesData.makeTimes = [];
  1046. this._productMakeTimesData.productUnlockMaxId = new Map<string, number>();
  1047. this._productMakeTimesData.productUnlockMaxId.set(ProductType.nzw, 10003);
  1048. } else {
  1049. if (value instanceof Array) {
  1050. this._productMakeTimesData.makeTimes = value;
  1051. this._productMakeTimesData.productUnlockMaxId = new Map<string, number>();
  1052. this._productMakeTimesData.productUnlockMaxId.set(ProductType.nzw, 10003);
  1053. let len = value.length;
  1054. for (let i = 0; i != len; ++i) {
  1055. let data = value[i];
  1056. let config = this.getProductMap(data.id);
  1057. let v = this._productMakeTimesData.productUnlockMaxId.get(config.tab);
  1058. if (v) {
  1059. if (v < data.id) {
  1060. this._productMakeTimesData.productUnlockMaxId.set(config.tab, data.id);
  1061. }
  1062. } else {
  1063. this._productMakeTimesData.productUnlockMaxId.set(config.tab, data.id);
  1064. }
  1065. }
  1066. needUpdate = true;
  1067. } else {
  1068. this._productMakeTimesData.makeTimes = value.makeTimes;
  1069. this._productMakeTimesData.productUnlockMaxId = this.objToMap(JSON.parse(value.productUnlockMaxId));
  1070. }
  1071. }
  1072. let len = this._productMakeTimesData.makeTimes.length;
  1073. for (var i = 0; i < len; i++) {
  1074. this._productMakeTimesMap.set(this._productMakeTimesData.makeTimes[i].id, this._productMakeTimesData.makeTimes[i].times);
  1075. //this.setMaxProduct(this._productMakeTimesData.makeTimes[i].id);
  1076. }
  1077. let isUpdate = this.judgeAddExtraUnlockMaxId();
  1078. if (needUpdate || isUpdate) {
  1079. this.updateDataToSever();
  1080. }
  1081. }
  1082. async addProductMakeTimesById(id: number) {
  1083. let isAddMaxProduct = false;
  1084. let times = this._productMakeTimesMap.get(id);
  1085. if (!times) {
  1086. times = 0;
  1087. }
  1088. times++;
  1089. this._productMakeTimesMap.set(id, times);
  1090. //更新到服务器
  1091. let has = false;
  1092. let len = this._productMakeTimesData.makeTimes.length;
  1093. for (var i = 0; i < len; i++) {
  1094. if (this._productMakeTimesData.makeTimes[i].id == id) {
  1095. this._productMakeTimesData.makeTimes[i].times = times;
  1096. has = true;
  1097. break;
  1098. }
  1099. }
  1100. if (!has) {
  1101. let data = { 'id': id, 'times': times };
  1102. this._productMakeTimesData.makeTimes.push(data);
  1103. }
  1104. //设置可种植/生产最大id
  1105. let nextID = id + 1;
  1106. let curConfig = this.getProductMap(id);
  1107. let nextConfig = this.getProductMap(nextID);
  1108. if (id == this.getMaxProductExtra(curConfig.tab)) {
  1109. if (nextConfig) {
  1110. gData.plantData.init_itemIndex = nextID;
  1111. }
  1112. }
  1113. if (nextConfig) {
  1114. if (nextConfig.tab == curConfig.tab && nextID > this.getMaxProductExtra(curConfig.tab)) {
  1115. if (nextConfig.unlock == 1 && nextConfig.value <= times) {
  1116. isAddMaxProduct = true;
  1117. this._productMakeTimesMap.set(nextID, 0);
  1118. let data = { 'id': nextID, 'times': 0 };
  1119. this._productMakeTimesData.makeTimes.push(data);
  1120. this._productMakeTimesData.productUnlockMaxId.set(nextConfig.tab, nextID);
  1121. //this.setMaxProduct(nextID);
  1122. //需要更新最大生产id
  1123. gData.farmMapData.isStateChange = true;
  1124. this.updateMaxProduct();
  1125. let nConfig = this.getProductMap(nextID + 1);
  1126. if (nConfig) {
  1127. gData.plantData.init_lock = nextID + 1;
  1128. }
  1129. }
  1130. }
  1131. }
  1132. if (!isAddMaxProduct) {
  1133. mk.event.emit("refreshFarmMapUI");
  1134. }
  1135. let sss: any = {};
  1136. sss.makeTimes = this._productMakeTimesData.makeTimes;
  1137. let json = this.mapToObj(this._productMakeTimesData.productUnlockMaxId);
  1138. sss.productUnlockMaxId = JSON.stringify(json);
  1139. await this.setProp(GameProp.productMakeTimes, sss);
  1140. }
  1141. mapToObj(mapData) {
  1142. let obj = {};
  1143. mapData.forEach(function (value, key) {
  1144. obj[key] = value;
  1145. });
  1146. return obj;
  1147. }
  1148. objToMap(obj) {
  1149. let map = new Map();
  1150. for (let k in obj) {
  1151. map.set(k, obj[k]);
  1152. }
  1153. return map;
  1154. }
  1155. //设置解锁的最大id
  1156. addProductUnlockMaxId(tab, id) {
  1157. if (this._productMakeTimesData.productUnlockMaxId) {
  1158. let productId = this._productMakeTimesData.productUnlockMaxId.get(tab);
  1159. if (productId) {
  1160. if(id > productId){
  1161. this._productMakeTimesData.productUnlockMaxId.set(tab, id);
  1162. console.log(`addProductUnlockMaxId====${tab}====${id}`);
  1163. return true;
  1164. }
  1165. }else{
  1166. console.log(`addProductUnlockMaxId22====${tab}====${id}`);
  1167. this._productMakeTimesData.productUnlockMaxId.set(tab, id);
  1168. return true;
  1169. }
  1170. return false;
  1171. }
  1172. return false;
  1173. }
  1174. //判断前面解锁需要数值大于后面解锁数值的情况
  1175. public judgeAddExtraUnlockMaxId() {
  1176. let isUpdateToSever = false;
  1177. if (this._productMakeTimesData.productUnlockMaxId) {
  1178. let data = this._productMakeTimesData.productUnlockMaxId;
  1179. data.forEach((value, key) => {
  1180. if (key != ProductType.dw) {
  1181. let product = this.getMaxProductDataByType(key, value + 1);
  1182. if (product && product.unlock == 1) {
  1183. let makeTimes = this.getProductMakeTimesById(value);
  1184. if (makeTimes >= product.value) {
  1185. this.addProductUnlockMaxId(key, product.picture);
  1186. isUpdateToSever = true;
  1187. }
  1188. }
  1189. }
  1190. });
  1191. }
  1192. return isUpdateToSever;
  1193. }
  1194. updateDataToSever() {
  1195. let sss: any = {};
  1196. sss.makeTimes = this._productMakeTimesData.makeTimes;
  1197. let json = this.mapToObj(this._productMakeTimesData.productUnlockMaxId);
  1198. sss.productUnlockMaxId = JSON.stringify(json);
  1199. this.setProp(GameProp.productMakeTimes, sss);
  1200. }
  1201. getProductMakeTimesById(id: number) {
  1202. let times = this._productMakeTimesMap.get(id);
  1203. if (!times) {
  1204. times = 0
  1205. }
  1206. return times;
  1207. }
  1208. getProductUnlockById(tab, id: number) {
  1209. if (this._productMakeTimesData.productUnlockMaxId) {
  1210. let productId = this._productMakeTimesData.productUnlockMaxId.get(tab);
  1211. if (productId) {
  1212. if (productId >= id) {
  1213. return true;
  1214. } else {
  1215. return false;
  1216. }
  1217. } else {
  1218. return false;
  1219. }
  1220. }
  1221. return false;
  1222. }
  1223. //------------- 养殖场数据-----------
  1224. /** 养殖场数据 服务器数据 */
  1225. private _pastureData = [];
  1226. /** 养殖场字典 本地数据,方便操作*/
  1227. private _pastureDataMap: Map<number, any> = new Map();
  1228. public setPastureDataMap(id, data, sendToServer = true) {
  1229. this._pastureDataMap.set(id, data);
  1230. let len = this._pastureData.length;
  1231. for (var i = 0; i < len; i++) {
  1232. if (this._pastureData[i].id == id) {
  1233. this._pastureData[i].state = data.state;
  1234. this._pastureData[i].productID = data.productID;
  1235. this._pastureData[i].growSpan = data.growSpan;
  1236. break;
  1237. }
  1238. }
  1239. this.needFreshArr.push(id);
  1240. //更新到服务器
  1241. if (sendToServer) {
  1242. this.freshSendToServer(2);
  1243. }
  1244. }
  1245. public getPastureDataMap(id) {
  1246. return this._pastureDataMap.get(id);
  1247. }
  1248. /** 服务器数据设置到本地 */
  1249. public setPastureDataMapByServer() {
  1250. this._pastureData = this.getProp(GameProp.pastureData);
  1251. if (!this._pastureData) {
  1252. this._pastureData = [];
  1253. }
  1254. let len = this._pastureData.length;
  1255. //新玩家初始化养殖场数据
  1256. if (len < 3) {
  1257. let arr = this.getProductArrByType(ProductType.dw);
  1258. let len1 = arr.length;
  1259. let id = 30001;
  1260. let data = null;
  1261. for (var i = 0; i < len1; i++) {
  1262. if(this.playerProp.orderData)
  1263. {
  1264. if (this.playerProp.orderData.overTimes < arr[i].value) {
  1265. data = { id: id, state: PastureState.Lock, productID: arr[i].picture, growSpan: 0 };
  1266. }
  1267. else {
  1268. data = { id: id, state: PastureState.Empty, productID: arr[i].picture, growSpan: 0 };
  1269. }
  1270. }else{
  1271. data = { id: id, state: PastureState.Lock, productID: arr[i].picture, growSpan: 0 };
  1272. }
  1273. this._pastureData.push(data);
  1274. this._pastureDataMap.set(id, data);
  1275. id++;
  1276. }
  1277. //更新到服务器
  1278. this.setProp(GameProp.pastureData, this._pastureData);
  1279. }
  1280. else {
  1281. let sickTimes = 0;
  1282. for (var i = 0; i < len; i++) {
  1283. this._pastureDataMap.set(this._pastureData[i].id, this._pastureData[i]);
  1284. if (this._pastureData[i].state == PastureState.Sick) {
  1285. sickTimes++;
  1286. }
  1287. }
  1288. this.RawInsectCurArr[1] = sickTimes;
  1289. }
  1290. }
  1291. //------------- 工厂数据-----------
  1292. /** 工厂数据 服务器数据 */
  1293. private _factoryData = [];
  1294. /** 工厂字典 本地数据,方便操作*/
  1295. private _factoryDataMap: Map<number, any> = new Map();
  1296. public setFactoryDataMap(id, data, sendToServer = true) {
  1297. this._factoryDataMap.set(id, data);
  1298. let len = this._factoryData.length;
  1299. for (var i = 0; i < len; i++) {
  1300. if (this._factoryData[i].id == id) {
  1301. this._factoryData[i].state = data.state;
  1302. this._factoryData[i].productID = data.productID;
  1303. this._factoryData[i].growSpan = data.growSpan;
  1304. break;
  1305. }
  1306. }
  1307. this.needFreshArr.push(id);
  1308. //更新到服务器
  1309. if (sendToServer) {
  1310. this.freshSendToServer(3);
  1311. }
  1312. }
  1313. public getFactoryDataMap(id) {
  1314. return this._factoryDataMap.get(id);
  1315. }
  1316. /** 服务器数据设置到本地 */
  1317. public setFactoryDataMapByServer() {
  1318. this._factoryData = this.getProp(GameProp.factoryData);
  1319. if (!this._factoryData) {
  1320. this._factoryData = [];
  1321. }
  1322. let isUpdate = false;
  1323. let len = this._factoryData.length;
  1324. //新玩家初始化工厂数据
  1325. if (len < 6) {
  1326. let id = 30004;
  1327. let data = null;
  1328. let tab = null;
  1329. for (var i = 0; i < 6; i++) {
  1330. tab = this.getTabByConfigID(id);
  1331. let arr = this.getProductArrByType(tab);
  1332. if(this.playerProp.orderData){
  1333. if (this.playerProp.orderData.overTimes < arr[0].value) {
  1334. data = { id: id, state: FactroyState.Lock, productID: 0, growSpan: 0 };
  1335. }
  1336. else {
  1337. data = { id: id, state: FactroyState.Empty, productID: 0, growSpan: 0 };
  1338. //更新最大可购买商品
  1339. //this.setMaxProduct(arr[0].picture, true);
  1340. // let is = this.addProductUnlockMaxId(tab, arr[0].picture);
  1341. // if(!isUpdate)
  1342. // {
  1343. // isUpdate = is;
  1344. // }
  1345. }
  1346. }else{
  1347. data = { id: id, state: FactroyState.Lock, productID: 0, growSpan: 0 };
  1348. }
  1349. this._factoryData.push(data);
  1350. this._factoryDataMap.set(id, data);
  1351. id++;
  1352. }
  1353. //更新到服务器
  1354. this.setProp(GameProp.factoryData, this._factoryData);
  1355. }
  1356. else {
  1357. let sickTimes = 0;
  1358. let id = 30004;
  1359. let tab = null;
  1360. for (var i = 0; i < len; i++) {
  1361. tab = this.getTabByConfigID(id);
  1362. let arr = this.getProductArrByType(tab);
  1363. this._factoryDataMap.set(this._factoryData[i].id, this._factoryData[i]);
  1364. if (this._factoryData[i].state == FactroyState.Sick) {
  1365. sickTimes++;
  1366. }
  1367. id++;
  1368. }
  1369. this.RawInsectCurArr[2] = sickTimes;
  1370. }
  1371. // if(isUpdate)
  1372. // {
  1373. // this.updateDataToSever();
  1374. // }
  1375. }
  1376. /** 通过工厂建筑物ID获取标签 */
  1377. getTabByConfigID(configID: number): ProductType {
  1378. let tab = ProductType.bmhc;
  1379. switch (configID) {
  1380. case 30004:
  1381. tab = ProductType.bmhc;
  1382. break;
  1383. case 30005:
  1384. tab = ProductType.gdp;
  1385. break;
  1386. case 30006:
  1387. tab = ProductType.ztc;
  1388. break;
  1389. case 30007:
  1390. tab = ProductType.lrc;
  1391. break;
  1392. case 30008:
  1393. tab = ProductType.gfmg;
  1394. break;
  1395. case 30009:
  1396. tab = ProductType.kcd;
  1397. break;
  1398. }
  1399. return tab;
  1400. }
  1401. /** 通过标签获取工厂建筑物ID */
  1402. getConfigIDByTab(tab: ProductType): number {
  1403. let configID = 0;
  1404. switch (tab) {
  1405. case ProductType.bmhc:
  1406. configID = 30004;
  1407. break;
  1408. case ProductType.gdp:
  1409. configID = 30005;
  1410. break;
  1411. case ProductType.ztc:
  1412. configID = 30006;
  1413. break;
  1414. case ProductType.lrc:
  1415. configID = 30007;
  1416. break;
  1417. case ProductType.gfmg:
  1418. configID = 30008;
  1419. break;
  1420. case ProductType.kcd:
  1421. configID = 30009;
  1422. break;
  1423. }
  1424. return configID;
  1425. }
  1426. getIndex(data) {
  1427. let index: any = {};
  1428. index.i = 0;
  1429. index.j = 0;
  1430. switch (data.tab) {
  1431. case '农作物':
  1432. index.i = 0;
  1433. index.j = data.picture - 10001;
  1434. break;
  1435. case '动物':
  1436. index.i = 1;
  1437. index.j = data.picture - 20001;
  1438. break;
  1439. case '爆米花厂':
  1440. index.i = 2;
  1441. index.j = data.picture - 20004;
  1442. break;
  1443. case '糕点铺':
  1444. index.i = 3;
  1445. index.j = data.picture - 20013;
  1446. break;
  1447. case '制糖厂':
  1448. index.i = 4;
  1449. index.j = data.picture - 20010;
  1450. break;
  1451. case '炼乳厂':
  1452. index.i = 5;
  1453. index.j = data.picture - 20007;
  1454. break;
  1455. case '功夫面馆':
  1456. index.i = 6;
  1457. index.j = data.picture - 20025;
  1458. break;
  1459. case '快餐店':
  1460. index.i = 7;
  1461. index.j = data.picture - 20019;
  1462. break;
  1463. }
  1464. return index;
  1465. }
  1466. /** 发送数据到服务器 */
  1467. freshSendToServer(type) {
  1468. switch (type) {
  1469. case 1:
  1470. this.setProp(GameProp.farmData, this._farmData);
  1471. break;
  1472. case 2:
  1473. this.setProp(GameProp.pastureData, this._pastureData);
  1474. break;
  1475. case 3:
  1476. this.setProp(GameProp.factoryData, this._factoryData);
  1477. break;
  1478. }
  1479. }
  1480. /** 最大可种植/生产商品数组 */
  1481. private _maxProduct = [];
  1482. public getMaxProduct(tab) {
  1483. if (this._maxProduct) {
  1484. let len = this._maxProduct.length;
  1485. let data = null;
  1486. for (var i = 0; i < len; i++) {
  1487. data = this._maxProduct[i];
  1488. if (data.tab == tab) {
  1489. return data.productID;
  1490. }
  1491. }
  1492. }
  1493. return null;
  1494. }
  1495. getMaxProductExtra(tab) {
  1496. if (this._productMakeTimesData.productUnlockMaxId) {
  1497. let productId = this._productMakeTimesData.productUnlockMaxId.get(tab);
  1498. return productId;
  1499. }
  1500. return null;
  1501. }
  1502. /** 设置最大可生产商品
  1503. * @param id 产品id
  1504. * @param unlock 是否是解锁增加
  1505. */
  1506. public setMaxProduct(id, unlock = false) {
  1507. let config = this.getProductMap(id);
  1508. if (!this._maxProduct) {
  1509. this._maxProduct = [];
  1510. }
  1511. let len = this._maxProduct.length;
  1512. let data = null;
  1513. let has = false;
  1514. for (var i = 0; i < len; i++) {
  1515. data = this._maxProduct[i];
  1516. if (data.tab == config.tab) {
  1517. if (data.productID < id) {
  1518. data.productID = id;
  1519. data.id = config.id;
  1520. }
  1521. has = true;
  1522. break;
  1523. }
  1524. }
  1525. if (!has && unlock) {
  1526. data = { tab: config.tab, productID: id, id: config.id };
  1527. this._maxProduct.push(data);
  1528. }
  1529. gData.farmMapData.isStateChange = true;
  1530. this.updateMaxProduct();
  1531. }
  1532. /** 农场升级时解锁工厂,检查最大可种植/生产商品 */
  1533. public checkTaskFinishUnLock() {
  1534. let isUpdateToSever = false;
  1535. for (var key in ProductType) {
  1536. let tab = ProductType[key];
  1537. let configArr = this.getProductArrByType(tab);
  1538. let len = configArr.length;
  1539. let data = null;
  1540. let needUpdate = false;
  1541. switch (tab) {
  1542. case ProductType.nzw:
  1543. break;
  1544. case ProductType.dw:
  1545. let id = 30001;
  1546. needUpdate = false;
  1547. let maxId = 0;
  1548. for (var i = 0; i < len; i++) {
  1549. data = this.getPastureDataMap(id);
  1550. if(this.playerProp.orderData){
  1551. if (this.playerProp.orderData.overTimes >= configArr[i].value) {
  1552. if (data.state == PastureState.Lock) {
  1553. data = { id: id, state: PastureState.Empty, productID: configArr[i].picture, growSpan: 0 };
  1554. this.setPastureDataMap(id, data, false);
  1555. needUpdate = true;
  1556. }
  1557. maxId = configArr[i].picture;
  1558. }
  1559. }
  1560. id++;
  1561. }
  1562. console.log(`checkTaskFinishUnLock11=====${maxId}`);
  1563. if (maxId != 0) {
  1564. //更新最大可购买商品
  1565. //this.setMaxProduct(maxId, true);
  1566. let is = this.addProductUnlockMaxId(tab, maxId);
  1567. if (!isUpdateToSever) {
  1568. isUpdateToSever = is;
  1569. }
  1570. }
  1571. //更新到服务器
  1572. if (needUpdate) {
  1573. this.setProp(GameProp.pastureData, this._pastureData);
  1574. this.setNextProduct();
  1575. }
  1576. break;
  1577. default:
  1578. //工厂解锁根据第一个商品
  1579. needUpdate = false;
  1580. let configID = this.getConfigIDByTab(tab);
  1581. data = this.getFactoryDataMap(configID);
  1582. if(this.playerProp.orderData){
  1583. if (this.playerProp.orderData.overTimes >= configArr[0].value) {
  1584. if (data.state == FactroyState.Lock) {
  1585. data = { id: id, state: FactroyState.Empty, productID: 0, growSpan: 0 };
  1586. this.setFactoryDataMap(configID, data, false);
  1587. needUpdate = true;
  1588. }
  1589. //更新最大可购买商品
  1590. //this.setMaxProduct(configArr[0].picture, true);
  1591. console.log(`checkTaskFinishUnLock222=====${maxId}`);
  1592. let is = this.addProductUnlockMaxId(tab, configArr[0].picture);
  1593. if (!isUpdateToSever) {
  1594. isUpdateToSever = is;
  1595. }
  1596. }
  1597. }
  1598. if (needUpdate) {
  1599. this.setProp(GameProp.factoryData, this._factoryData);
  1600. this.setNextProduct();
  1601. }
  1602. break;
  1603. }
  1604. }
  1605. if (isUpdateToSever) {
  1606. console.log('===================isUpdateToSever222');
  1607. this.updateDataToSever();
  1608. //需要更新最大生产id
  1609. gData.farmMapData.isStateChange = true;
  1610. this.updateMaxProduct();
  1611. }
  1612. }
  1613. checkCanSpeedUp(pop = false) {
  1614. let can = false;
  1615. can = gData.farmSystem.canSpeedUp();
  1616. if (!can) {
  1617. can = gData.pastureSystem.canSpeedUp();
  1618. if (!can) {
  1619. can = gData.factorySystem.canSpeedUp();
  1620. }
  1621. }
  1622. if (can && pop) {
  1623. mk.ui.openPanel('module/speedUpUI/speedUp');
  1624. }
  1625. return can;
  1626. }
  1627. popSpeedUpByRate()
  1628. {
  1629. let isPop = false;
  1630. let rate = gData.adData.getPerByEcpm(RateConfig.RC_popSpeedUp);
  1631. if(rate >= Math.random())
  1632. {
  1633. isPop = gData.pastureSystem.canSpeedUp();
  1634. if (!isPop) {
  1635. isPop = gData.factorySystem.canSpeedUp();
  1636. }
  1637. }
  1638. if(isPop){
  1639. mk.ui.openPanel('module/speedUpUI/speedUp');
  1640. }
  1641. return isPop;
  1642. }
  1643. setHarvest() {
  1644. gData.farmSystem.setHarvest();
  1645. gData.pastureSystem.setHarvest();
  1646. gData.factorySystem.setHarvest();
  1647. }
  1648. checkCanHarvest() {
  1649. let can = false;
  1650. can = gData.farmSystem.canHarvest();
  1651. if (!can) {
  1652. can = gData.pastureSystem.canHarvest();
  1653. if (!can) {
  1654. can = gData.factorySystem.canHarvest();
  1655. }
  1656. }
  1657. return can;
  1658. }
  1659. checkCanClearSick() {
  1660. let can = false;
  1661. can = gData.farmSystem.canClearSick();
  1662. if (!can) {
  1663. can = gData.pastureSystem.canClearSick();
  1664. if (!can) {
  1665. can = gData.factorySystem.canClearSick();
  1666. }
  1667. }
  1668. return can;
  1669. }
  1670. doPointToXYLogic() {
  1671. let value = mk.storage.getStorage('cash_out');
  1672. if (!value) {
  1673. mk.storage.setStorage('cash_out', 1);
  1674. mk.data.sendXYEvent('cash_1', `第一次提现`);
  1675. } else {
  1676. if (value == 1) {
  1677. mk.storage.setStorage('cash_out', 2);
  1678. mk.data.sendXYEvent('cash_2', `第二次提现`);
  1679. } else if (value == 2) {
  1680. mk.storage.setStorage('cash_out', 3);
  1681. mk.data.sendXYEvent('cash_3', `第三次提现`);
  1682. }
  1683. }
  1684. }
  1685. /** 更新最大可种植产品到服务器 */
  1686. async updateMaxProduct() {
  1687. if (this.maxProductToServer) {
  1688. //let data = { "unLockProductList": this._maxProduct };
  1689. let data = { "unLockProductList": [] };
  1690. let maxProductData = this._productMakeTimesData.productUnlockMaxId;
  1691. maxProductData.forEach((value, key) => {
  1692. let config = this.getProductMap(value);
  1693. let d = { tab: key, productID: value, id: config.id };
  1694. data.unLockProductList.push(d);
  1695. });
  1696. mk.console.logSingle("updateMaxProduct", data);
  1697. let respone = await mk.http.sendData('orderTask/updateUnlockProduct', data);
  1698. console.log("------");
  1699. }
  1700. }
  1701. popTableScreenADLogic(type: number) {
  1702. let str = null;
  1703. switch (type) {
  1704. case 0:
  1705. str = InterAdType.interstitial1_click_1;
  1706. break;
  1707. case 1:
  1708. str = InterAdType.interstitial1_click_2;
  1709. break;
  1710. case 2:
  1711. str = InterAdType.interstitial1_click_3;
  1712. break;
  1713. case 3:
  1714. str = InterAdType.interstitial1_click_4;
  1715. break;
  1716. case 4:
  1717. str = InterAdType.interstitial1_click_5;
  1718. break;
  1719. case 5:
  1720. str = InterAdType.interstitial1_click_6;
  1721. break;
  1722. case 6:
  1723. str = InterAdType.interstitial1_click_7;
  1724. break;
  1725. case 7:
  1726. str = InterAdType.interstitial1_click_8;
  1727. break;
  1728. case 8:
  1729. str = InterAdType.interstitial1_click_9;
  1730. break;
  1731. case 9:
  1732. str = InterAdType.interstitial1_click_10;
  1733. break;
  1734. case 10:
  1735. str = InterAdType.interstitial1_click_11;
  1736. break;
  1737. case 11:
  1738. str = InterAdType.interstitial1_click_12;
  1739. break;
  1740. case 12:
  1741. str = InterAdType.interstitial1_click_13;
  1742. break;
  1743. case 13:
  1744. str = InterAdType.interstitial1_click_14;
  1745. break;
  1746. case 14:
  1747. str = InterAdType.interstitial1_click_15;
  1748. break;
  1749. case 15:
  1750. str = InterAdType.interstitial1_click_16;
  1751. break;
  1752. case 16:
  1753. str = InterAdType.interstitial1_click_17;
  1754. break;
  1755. case 17:
  1756. str = InterAdType.interstitial1_click_18;
  1757. break;
  1758. }
  1759. let index = 0;
  1760. let rateType = null;
  1761. if(type <= 11){
  1762. index = type;
  1763. }else{
  1764. index = 12;
  1765. rateType = RateConfig.RC_afterVideo;
  1766. }
  1767. if(str != null){
  1768. let cashTimes = gData.gameData.getProp(GameProp.cashTimes);
  1769. let is = gData.gameData.insertAdSwitch[index];
  1770. if(is == "1" && cashTimes >= gData.gameData.insertAdLimit){
  1771. gData.adData.checkPopInter(str, rateType);
  1772. }
  1773. }
  1774. }
  1775. }
  1776. /**
  1777. * 所有模块的非校验数据
  1778. */
  1779. export enum GameProp {
  1780. /** -------------------- 通用玩家数据 ------------------------- */
  1781. /** 是否新手 0新手 1老手 */
  1782. newPlayer = 1,
  1783. /** 当前新手引导步骤 */
  1784. guideID = 2,
  1785. /** 需要自动弹界面 每次登录都弹 除首次 表示今日是否要自动开 1自动开 2不自动开 其他不处理*/
  1786. isAutoOpenPanel = 3,
  1787. /** 关闭常规提现时需要自动开存钱罐 每天一次 表示今日有没有开过 */
  1788. isOpenBankOnCloseCash = 4,
  1789. //看视频次数
  1790. videoTimes = 5,
  1791. //提现次数
  1792. cashTimes = 6,
  1793. /** ------------------ 游戏核心数据 --------------------------- */
  1794. /** 农田数据 */
  1795. farmData = 11,
  1796. /** 产品生产次数 */
  1797. productMakeTimes = 12,
  1798. /** 养殖场数据 */
  1799. pastureData = 14,
  1800. /** 工厂数据 */
  1801. factoryData = 15,
  1802. /** 剩余可种植次数 */
  1803. leftTimes = 16,
  1804. /**
  1805. 图鉴领取数据*/
  1806. farmMapGetRewardData = 17,
  1807. //红包任务tag
  1808. redBagTaskRefresh = 18,
  1809. /** ------------------ 转盘数据 ------------------------------ */
  1810. turnable_leftTimes = 20,
  1811. //提现次数
  1812. cashOutTimes = 21,
  1813. //银行当天完成任务tag
  1814. finishRichBankTodayTask = 22,
  1815. }
  1816. /**
  1817. * 玩家数据
  1818. */
  1819. class PlayerProp {
  1820. /** 自定义不需要校验的数据 */
  1821. gameUserData = 0;
  1822. _isSignInToday = 0;
  1823. /**
  1824. * 今日是否有签到
  1825. * - 0 未签到,表示可以签到
  1826. * - 1 有签到,表示不可签到
  1827. */
  1828. set isSignInToday(value: number) {
  1829. this._isSignInToday = value;
  1830. gData.sign.init_data = true;
  1831. gData.gameData.init_red_point = true;
  1832. }
  1833. get isSignInToday(): number {
  1834. return this._isSignInToday;
  1835. }
  1836. private _piggyBank: number = 0;
  1837. /** 存钱罐存款 */
  1838. set piggyBank(value: number) {
  1839. if (this._piggyBank === value) return;
  1840. if (gData.gameData.playerProp.isWithdrawable && value > 0) return;// 存钱罐可提现状态,不能增加存钱罐金额
  1841. this._piggyBank = value;
  1842. gData.gameData.init_coin = true;
  1843. gData.gameData.init_red_point = true;
  1844. }
  1845. get piggyBank(): number {
  1846. return this._piggyBank;
  1847. }
  1848. /** 初始化 */
  1849. initPiggyBank(v) {
  1850. this._piggyBank = v;
  1851. }
  1852. _isWithdrawable = 0;
  1853. /**
  1854. * 存钱罐能否提现
  1855. * - 0 不能提现
  1856. * - 1 能提现
  1857. */
  1858. set isWithdrawable(value: number) {
  1859. if (this._isWithdrawable != value) {
  1860. this._isWithdrawable = value;
  1861. gData.gameData.init_red_point = true;
  1862. }
  1863. }
  1864. get isWithdrawable(): number {
  1865. return this._isWithdrawable;
  1866. }
  1867. /** 存钱罐每日提现次数 */
  1868. piggyBankCashTimes = 0;
  1869. /** 累计存钱罐每日提现次数 */
  1870. totalPiggyBankCashTimes = 0;
  1871. /** 提现进度 */
  1872. cashIndex = 0;
  1873. /** 上次登录时间 */
  1874. lastTime = 0;
  1875. /** 登录天数 */
  1876. loginDays = 0;
  1877. newPlayer = 0;
  1878. private _redMoney: number = 0;
  1879. /** 红包币数量 */
  1880. set redMoney(value: number) {
  1881. this._redMoney = value;
  1882. gData.gameData.init_coin = true;
  1883. //gData.gameData.init_red_point = true;
  1884. gData.gameData.init_wallet_redMoney = true;
  1885. mk.event.emit('refreshCoin');
  1886. if(this._redMoney >= 300000){
  1887. mk.guide.open(14);
  1888. }
  1889. mk.data.setTAEventUser(0, 'current_redmoney_stock', this._redMoney);
  1890. }
  1891. get redMoney(): number {
  1892. return this._redMoney;
  1893. }
  1894. _signInDay = 0;
  1895. /** 累计签到次数 客户端理解 上次签到天数 */
  1896. set signInDay(value: number) {
  1897. if (this._signInDay === value) return;
  1898. this._signInDay = value;
  1899. gData.sign.init_data = true;
  1900. }
  1901. get signInDay(): number {
  1902. return this._signInDay;
  1903. }
  1904. /** 转盘次数 */
  1905. turntableTimes = 0;
  1906. /** 版本号 */
  1907. versioncfg = 0;
  1908. /** 福袋数据 */
  1909. userTuCaoInfo = 0;
  1910. /** 能免费领红包 1 表示是新人第一次产出红包币,不用看视频*/
  1911. isFirstRedMoney = 0;
  1912. //农场等级
  1913. gradeLevel = 1;
  1914. //农场等级奖励数据
  1915. farmGradeData: any = {};
  1916. //农场等级名字
  1917. farmGradeName: number = 1;
  1918. //农场经验
  1919. private farmExp = 0;
  1920. set farmExpValue(value: number) {
  1921. this.farmExp = value;
  1922. gData.gameData.init_expLevel = true;
  1923. }
  1924. get farmExpValue(): number {
  1925. return this.farmExp;
  1926. }
  1927. //提现新手数据
  1928. userNoviceWeFareInfo: any = {};
  1929. //提现记录数据
  1930. redMoneyCashPayRecordList = null;
  1931. //任务红;
  1932. userFarmTaskInfo = null;
  1933. getRedMoneyCashOutTimesByIndex(index: number): number {
  1934. if (this.redMoneyCashPayRecordList) {
  1935. for (let i = 0; i != this.redMoneyCashPayRecordList.length; ++i) {
  1936. if (index === this.redMoneyCashPayRecordList[i].index) {
  1937. return this.redMoneyCashPayRecordList[i].frequency;
  1938. }
  1939. }
  1940. }
  1941. return 0;
  1942. }
  1943. /** ABTest分组id */
  1944. groupCode = 0;
  1945. //加速剩余次数
  1946. speedUpLeftTimes = 0;
  1947. /** 农场任务完成次数 */
  1948. completeFarmTaskTimes = 0;
  1949. /** 订单数据 */
  1950. orderData = null;
  1951. /** 临时订单数据, 只用于种植优先选择作用 */
  1952. copyOrderData = null;
  1953. //插队看视频次数限制
  1954. lineRedMoney = 0;
  1955. //当前生产次数
  1956. curProductionAdTimes = 0;
  1957. }
  1958. /**
  1959. * 奖励状态
  1960. */
  1961. export enum RewardState {
  1962. /** 已领取 */
  1963. none = 1,
  1964. /** 未解锁 */
  1965. lock = 2,
  1966. /** 可领取 */
  1967. unlock = 3
  1968. }
  1969. /**
  1970. * 奖励类型
  1971. */
  1972. export enum RewardType {
  1973. /** 红包币 */
  1974. redBag = 1,
  1975. /** 毛币 */
  1976. rmb = 2,
  1977. /** 金猪币 */
  1978. pigRmb = 3,
  1979. /** 生产次数 */
  1980. productTimes = 4,
  1981. }
  1982. /**
  1983. * 音频路径
  1984. */
  1985. export enum AUDIO_TYPE {
  1986. /**主界面背景音乐*/
  1987. bgm = 'bgm',
  1988. /**打开存钱罐界面播放一次*/
  1989. pigBank = 'pigBank',
  1990. /**关卡玩法背景音乐*/
  1991. missionBg = 'missionBg',
  1992. /**红包币领取界面关闭音效*/
  1993. rewardClose = 'rewardClose',
  1994. /**红包币领取界面开启音效*/
  1995. rewardOpen = 'rewardOpen',
  1996. /**红包界面打开音效*/
  1997. reward = 'reward',
  1998. /**提现到账界面打开播放一次*/
  1999. receiptNotice = 'receiptNotice',
  2000. /**通用按钮点击音效 */
  2001. button = 'button',
  2002. /**转盘转动音效*/
  2003. turnableplay = 'turnableplay',
  2004. /**转盘转动音效*/
  2005. turnplateDrawEnd = 'turnplateDrawEnd',
  2006. /**主页背景音乐 */
  2007. music_startBg = "music_startBg",
  2008. /**游戏背景音乐 */
  2009. music_gameBg = "music_gameBg",
  2010. /**按钮点击 */
  2011. ef_button_click = "ef_button_click",
  2012. /**红包打开 */
  2013. ef_redPacket_open = "ef_redPacket_open",
  2014. /**红包来了音效 */
  2015. ef_redPacket_come = "ef_redPacket_come",
  2016. /**消除4个 */
  2017. ef_bonus4 = "ef_bonus4",
  2018. /**消除5个 */
  2019. ef_bonus5 = "ef_bonus5",
  2020. /**消除6个 */
  2021. ef_bonus6 = "ef_bonus6",
  2022. /**消除7个 */
  2023. ef_bonus7 = "ef_bonus7",
  2024. /**消除8个 */
  2025. ef_bonus8 = "ef_bonus8",
  2026. /**普通消除音效 */
  2027. ef_eliminate = "ef_eliminate",
  2028. /**bouns消除音效 */
  2029. ef_eliminate_bonus = "ef_eliminate_bonus",
  2030. /**胜利音效 */
  2031. ef_win = "ef_win",
  2032. /**锤子 */
  2033. ef_change = "ef_change",
  2034. /**刷新 */
  2035. ef_refresh = "ef_refresh",
  2036. /**飞翔 */
  2037. ef_fly = "ef_fly",
  2038. /**关闭按钮音效*/
  2039. closeButton = "closeButton",
  2040. //红包界面打开
  2041. congratulations = 'congratulations',
  2042. //红包飞音效
  2043. redmoney = 'redmoney',
  2044. /**存入银行成功*/
  2045. saveSuccess = 'saveSuccess',
  2046. }
  2047. /** ECPM */
  2048. type ADShowCfg = {
  2049. average_ecpm: number,
  2050. insert_probability: number,
  2051. is_show_banner: number,
  2052. is_show_inter: number,
  2053. }
  2054. /**事件类型 */
  2055. export enum EVENT_TYPE {
  2056. BACK_WxAuth = "BACK_WxAuth",
  2057. UPDATE_CashNum = "UPDATE_CashNum",
  2058. }
  2059. /** 数据事件Id */
  2060. export enum DataEventId {
  2061. /** 点击 */
  2062. guide = "guide",
  2063. /** 点击跳过 */
  2064. guideSkip = "guideSkip",
  2065. /** 按钮点击 */
  2066. button_click = "button_click",
  2067. /** 看视频 */
  2068. video_init = "video_init",
  2069. /** 看视频完成 */
  2070. video_end = "video_end",
  2071. /** 成功拉取全屏视频 */
  2072. interstitial2_init = "interstitial2_init",
  2073. /** 广告点击 */
  2074. Ad_click = "Ad_click",
  2075. /** 全屏视频完成 */
  2076. interstitial2_end = "interstitial2_end",
  2077. /** 福袋功能 */
  2078. fudaiFunction = "fudaiFunction",
  2079. /** 互推功能 */
  2080. hutuiFunction = "hutuiFunction",
  2081. /** 激励视频ecpm */
  2082. ad_videoEcpm = 'ad_video',
  2083. /** 开屏ecpm */
  2084. ad_openEcpm = 'ad_open',
  2085. /** 提现 */
  2086. Sundry = 'Sundry',
  2087. /** 加载 */
  2088. loading = 'loading',
  2089. /** 排队 */
  2090. queue = 'queue',
  2091. /** 实名认证 */
  2092. realName = 'realName',
  2093. /** 离线生产次数弹出 */
  2094. offlineProductTimes = "offlineProductTimes",
  2095. /**触发提现到达上限 */
  2096. cashLimit = "cashLimit",
  2097. /**互推红包弹出位置 */
  2098. htRedBag_scene = "htRedBag_scene",
  2099. /**互推红包领取次数*/
  2100. htRedBag_eject = "htRedBag_eject",
  2101. interstita11_eject = "interstita11_eject"
  2102. }
  2103. /** 视频广告类型 */
  2104. export enum VideoAdType {
  2105. video_init_1 = '农场加等级经验',
  2106. video_init_2 = '提现-加进度',
  2107. video_init_3 = '提现-加现金',
  2108. video_init_4 = '签到',
  2109. video_init_5 = '抽奖',
  2110. video_init_6 = '图鉴领奖',
  2111. video_init_7 = '消灭害虫',
  2112. video_init_8 = '恢复健康',
  2113. video_init_9 = '恢复供电',
  2114. video_init_10 = '山羊红包',
  2115. video_init_11 = '拓建',
  2116. video_init_12 = '收获',
  2117. video_init_13 = '飘浮红包',
  2118. video_init_14 = '全体加速',
  2119. video_init_15 = '福利加进度',
  2120. video_init_16 = '生产加次数',
  2121. video_init_17 = '点击生产按钮',
  2122. video_init_18 = '离开游戏领红包',
  2123. video_init_19 = '定时弹出红包',
  2124. video_init_20 = '插队',
  2125. video_init_21 = '恢复生产次数',
  2126. //video_init_22 = '长时间未操作弹出视频',
  2127. }
  2128. export enum InterFullAdType {
  2129. interstitial2_init_1 = '点击红包的关闭按钮',
  2130. interstitial2_init_2 = '普通收获',
  2131. interstitial2_init_3 = '点击鸟和狗',
  2132. interstitial2_init_4 = "长时间未操作弹出"
  2133. }
  2134. export enum InterAdType {
  2135. interstitial1_click_1 = '恭喜发财红包弹出后',
  2136. interstitial1_click_2 = '恭喜获得弹窗弹出后',
  2137. interstitial1_click_3 = '生虫/生病/停电弹出后',
  2138. interstitial1_click_4 = '关闭抽奖界面后',
  2139. interstitial1_click_5 = '关闭任务红包后',
  2140. interstitial1_click_6 = '关闭富翁银行后',
  2141. interstitial1_click_7 = '打开领取生产次数界面',
  2142. interstitial1_click_8 = '农作物点击可收获',
  2143. interstitial1_click_9 = '关闭全体加速后',
  2144. interstitial1_click_10 = '关闭福利后',
  2145. interstitial1_click_11 = '打开个人资料页',
  2146. interstitial1_click_12 = '打开更多游戏页',
  2147. interstitial1_click_13 = '全体加速激励视频播完后',
  2148. interstitial1_click_14 = '离线奖励激励视频播完后',
  2149. interstitial1_click_15 = '抽奖激励视频播完后',
  2150. interstitial1_click_16 = '图鉴领奖激励视频播完后',
  2151. interstitial1_click_17 = '拓建激励视频播完后',
  2152. interstitial1_click_18 = '收获超级加倍激励视频播完后',
  2153. //interstitial1_click_19 = '定时弹出插屏',
  2154. }
  2155. export enum BannerAdType {
  2156. banner_click_1 = '恭喜获得弹窗弹出后',
  2157. banner_click_2 = '任务红包',
  2158. banner_click_3 = '恭喜发财红包',
  2159. banner_click_4 = '图鉴',
  2160. banner_click_5 = '全体加速',
  2161. banner_click_6 = '收获弹窗',
  2162. banner_click_7 = '拓建弹窗',
  2163. banner_click_8 = '三个恢复弹窗',
  2164. banner_click_9 = '抽奖',
  2165. banner_click_10 = '提现账单'
  2166. }
  2167. export enum ExpAddType {
  2168. EAT_video = 1,
  2169. EAT_harvest = 2,
  2170. EAT_others = 3,
  2171. }
  2172. export enum FarmState {
  2173. Lock,
  2174. CanUnlock,
  2175. Empty,
  2176. Growing,
  2177. Ripe,
  2178. Sick
  2179. }
  2180. export enum PastureState {
  2181. Lock,
  2182. Empty,
  2183. Growing,
  2184. Ripe,
  2185. Sick
  2186. }
  2187. export enum ProductType {
  2188. nzw = '农作物',
  2189. dw = '动物',
  2190. bmhc = '爆米花厂',
  2191. gdp = '糕点铺',
  2192. ztc = '制糖厂',
  2193. lrc = '炼乳厂',
  2194. gfmg = '功夫面馆',
  2195. kcd = '快餐店'
  2196. }
  2197. /** 动物状态 */
  2198. export enum AnimalState {
  2199. Hanger,
  2200. Eat,
  2201. Wait
  2202. }
  2203. export enum FactroyState {
  2204. Lock,
  2205. Empty,
  2206. Producting,
  2207. Ripe,
  2208. Sick
  2209. }
  2210. //功能开关含义
  2211. export enum FunctionSwitch{
  2212. FS_farmGrade = 0, //农场等级奖励
  2213. FS_cashOutBtn = 1, //主界面提现按钮
  2214. FS_sign = 2, //签到
  2215. FS_turntable = 3, //抽奖转盘
  2216. FS_redPacketTash = 4, //任务红包
  2217. FS_welfareBtn = 5, //福利按钮
  2218. FS_inviteBtn = 6, //邀请按钮
  2219. FS_floatRedPacket = 7, //漂浮红包
  2220. FS_electBtn = 8, //互推按钮
  2221. FS_sheepRedPacket = 9, //山羊红包
  2222. FS_addCashBtn = 10, //提现界面的加现金按钮
  2223. FS_order = 11, //订单
  2224. FS_floatFarmMap = 12, //图鉴浮窗
  2225. FS_richManBank = 13, //富翁银行
  2226. FS_openPushNotice = 14, //打开推送通知权限
  2227. FS_cashOutBill = 15, //提现账单
  2228. }