GameData.ts 79 KB

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