GameData.ts 66 KB

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