GameData.ts 66 KB

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