GameData.ts 85 KB

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