GameData.ts 85 KB

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