GameData.ts 86 KB

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