GameData.ts 86 KB

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