GameData.ts 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959
  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 = 3;//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. public doJudgeOrderLogic(out?: any)
  536. {
  537. let data = this.playerProp.orderData;
  538. let orderData = data.orderTaskList;
  539. if (data && orderData) {
  540. let productJson = this.configs.Product;
  541. for (let i = 0; i != orderData.length; ++i) {
  542. let dataE = orderData[i];
  543. if (this.playerProp.copyOrderData[i] < dataE.taskCount) {
  544. if (dataE.Id <= productJson.length) {
  545. let productData = productJson[dataE.Id - 1];
  546. if (productData.tab == ProductType.nzw) {
  547. continue;
  548. }else if(productData.tab == ProductType.dw)
  549. {
  550. let pastureIcon = gData.pastureSystem.pastureIcons;
  551. let len = pastureIcon.length;
  552. for (var j = 0; j < len; j++) {
  553. if (pastureIcon[j].data.productID == productData.picture && pastureIcon[j].data.state == PastureState.Empty) {
  554. out.state = 2;
  555. break;
  556. }
  557. }
  558. }else{
  559. let factoryIcon = gData.factorySystem.factoryIcons;
  560. let len = factoryIcon.length;
  561. for (var j = 0; j < len; j++) {
  562. let tab = this.getTabByConfigID(factoryIcon[j].configID);
  563. if (tab == productData.tab&& factoryIcon[j].data.state == FactroyState.Empty) {
  564. out.state = 1;
  565. break;
  566. }
  567. }
  568. }
  569. }
  570. }
  571. }
  572. }
  573. }
  574. /** 随机获取可生产产品 */
  575. getRandomFactoryConfig(configID) {
  576. let tab = gData.gameData.getTabByConfigID(configID);
  577. let arr = this.getProductArrByType(tab);
  578. let max = this.getMaxProduct(tab);
  579. let canArr = [];
  580. let len = arr.length;
  581. for (var i = 0; i < len; i++) {
  582. if (arr[i].picture <= max) {
  583. canArr.push(arr[i].picture);
  584. if (arr[i].picture == max) {
  585. break;
  586. }
  587. }
  588. }
  589. let index = Util.rnd(0, canArr.length - 1);
  590. let id = canArr[index];
  591. return this.getProductMap(id);
  592. }
  593. public doFarmMapDataCheck(startIndex: number, isHaveEmpty?: any) {
  594. let value = 0;
  595. for (let key in ProductType) {
  596. if (startIndex <= value) {
  597. let max = this.getMaxProduct(ProductType[key]);
  598. if (max) {
  599. let list_data = this.getProductArrByType(ProductType[key]);
  600. for (let i = 0; i != list_data.length; ++i) {
  601. let picId = list_data[i].picture - 1;
  602. if (list_data[i].unlock == 1 && picId == max) {
  603. let state = this.getFarmMapRewardState(this.getIndex(list_data[i]));
  604. if (state == 0) {
  605. switch (ProductType[key]) {
  606. case ProductType.nzw:
  607. console.log("图鉴数据匹配成功");
  608. this.nextType = 1
  609. return picId;
  610. case ProductType.dw:
  611. {
  612. let pastureIconsData = gData.pastureSystem.pastureIcons;
  613. let len = pastureIconsData.length;
  614. for (let index = 0; index < len; index++) {
  615. if (pastureIconsData[index].data.state == PastureState.Empty) {
  616. if (isHaveEmpty && startIndex == value) {
  617. isHaveEmpty.state = true;
  618. }
  619. if (picId == pastureIconsData[index].data.productID) {
  620. console.log("图鉴数据匹配成功");
  621. this.nextCanProduct = this.getProductMap(pastureIconsData[index].data.productID);
  622. this.nextMake = pastureIconsData[index];
  623. this.nextType = 2;
  624. return picId;
  625. }
  626. }
  627. }
  628. }
  629. break;
  630. default:
  631. {
  632. let factoryIconsData = gData.factorySystem.factoryIcons;
  633. let len = factoryIconsData.length;
  634. for (let index = 0; index < len; index++) {
  635. if (factoryIconsData[index].data.state == FactroyState.Empty) {
  636. if (isHaveEmpty) {
  637. isHaveEmpty.state = true;
  638. }
  639. let tab = this.getTabByConfigID(factoryIconsData[index].configID);
  640. if (tab == ProductType[key]) {
  641. console.log("图鉴数据匹配成功");
  642. this.nextCanProduct = this.getProductMap(picId);
  643. this.nextMake = factoryIconsData[index];
  644. this.nextType = 3;
  645. return picId;
  646. }
  647. }
  648. }
  649. }
  650. break;
  651. }
  652. }
  653. }
  654. }
  655. }
  656. }
  657. ++value;
  658. }
  659. console.log("图鉴数据匹配不成功");
  660. return null;
  661. }
  662. /** 自动生产选中下一个 */
  663. setNextProduct(sel = true) {
  664. if (this.nextMake) {
  665. return;
  666. }
  667. //-1无效,0:有空地,1:工厂有空位,2:饲养厂有空位
  668. let haveEmpty = { state: -1 };
  669. let next = gData.farmSystem.selectNextFarm(haveEmpty, sel);
  670. if (!next) {
  671. if(haveEmpty.state == -1)
  672. {
  673. this.doJudgeOrderLogic(haveEmpty);
  674. }
  675. let next1 = gData.pastureSystem.nextPasture(haveEmpty);
  676. if (!next1) {
  677. let next2 = gData.factorySystem.nextFactory(haveEmpty);
  678. if (!next2) {
  679. this.nextType = 0;
  680. }
  681. else {
  682. //this.nextType = 3;
  683. }
  684. }
  685. else {
  686. //this.nextType = 2;
  687. }
  688. }
  689. else {
  690. //this.nextType = 1;
  691. }
  692. this.init_makeInfo = true;
  693. }
  694. hasFirstCheck = false;
  695. firstCheckNext() {
  696. if (!this.hasFirstCheck && gData.farmSystem.farms.length >= 18
  697. && gData.pastureSystem.pastureIcons.length >= 3 && gData.factorySystem.factoryIcons.length >= 6) {
  698. this.hasFirstCheck = true;
  699. Util.objSortByKey(gData.farmSystem.farms, 'sortID');
  700. Util.objSortByKey(gData.pastureSystem.pastureIcons, 'sortID');
  701. Util.objSortByKey(gData.factorySystem.factoryIcons, 'sortID');
  702. gData.gameData.setNextProduct(false);
  703. }
  704. }
  705. async makeProduct() {
  706. let flyRed = true;
  707. switch (this.nextType) {
  708. case 0:
  709. //mk.tip.pop('农场已满,无法继续生产');
  710. //弹出收获、生虫、加速
  711. if (!this.checkCanHarvest()) {
  712. if (!this.checkCanClearSick()) {
  713. this.checkCanSpeedUp(true);
  714. }
  715. }
  716. flyRed = false;
  717. break;
  718. case 1:
  719. flyRed = await gData.farmSystem.btnMake();
  720. gData.adData.checkPopRed();
  721. break;
  722. case 2:
  723. flyRed = await gData.pastureSystem.btnMake();
  724. gData.adData.checkPopRed();
  725. break;
  726. case 3:
  727. flyRed = await gData.factorySystem.btnMake();
  728. gData.adData.checkPopRed();
  729. break;
  730. }
  731. return flyRed;
  732. }
  733. public async updateNewTaskProgress(isNeedRefresh = false) {
  734. // if (gData.gameData.init_redBagTask) {
  735. // return;
  736. // }
  737. if (this.playerProp.userFarmTaskInfo) {
  738. let com = this.playerProp.userFarmTaskInfo.completeCount;
  739. let count = this.playerProp.userFarmTaskInfo.taskCount;
  740. if (com >= count) {
  741. if (!this.gameStyle.getIsCanGetOrderReward()) {
  742. mk.tip.pop('任务红包进度已满,快去提现');
  743. }else{
  744. mk.tip.pop("订单已完成,快领奖吧!");
  745. }
  746. return false;
  747. }
  748. }
  749. let data = {};
  750. let response = await mk.http.sendData('farmTask/updateUserFarmTaskInfo', data);
  751. mk.console.logSingle('refrehTask=>', response);
  752. if (response.errcode != 0) {
  753. return false;
  754. }
  755. gData.gameData.init_task = true;
  756. this.playerProp.userFarmTaskInfo = response.data.userFarmTaskInfo;
  757. if (this.playerProp.userFarmTaskInfo.completeCount >= this.playerProp.userFarmTaskInfo.taskCount) {
  758. //mk.ui.closeAllUI();
  759. //mk.guide.open(4);
  760. }
  761. // if (isNeedRefresh) {
  762. // gData.gameData.init_task = true;
  763. // }
  764. return true;
  765. }
  766. public setFarmDataMap(id, data, sendToServer = true) {
  767. this._farmDataMap.set(id, data);
  768. let len = this._farmData.length;
  769. for (var i = 0; i < len; i++) {
  770. if (this._farmData[i].id == id) {
  771. this._farmData[i].state = data.state;
  772. this._farmData[i].productID = data.productID;
  773. this._farmData[i].growSpan = data.growSpan;
  774. break;
  775. }
  776. }
  777. this.needFreshArr.push(id);
  778. //更新到服务器
  779. if (sendToServer) {
  780. this.freshSendToServer(1);
  781. }
  782. }
  783. public getFarmDataMap(id) {
  784. return this._farmDataMap.get(id);
  785. }
  786. /** 服务器数据设置到本地 */
  787. public setFramDataMapByServer() {
  788. this._farmData = this.getProp(GameProp.farmData);
  789. if (!this._farmData) {
  790. this._farmData = [];
  791. }
  792. let len = this._farmData.length;
  793. //新玩家初始化农田数据
  794. if (len < 18) {
  795. let id = 31000;
  796. let data = null;
  797. let unluckNum = parseInt(gData.gameData.configs.ServerConfig.unluckNum);
  798. for (var i = 0; i < 18; i++) {
  799. if (i < unluckNum) {
  800. data = { id: id, state: FarmState.Empty, productID: 0, growSpan: 0 };
  801. }
  802. else if (i == unluckNum) {
  803. data = { id: id, state: FarmState.CanUnlock, productID: 0, growSpan: 0 };
  804. }
  805. else {
  806. data = { id: id, state: FarmState.Lock, productID: 0, growSpan: 0 };
  807. }
  808. this._farmData.push(data);
  809. this._farmDataMap.set(id, data);
  810. id++;
  811. }
  812. //第一次初始数据
  813. // this.setMaxProduct(10003);
  814. //更新到服务器
  815. this.setProp(GameProp.farmData, this._farmData);
  816. }
  817. else {
  818. let sickTimes = 0;
  819. for (var i = 0; i < len; i++) {
  820. this._farmDataMap.set(this._farmData[i].id, this._farmData[i]);
  821. if (this._farmData[i].state == FarmState.Sick) {
  822. sickTimes++;
  823. }
  824. }
  825. this.RawInsectCurArr[0] = sickTimes;
  826. }
  827. this.setMaxProduct(10003, true);
  828. }
  829. /** puduct配置数据 <picture, config> */
  830. private _productMap: Map<number, any> = new Map();
  831. /** puduct类型配置数据 <tab, 类型数组> */
  832. private _productTypeMap: Map<string, any> = new Map();
  833. /** 设置puduct配置数据 */
  834. public setProductMapFromJson() {
  835. let productJson = this.configs.Product;
  836. // // 先用本地数据
  837. // let productJson = gData.configData.configMap.get('product');
  838. let len = productJson.length;
  839. let product = null;
  840. let tab = '';
  841. let arr = [];
  842. for (var i = 0; i < len; i++) {
  843. product = productJson[i];
  844. this._productMap.set(product.picture, product);
  845. if (tab != product.tab) {
  846. arr = [];
  847. this._productTypeMap.set(product.tab, arr);
  848. tab = product.tab;
  849. }
  850. arr.push(product);
  851. }
  852. }
  853. /** 根据id获取单个数据 */
  854. public getProductMap(id) {
  855. return this._productMap.get(id);
  856. }
  857. /** 根据tab获取数组 */
  858. public getProductArrByType(type: ProductType) {
  859. return this._productTypeMap.get(type);
  860. }
  861. /** 产品生产/种植次数 服务器数据 */
  862. private _productMakeTimesData = [];
  863. /** 产品生产/种植次数 */
  864. private _productMakeTimesMap: Map<number, number> = new Map();
  865. private initProductTimes() {
  866. this._productMakeTimesData = this.getProp(GameProp.productMakeTimes);
  867. if (!this._productMakeTimesData) {
  868. this._productMakeTimesData = [];
  869. }
  870. let len = this._productMakeTimesData.length;
  871. for (var i = 0; i < len; i++) {
  872. this._productMakeTimesMap.set(this._productMakeTimesData[i].id, this._productMakeTimesData[i].times);
  873. this.setMaxProduct(this._productMakeTimesData[i].id);
  874. }
  875. }
  876. addProductMakeTimesById(id: number) {
  877. let isAddMaxProduct = false;
  878. let times = this._productMakeTimesMap.get(id);
  879. if (!times) {
  880. times = 0;
  881. }
  882. times++;
  883. this._productMakeTimesMap.set(id, times);
  884. //更新到服务器
  885. let has = false;
  886. let len = this._productMakeTimesData.length;
  887. for (var i = 0; i < len; i++) {
  888. if (this._productMakeTimesData[i].id == id) {
  889. this._productMakeTimesData[i].times = times;
  890. has = true;
  891. break;
  892. }
  893. }
  894. if (!has) {
  895. let data = { 'id': id, 'times': times };
  896. this._productMakeTimesData.push(data);
  897. }
  898. //设置可种植/生产最大id
  899. let nextID = id + 1;
  900. let curConfig = this.getProductMap(id);
  901. let nextConfig = this.getProductMap(nextID);
  902. if (id == this.getMaxProduct(curConfig.tab)) {
  903. if (nextConfig) {
  904. gData.plantData.init_itemIndex = nextID;
  905. }
  906. }
  907. if (nextConfig) {
  908. if (nextConfig.tab == curConfig.tab && nextID > this.getMaxProduct(curConfig.tab)) {
  909. if (nextConfig.unlock == 1 && nextConfig.value <= times) {
  910. isAddMaxProduct = true;
  911. this._productMakeTimesMap.set(nextID, 0);
  912. let data = { 'id': nextID, 'times': 0 };
  913. this._productMakeTimesData.push(data);
  914. this.setMaxProduct(nextID);
  915. let nConfig = this.getProductMap(nextID + 1);
  916. if (nConfig) {
  917. gData.plantData.init_lock = nextID + 1;
  918. }
  919. }
  920. }
  921. }
  922. if (!isAddMaxProduct) {
  923. mk.event.emit("refreshFarmMapUI");
  924. }
  925. this.setProp(GameProp.productMakeTimes, this._productMakeTimesData);
  926. }
  927. getProductMakeTimesById(id: number) {
  928. let times = this._productMakeTimesMap.get(id);
  929. if (!times) {
  930. times = 0
  931. }
  932. return times;
  933. }
  934. //------------- 养殖场数据-----------
  935. /** 养殖场数据 服务器数据 */
  936. private _pastureData = [];
  937. /** 养殖场字典 本地数据,方便操作*/
  938. private _pastureDataMap: Map<number, any> = new Map();
  939. public setPastureDataMap(id, data, sendToServer = true) {
  940. this._pastureDataMap.set(id, data);
  941. let len = this._pastureData.length;
  942. for (var i = 0; i < len; i++) {
  943. if (this._pastureData[i].id == id) {
  944. this._pastureData[i].state = data.state;
  945. this._pastureData[i].productID = data.productID;
  946. this._pastureData[i].growSpan = data.growSpan;
  947. break;
  948. }
  949. }
  950. this.needFreshArr.push(id);
  951. //更新到服务器
  952. if (sendToServer) {
  953. this.freshSendToServer(2);
  954. }
  955. }
  956. public getPastureDataMap(id) {
  957. return this._pastureDataMap.get(id);
  958. }
  959. /** 服务器数据设置到本地 */
  960. public setPastureDataMapByServer() {
  961. this._pastureData = this.getProp(GameProp.pastureData);
  962. if (!this._pastureData) {
  963. this._pastureData = [];
  964. }
  965. let len = this._pastureData.length;
  966. //新玩家初始化养殖场数据
  967. if (len < 3) {
  968. let arr = this.getProductArrByType(ProductType.dw);
  969. let len1 = arr.length;
  970. let id = 30001;
  971. let data = null;
  972. for (var i = 0; i < len1; i++) {
  973. if (this.playerProp.completeFarmTaskTimes < arr[i].value) {
  974. data = { id: id, state: PastureState.Lock, productID: arr[i].picture, growSpan: 0 };
  975. }
  976. else {
  977. data = { id: id, state: PastureState.Empty, productID: arr[i].picture, growSpan: 0 };
  978. }
  979. this._pastureData.push(data);
  980. this._pastureDataMap.set(id, data);
  981. id++;
  982. }
  983. //更新到服务器
  984. this.setProp(GameProp.pastureData, this._pastureData);
  985. }
  986. else {
  987. let sickTimes = 0;
  988. for (var i = 0; i < len; i++) {
  989. this._pastureDataMap.set(this._pastureData[i].id, this._pastureData[i]);
  990. if (this._pastureData[i].state == PastureState.Sick) {
  991. sickTimes++;
  992. }
  993. }
  994. this.RawInsectCurArr[1] = sickTimes;
  995. }
  996. }
  997. //------------- 工厂数据-----------
  998. /** 工厂数据 服务器数据 */
  999. private _factoryData = [];
  1000. /** 工厂字典 本地数据,方便操作*/
  1001. private _factoryDataMap: Map<number, any> = new Map();
  1002. public setFactoryDataMap(id, data, sendToServer = true) {
  1003. this._factoryDataMap.set(id, data);
  1004. let len = this._factoryData.length;
  1005. for (var i = 0; i < len; i++) {
  1006. if (this._factoryData[i].id == id) {
  1007. this._factoryData[i].state = data.state;
  1008. this._factoryData[i].productID = data.productID;
  1009. this._factoryData[i].growSpan = data.growSpan;
  1010. break;
  1011. }
  1012. }
  1013. this.needFreshArr.push(id);
  1014. //更新到服务器
  1015. if (sendToServer) {
  1016. this.freshSendToServer(3);
  1017. }
  1018. }
  1019. public getFactoryDataMap(id) {
  1020. return this._factoryDataMap.get(id);
  1021. }
  1022. /** 服务器数据设置到本地 */
  1023. public setFactoryDataMapByServer() {
  1024. this._factoryData = this.getProp(GameProp.factoryData);
  1025. if (!this._factoryData) {
  1026. this._factoryData = [];
  1027. }
  1028. let len = this._factoryData.length;
  1029. //新玩家初始化工厂数据
  1030. if (len < 6) {
  1031. let id = 30004;
  1032. let data = null;
  1033. let tab = null;
  1034. for (var i = 0; i < 6; i++) {
  1035. tab = this.getTabByConfigID(id);
  1036. let arr = this.getProductArrByType(tab);
  1037. if (this.playerProp.completeFarmTaskTimes < arr[0].value) {
  1038. data = { id: id, state: FactroyState.Lock, productID: 0, growSpan: 0 };
  1039. }
  1040. else {
  1041. data = { id: id, state: FactroyState.Empty, productID: 0, growSpan: 0 };
  1042. //更新最大可购买商品
  1043. this.setMaxProduct(arr[0].picture, true);
  1044. }
  1045. this._factoryData.push(data);
  1046. this._factoryDataMap.set(id, data);
  1047. id++;
  1048. }
  1049. //更新到服务器
  1050. this.setProp(GameProp.factoryData, this._factoryData);
  1051. }
  1052. else {
  1053. let sickTimes = 0;
  1054. let id = 30004;
  1055. let tab = null;
  1056. for (var i = 0; i < len; i++) {
  1057. tab = this.getTabByConfigID(id);
  1058. let arr = this.getProductArrByType(tab);
  1059. this._factoryDataMap.set(this._factoryData[i].id, this._factoryData[i]);
  1060. if (this._factoryData[i].state == FactroyState.Sick) {
  1061. sickTimes++;
  1062. }
  1063. if (this.playerProp.completeFarmTaskTimes >= arr[0].value) {
  1064. //更新最大可购买商品
  1065. this.setMaxProduct(arr[0].picture, true);
  1066. }
  1067. id++;
  1068. }
  1069. this.RawInsectCurArr[2] = sickTimes;
  1070. }
  1071. }
  1072. /** 通过工厂建筑物ID获取标签 */
  1073. getTabByConfigID(configID: number): ProductType {
  1074. let tab = ProductType.bmhc;
  1075. switch (configID) {
  1076. case 30004:
  1077. tab = ProductType.bmhc;
  1078. break;
  1079. case 30005:
  1080. tab = ProductType.gdp;
  1081. break;
  1082. case 30006:
  1083. tab = ProductType.ztc;
  1084. break;
  1085. case 30007:
  1086. tab = ProductType.lrc;
  1087. break;
  1088. case 30008:
  1089. tab = ProductType.gfmg;
  1090. break;
  1091. case 30009:
  1092. tab = ProductType.kcd;
  1093. break;
  1094. }
  1095. return tab;
  1096. }
  1097. /** 通过标签获取工厂建筑物ID */
  1098. getConfigIDByTab(tab: ProductType): number {
  1099. let configID = 0;
  1100. switch (tab) {
  1101. case ProductType.bmhc:
  1102. configID = 30004;
  1103. break;
  1104. case ProductType.gdp:
  1105. configID = 30005;
  1106. break;
  1107. case ProductType.ztc:
  1108. configID = 30006;
  1109. break;
  1110. case ProductType.lrc:
  1111. configID = 30007;
  1112. break;
  1113. case ProductType.gfmg:
  1114. configID = 30008;
  1115. break;
  1116. case ProductType.kcd:
  1117. configID = 30009;
  1118. break;
  1119. }
  1120. return configID;
  1121. }
  1122. getIndex(data) {
  1123. let index: any = {};
  1124. index.i = 0;
  1125. index.j = 0;
  1126. switch (data.tab) {
  1127. case '农作物':
  1128. index.i = 0;
  1129. index.j = data.picture - 10001;
  1130. break;
  1131. case '动物':
  1132. index.i = 1;
  1133. index.j = data.picture - 20001;
  1134. break;
  1135. case '爆米花厂':
  1136. index.i = 2;
  1137. index.j = data.picture - 20004;
  1138. break;
  1139. case '糕点铺':
  1140. index.i = 3;
  1141. index.j = data.picture - 20013;
  1142. break;
  1143. case '制糖厂':
  1144. index.i = 4;
  1145. index.j = data.picture - 20010;
  1146. break;
  1147. case '炼乳厂':
  1148. index.i = 5;
  1149. index.j = data.picture - 20007;
  1150. break;
  1151. case '功夫面馆':
  1152. index.i = 6;
  1153. index.j = data.picture - 20025;
  1154. break;
  1155. case '快餐店':
  1156. index.i = 7;
  1157. index.j = data.picture - 20019;
  1158. break;
  1159. }
  1160. return index;
  1161. }
  1162. /** 发送数据到服务器 */
  1163. freshSendToServer(type) {
  1164. switch (type) {
  1165. case 1:
  1166. this.setProp(GameProp.farmData, this._farmData);
  1167. break;
  1168. case 2:
  1169. this.setProp(GameProp.pastureData, this._pastureData);
  1170. break;
  1171. case 3:
  1172. this.setProp(GameProp.factoryData, this._factoryData);
  1173. break;
  1174. }
  1175. }
  1176. /** 最大可种植/生产商品数组 */
  1177. private _maxProduct = [];
  1178. public getMaxProduct(tab) {
  1179. if (this._maxProduct) {
  1180. let len = this._maxProduct.length;
  1181. let data = null;
  1182. for (var i = 0; i < len; i++) {
  1183. data = this._maxProduct[i];
  1184. if (data.tab == tab) {
  1185. return data.productID;
  1186. }
  1187. }
  1188. }
  1189. return null;
  1190. }
  1191. /** 设置最大可生产商品
  1192. * @param id 产品id
  1193. * @param unlock 是否是解锁增加
  1194. */
  1195. public setMaxProduct(id, unlock = false) {
  1196. let config = this.getProductMap(id);
  1197. if (!this._maxProduct) {
  1198. this._maxProduct = [];
  1199. }
  1200. let len = this._maxProduct.length;
  1201. let data = null;
  1202. let has = false;
  1203. for (var i = 0; i < len; i++) {
  1204. data = this._maxProduct[i];
  1205. if (data.tab == config.tab) {
  1206. if (data.productID < id) {
  1207. data.productID = id;
  1208. data.id = config.id;
  1209. }
  1210. has = true;
  1211. break;
  1212. }
  1213. }
  1214. if (!has && unlock) {
  1215. data = { tab: config.tab, productID: id, id: config.id };
  1216. this._maxProduct.push(data);
  1217. }
  1218. gData.farmMapData.isStateChange = true;
  1219. this.updateMaxProduct();
  1220. }
  1221. /** 农场升级时解锁工厂,检查最大可种植/生产商品 */
  1222. public checkTaskFinishUnLock() {
  1223. for (var key in ProductType) {
  1224. let tab = ProductType[key];
  1225. let configArr = this.getProductArrByType(tab);
  1226. let len = configArr.length;
  1227. let data = null;
  1228. let needUpdate = false;
  1229. switch (tab) {
  1230. case ProductType.nzw:
  1231. break;
  1232. case ProductType.dw:
  1233. let id = 30001;
  1234. needUpdate = false;
  1235. let maxId = 0;
  1236. for (var i = 0; i < len; i++) {
  1237. data = this.getPastureDataMap(id);
  1238. if (this.playerProp.completeFarmTaskTimes >= configArr[i].value) {
  1239. if (data.state == PastureState.Lock) {
  1240. data = { id: id, state: PastureState.Empty, productID: configArr[i].picture, growSpan: 0 };
  1241. this.setPastureDataMap(id, data, false);
  1242. needUpdate = true;
  1243. }
  1244. maxId = configArr[i].picture;
  1245. }
  1246. id++;
  1247. }
  1248. if (maxId != 0) {
  1249. //更新最大可购买商品
  1250. this.setMaxProduct(maxId, true);
  1251. }
  1252. //更新到服务器
  1253. if (needUpdate) {
  1254. this.setProp(GameProp.pastureData, this._pastureData);
  1255. this.setNextProduct();
  1256. }
  1257. break;
  1258. default:
  1259. //工厂解锁根据第一个商品
  1260. needUpdate = false;
  1261. let configID = this.getConfigIDByTab(tab);
  1262. data = this.getFactoryDataMap(configID);
  1263. if (this.playerProp.completeFarmTaskTimes >= configArr[0].value) {
  1264. if (data.state == FactroyState.Lock) {
  1265. data = { id: id, state: FactroyState.Empty, productID: 0, growSpan: 0 };
  1266. this.setFactoryDataMap(configID, data, false);
  1267. needUpdate = true;
  1268. }
  1269. //更新最大可购买商品
  1270. this.setMaxProduct(configArr[0].picture, true);
  1271. }
  1272. if (needUpdate) {
  1273. this.setProp(GameProp.factoryData, this._factoryData);
  1274. this.setNextProduct();
  1275. }
  1276. break;
  1277. }
  1278. }
  1279. }
  1280. checkCanSpeedUp(pop = false) {
  1281. let can = false;
  1282. can = gData.farmSystem.canSpeedUp();
  1283. if (!can) {
  1284. can = gData.pastureSystem.canSpeedUp();
  1285. if (!can) {
  1286. can = gData.factorySystem.canSpeedUp();
  1287. }
  1288. }
  1289. if (can && pop) {
  1290. mk.ui.openPanel('module/speedUpUI/speedUp');
  1291. }
  1292. return can;
  1293. }
  1294. setHarvest() {
  1295. gData.farmSystem.setHarvest();
  1296. gData.pastureSystem.setHarvest();
  1297. gData.factorySystem.setHarvest();
  1298. }
  1299. checkCanHarvest() {
  1300. let can = false;
  1301. can = gData.farmSystem.canHarvest();
  1302. if (!can) {
  1303. can = gData.pastureSystem.canHarvest();
  1304. if (!can) {
  1305. can = gData.factorySystem.canHarvest();
  1306. }
  1307. }
  1308. return can;
  1309. }
  1310. checkCanClearSick() {
  1311. let can = false;
  1312. can = gData.farmSystem.canClearSick();
  1313. if (!can) {
  1314. can = gData.pastureSystem.canClearSick();
  1315. if (!can) {
  1316. can = gData.factorySystem.canClearSick();
  1317. }
  1318. }
  1319. return can;
  1320. }
  1321. doPointToXYLogic() {
  1322. let value = mk.storage.getStorage('cash_out');
  1323. if (!value) {
  1324. mk.storage.setStorage('cash_out', 1);
  1325. mk.data.sendXYEvent('cash_1', `第一次提现`);
  1326. } else {
  1327. if (value == 1) {
  1328. mk.storage.setStorage('cash_out', 2);
  1329. mk.data.sendXYEvent('cash_2', `第二次提现`);
  1330. } else if (value == 2) {
  1331. mk.storage.setStorage('cash_out', 3);
  1332. mk.data.sendXYEvent('cash_3', `第三次提现`);
  1333. }
  1334. }
  1335. }
  1336. /** 更新最大可种植产品到服务器 */
  1337. async updateMaxProduct() {
  1338. if (this.maxProductToServer) {
  1339. let data = { "unLockProductList": this._maxProduct };
  1340. // for (let i = 0; i != this._maxProduct.length; ++i) {
  1341. // let dataE = this._maxProduct[i];
  1342. // let d = { id: dataE.productID, tab: dataE.tab };
  1343. // data.unLockProductList.push(d);
  1344. // }
  1345. mk.console.logSingle("updateMaxProduct", data);
  1346. let respone = await mk.http.sendData('orderTask/updateUnlockProduct', data);
  1347. console.log("------");
  1348. }
  1349. }
  1350. }
  1351. /**
  1352. * 所有模块的非校验数据
  1353. */
  1354. export enum GameProp {
  1355. /** -------------------- 通用玩家数据 ------------------------- */
  1356. /** 是否新手 0新手 1老手 */
  1357. newPlayer = 1,
  1358. /** 当前新手引导步骤 */
  1359. guideID = 2,
  1360. /** 需要自动弹界面 每次登录都弹 除首次 表示今日是否要自动开 1自动开 2不自动开 其他不处理*/
  1361. isAutoOpenPanel = 3,
  1362. /** 关闭常规提现时需要自动开存钱罐 每天一次 表示今日有没有开过 */
  1363. isOpenBankOnCloseCash = 4,
  1364. //看视频次数
  1365. videoTimes = 5,
  1366. //提现次数
  1367. cashTimes = 6,
  1368. /** ------------------ 游戏核心数据 --------------------------- */
  1369. /** 农田数据 */
  1370. farmData = 11,
  1371. /** 产品生产次数 */
  1372. productMakeTimes = 12,
  1373. /** 养殖场数据 */
  1374. pastureData = 14,
  1375. /** 工厂数据 */
  1376. factoryData = 15,
  1377. /** 剩余可种植次数 */
  1378. leftTimes = 16,
  1379. /**
  1380. 图鉴领取数据*/
  1381. farmMapGetRewardData = 17,
  1382. //红包任务tag
  1383. redBagTaskRefresh = 18,
  1384. /** ------------------ 转盘数据 ------------------------------ */
  1385. turnable_leftTimes = 20,
  1386. //提现次数
  1387. cashOutTimes = 21,
  1388. }
  1389. /**
  1390. * 玩家数据
  1391. */
  1392. class PlayerProp {
  1393. /** 自定义不需要校验的数据 */
  1394. gameUserData = 0;
  1395. _isSignInToday = 0;
  1396. /**
  1397. * 今日是否有签到
  1398. * - 0 未签到,表示可以签到
  1399. * - 1 有签到,表示不可签到
  1400. */
  1401. set isSignInToday(value: number) {
  1402. this._isSignInToday = value;
  1403. gData.sign.init_data = true;
  1404. gData.gameData.init_red_point = true;
  1405. }
  1406. get isSignInToday(): number {
  1407. return this._isSignInToday;
  1408. }
  1409. private _piggyBank: number = 0;
  1410. /** 存钱罐存款 */
  1411. set piggyBank(value: number) {
  1412. if (this._piggyBank === value) return;
  1413. if (gData.gameData.playerProp.isWithdrawable && value > 0) return;// 存钱罐可提现状态,不能增加存钱罐金额
  1414. this._piggyBank = value;
  1415. gData.gameData.init_coin = true;
  1416. gData.gameData.init_red_point = true;
  1417. }
  1418. get piggyBank(): number {
  1419. return this._piggyBank;
  1420. }
  1421. /** 初始化 */
  1422. initPiggyBank(v) {
  1423. this._piggyBank = v;
  1424. }
  1425. _isWithdrawable = 0;
  1426. /**
  1427. * 存钱罐能否提现
  1428. * - 0 不能提现
  1429. * - 1 能提现
  1430. */
  1431. set isWithdrawable(value: number) {
  1432. if (this._isWithdrawable != value) {
  1433. this._isWithdrawable = value;
  1434. gData.gameData.init_red_point = true;
  1435. }
  1436. }
  1437. get isWithdrawable(): number {
  1438. return this._isWithdrawable;
  1439. }
  1440. /** 存钱罐每日提现次数 */
  1441. piggyBankCashTimes = 0;
  1442. /** 累计存钱罐每日提现次数 */
  1443. totalPiggyBankCashTimes = 0;
  1444. /** 提现进度 */
  1445. cashIndex = 0;
  1446. /** 上次登录时间 */
  1447. lastTime = 0;
  1448. /** 登录天数 */
  1449. loginDays = 0;
  1450. newPlayer = 0;
  1451. private _redMoney: number = 0;
  1452. /** 红包币数量 */
  1453. set redMoney(value: number) {
  1454. this._redMoney = value;
  1455. gData.gameData.init_coin = true;
  1456. //gData.gameData.init_red_point = true;
  1457. gData.gameData.init_wallet_redMoney = true;
  1458. mk.event.emit('refreshCoin');
  1459. mk.data.setTAEventUser(0, 'current_redmoney_stock', this._redMoney);
  1460. }
  1461. get redMoney(): number {
  1462. return this._redMoney;
  1463. }
  1464. _signInDay = 0;
  1465. /** 累计签到次数 客户端理解 上次签到天数 */
  1466. set signInDay(value: number) {
  1467. if (this._signInDay === value) return;
  1468. this._signInDay = value;
  1469. gData.sign.init_data = true;
  1470. }
  1471. get signInDay(): number {
  1472. return this._signInDay;
  1473. }
  1474. /** 转盘次数 */
  1475. turntableTimes = 0;
  1476. /** 版本号 */
  1477. versioncfg = 0;
  1478. /** 福袋数据 */
  1479. userTuCaoInfo = 0;
  1480. /** 能免费领红包 1 表示是新人第一次产出红包币,不用看视频*/
  1481. isFirstRedMoney = 0;
  1482. //农场等级
  1483. gradeLevel = 1;
  1484. //农场等级奖励数据
  1485. farmGradeData: any = {};
  1486. //农场等级名字
  1487. farmGradeName: number = 1;
  1488. //农场经验
  1489. private farmExp = 0;
  1490. set farmExpValue(value: number) {
  1491. this.farmExp = value;
  1492. gData.gameData.init_expLevel = true;
  1493. }
  1494. get farmExpValue(): number {
  1495. return this.farmExp;
  1496. }
  1497. //提现新手数据
  1498. userNoviceWeFareInfo: any = {};
  1499. //提现记录数据
  1500. redMoneyCashPayRecordList = null;
  1501. //任务红;
  1502. userFarmTaskInfo = null;
  1503. getRedMoneyCashOutTimesByIndex(index: number): number {
  1504. if (this.redMoneyCashPayRecordList) {
  1505. for (let i = 0; i != this.redMoneyCashPayRecordList.length; ++i) {
  1506. if (index === this.redMoneyCashPayRecordList[i].index) {
  1507. return this.redMoneyCashPayRecordList[i].frequency;
  1508. }
  1509. }
  1510. }
  1511. return 0;
  1512. }
  1513. /** ABTest分组id */
  1514. groupCode = 0;
  1515. //加速剩余次数
  1516. speedUpLeftTimes = 0;
  1517. /** 农场任务完成次数 */
  1518. completeFarmTaskTimes = 0;
  1519. /** 订单数据 */
  1520. orderData = null;
  1521. /** 临时订单数据, 只用于种植优先选择作用 */
  1522. copyOrderData = null;
  1523. }
  1524. /**
  1525. * 奖励状态
  1526. */
  1527. export enum RewardState {
  1528. /** 已领取 */
  1529. none = 1,
  1530. /** 未解锁 */
  1531. lock = 2,
  1532. /** 可领取 */
  1533. unlock = 3
  1534. }
  1535. /**
  1536. * 奖励类型
  1537. */
  1538. export enum RewardType {
  1539. /** 红包币 */
  1540. redBag = 1,
  1541. /** 毛币 */
  1542. rmb = 2,
  1543. /** 金猪币 */
  1544. pigRmb = 3,
  1545. /** 生产次数 */
  1546. productTimes = 4,
  1547. }
  1548. /**
  1549. * 音频路径
  1550. */
  1551. export enum AUDIO_TYPE {
  1552. /**主界面背景音乐*/
  1553. bgm = 'bgm',
  1554. /**打开存钱罐界面播放一次*/
  1555. pigBank = 'pigBank',
  1556. /**关卡玩法背景音乐*/
  1557. missionBg = 'missionBg',
  1558. /**红包币领取界面关闭音效*/
  1559. rewardClose = 'rewardClose',
  1560. /**红包币领取界面开启音效*/
  1561. rewardOpen = 'rewardOpen',
  1562. /**红包界面打开音效*/
  1563. reward = 'reward',
  1564. /**提现到账界面打开播放一次*/
  1565. receiptNotice = 'receiptNotice',
  1566. /**通用按钮点击音效 */
  1567. button = 'button',
  1568. /**转盘转动音效*/
  1569. turnableplay = 'turnableplay',
  1570. /**转盘转动音效*/
  1571. turnplateDrawEnd = 'turnplateDrawEnd',
  1572. /**主页背景音乐 */
  1573. music_startBg = "music_startBg",
  1574. /**游戏背景音乐 */
  1575. music_gameBg = "music_gameBg",
  1576. /**按钮点击 */
  1577. ef_button_click = "ef_button_click",
  1578. /**红包打开 */
  1579. ef_redPacket_open = "ef_redPacket_open",
  1580. /**红包来了音效 */
  1581. ef_redPacket_come = "ef_redPacket_come",
  1582. /**消除4个 */
  1583. ef_bonus4 = "ef_bonus4",
  1584. /**消除5个 */
  1585. ef_bonus5 = "ef_bonus5",
  1586. /**消除6个 */
  1587. ef_bonus6 = "ef_bonus6",
  1588. /**消除7个 */
  1589. ef_bonus7 = "ef_bonus7",
  1590. /**消除8个 */
  1591. ef_bonus8 = "ef_bonus8",
  1592. /**普通消除音效 */
  1593. ef_eliminate = "ef_eliminate",
  1594. /**bouns消除音效 */
  1595. ef_eliminate_bonus = "ef_eliminate_bonus",
  1596. /**胜利音效 */
  1597. ef_win = "ef_win",
  1598. /**锤子 */
  1599. ef_change = "ef_change",
  1600. /**刷新 */
  1601. ef_refresh = "ef_refresh",
  1602. /**飞翔 */
  1603. ef_fly = "ef_fly",
  1604. /**关闭按钮音效*/
  1605. closeButton = "closeButton",
  1606. //红包界面打开
  1607. congratulations = 'congratulations',
  1608. //红包飞音效
  1609. redmoney = 'redmoney'
  1610. }
  1611. /** ECPM */
  1612. type ADShowCfg = {
  1613. average_ecpm: number,
  1614. insert_probability: number,
  1615. is_show_banner: number,
  1616. is_show_inter: number,
  1617. }
  1618. /**事件类型 */
  1619. export enum EVENT_TYPE {
  1620. BACK_WxAuth = "BACK_WxAuth",
  1621. UPDATE_CashNum = "UPDATE_CashNum",
  1622. }
  1623. /** 数据事件Id */
  1624. export enum DataEventId {
  1625. /** 点击 */
  1626. guide = "guide",
  1627. /** 点击跳过 */
  1628. guideSkip = "guideSkip",
  1629. /** 按钮点击 */
  1630. button_click = "button_click",
  1631. /** 看视频 */
  1632. video_init = "video_init",
  1633. /** 看视频完成 */
  1634. video_end = "video_end",
  1635. /** 成功拉取全屏视频 */
  1636. interstitial2_init = "interstitial2_init",
  1637. /** 广告点击 */
  1638. Ad_click = "Ad_click",
  1639. /** 全屏视频完成 */
  1640. interstitial2_end = "interstitial2_end",
  1641. /** 福袋功能 */
  1642. fudaiFunction = "fudaiFunction",
  1643. /** 互推功能 */
  1644. hutuiFunction = "hutuiFunction",
  1645. /** 激励视频ecpm */
  1646. ad_videoEcpm = 'ad_video',
  1647. /** 开屏ecpm */
  1648. ad_openEcpm = 'ad_open',
  1649. /** 提现 */
  1650. Sundry = 'Sundry',
  1651. /** 加载 */
  1652. loading = 'loading',
  1653. /** 排队 */
  1654. queue = 'queue'
  1655. }
  1656. /** 视频广告类型 */
  1657. export enum VideoAdType {
  1658. video_init_1 = '农场加等级经验',
  1659. video_init_2 = '提现-加进度',
  1660. video_init_3 = '提现-加现金',
  1661. video_init_4 = '签到',
  1662. video_init_5 = '抽奖',
  1663. video_init_6 = '图鉴领奖',
  1664. video_init_7 = '消灭害虫',
  1665. video_init_8 = '恢复健康',
  1666. video_init_9 = '恢复供电',
  1667. video_init_10 = '山羊红包',
  1668. video_init_11 = '拓建',
  1669. video_init_12 = '收获',
  1670. video_init_13 = '飘浮红包',
  1671. video_init_14 = '全体加速',
  1672. video_init_15 = '福利加进度',
  1673. video_init_16 = '生产加次数',
  1674. video_init_17 = '点击生产按钮',
  1675. video_init_18 = '离开游戏领红包',
  1676. video_init_19 = '定时弹出红包',
  1677. video_init_20 = '插队',
  1678. video_init_21 = '恢复生产次数',
  1679. }
  1680. export enum InterFullAdType {
  1681. interstitial2_init_1 = '点击红包的关闭按钮',
  1682. interstitial2_init_2 = '普通收获',
  1683. interstitial2_init_3 = '点击鸟和狗'
  1684. }
  1685. export enum InterAdType {
  1686. interstitial1_click_1 = '恭喜发财红包弹出后',
  1687. interstitial1_click_2 = '恭喜获得弹窗弹出后',
  1688. interstitial1_click_3 = '生虫/生病/停电弹出后'
  1689. }
  1690. export enum BannerAdType {
  1691. banner_click_1 = '恭喜获得弹窗弹出后',
  1692. banner_click_2 = '任务红包',
  1693. banner_click_3 = '恭喜发财红包',
  1694. banner_click_4 = '图鉴',
  1695. banner_click_5 = '全体加速',
  1696. banner_click_6 = '收获弹窗',
  1697. banner_click_7 = '拓建弹窗',
  1698. banner_click_8 = '三个恢复弹窗',
  1699. banner_click_9 = '抽奖'
  1700. }
  1701. export enum ExpAddType {
  1702. EAT_video = 1,
  1703. EAT_harvest = 2,
  1704. EAT_others = 3,
  1705. }
  1706. export enum FarmState {
  1707. Lock,
  1708. CanUnlock,
  1709. Empty,
  1710. Growing,
  1711. Ripe,
  1712. Sick
  1713. }
  1714. export enum PastureState {
  1715. Lock,
  1716. Empty,
  1717. Growing,
  1718. Ripe,
  1719. Sick
  1720. }
  1721. export enum ProductType {
  1722. nzw = '农作物',
  1723. dw = '动物',
  1724. bmhc = '爆米花厂',
  1725. gdp = '糕点铺',
  1726. ztc = '制糖厂',
  1727. lrc = '炼乳厂',
  1728. gfmg = '功夫面馆',
  1729. kcd = '快餐店'
  1730. }
  1731. /** 动物状态 */
  1732. export enum AnimalState {
  1733. Hanger,
  1734. Eat,
  1735. Wait
  1736. }
  1737. export enum FactroyState {
  1738. Lock,
  1739. Empty,
  1740. Producting,
  1741. Ripe,
  1742. Sick
  1743. }