GameData.ts 81 KB

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