GameData.ts 66 KB

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