GameData.ts 89 KB

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