GameData.ts 86 KB

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