GameData.ts 63 KB

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