GameData.ts 66 KB

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