GameData.ts 66 KB

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