GameData.ts 86 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480
  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. * 初始化游戏数据:网络配置信息,用户信息
  104. * @returns
  105. */
  106. public async init() {
  107. let data: any = { "versionCode": gData.appData.version };
  108. let response = await mk.http.sendData('getAllConfigInfo', data);
  109. if (response.errcode != 0) {
  110. if (response.errcode == -10003 || response.errcode == -20003) {
  111. //清除缓存
  112. gData.loginData.reload();
  113. }
  114. return;
  115. }
  116. mk.console.logSingle("getAllConfigInfo", response.data);
  117. this.initConfigs(response.data);
  118. data = {};
  119. response = await mk.http.sendData('getInfoCrypt', data);
  120. if (response.errcode != 0) {
  121. return;
  122. }
  123. mk.console.logSingle("getInfoCrypt", response.data);
  124. this.initPlayerProp(response.data)
  125. this.initProps(response.data.gameUserData);
  126. if (gData.warnTipData.curSolution == 4) {
  127. if (response.data.isSystemRisk == 0) {
  128. //拉白后重置
  129. gData.warnTipData.setSolution(0);
  130. }
  131. }
  132. this.uploadAverageEcpm();
  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. public async uploadAverageEcpm(){
  149. let data = {};
  150. let response = await mk.http.sendData('user/adShowConfig', data);
  151. if (response.errcode != 0) {
  152. return;
  153. }
  154. this.adShowConfig = response.data;
  155. mk.data.setTAEventUser(0, "average_ecpm", this.adShowConfig.average_ecpm);
  156. mk.console.logSingle("user/adShowConfig", response.data);
  157. }
  158. private initConfigs(data) {
  159. // console.log('config ', data);
  160. this.configs = data;
  161. this.funOpenData = this.configs.ServerConfig.Functionswitch.split(",");
  162. //从服务器解析配置
  163. this.setProductMapFromJson();
  164. gData.loginData.popIdentifySwitch = this.configs.ServerConfig.popIdentifySwitch.split(";");
  165. this.prohibiJBAd = this.configs.ServerConfig.ProhibitJBAd.split(";");
  166. this.prohibitProductionAd = this.configs.ServerConfig.ProhibitProductionAd.split(";");
  167. this.productionAdMaxTimes = this.configs.ServerConfig.ProductionAdMax;
  168. gData.gameData.shareUrl = this.configs.ServerConfig.shareUrl;
  169. gData.gameData.shareTitle = this.configs.ServerConfig.shareTitle;
  170. gData.gameData.shareDes = this.configs.ServerConfig.shareDes;
  171. gData.gameData.shareImgUrl = this.configs.ServerConfig.shareImgUrl;
  172. gData.gameData.RawInsectArr = this.configs.ServerConfig.RawInsect.split(',');
  173. //富翁银行
  174. gData.safeDepositBoxData.richBankConfig = this.configs.BankTask;
  175. gData.gameData.welfareOpenLimit = parseInt(this.configs.ServerConfig.welfareOpen);
  176. gData.gameData.orderRewardType = parseInt(this.configs.ServerConfig.OrderReward);
  177. //gData.gameData.taskRedBagAutoShowLimit = parseInt(this.configs.ServerConfig.harvestSwitch);
  178. gData.gameData.insectAutoShowLimit = parseInt(this.configs.ServerConfig.StopProductionSwitch);
  179. gData.gameData.insertAdLimit = parseInt(this.configs.ServerConfig.InsertAdCash);
  180. gData.gameData.insertAdSwitch = this.configs.ServerConfig.InsertAdScene.split(",");
  181. //gData.gameData.fullScreenAdSwitch = this.configs.ServerConfig.FullScreenAdScene.split(",");
  182. }
  183. /**
  184. * 初始化玩家数据
  185. */
  186. private initPlayerProp(res_data) {
  187. this.playerProp = new PlayerProp();
  188. this.playerProp.cashIndex = res_data.cashIndex;
  189. this.playerProp.gameUserData = res_data.gameUserData;
  190. this.playerProp.isSignInToday = res_data.isSignInToday;
  191. this.playerProp.isWithdrawable = res_data.isWithdrawable;
  192. this.playerProp.lastTime = res_data.lastTime;
  193. this.playerProp.loginDays = res_data.loginDays;
  194. this.playerProp.newPlayer = res_data.newPlayer;
  195. this.playerProp.initPiggyBank(res_data.piggyBank);
  196. this.playerProp.piggyBankCashTimes = res_data.piggyBankCashTimes;
  197. this.playerProp.redMoney = res_data.redMoney == null ? 0 : res_data.redMoney;
  198. this.playerProp.signInDay = res_data.signInDay;
  199. this.playerProp.totalPiggyBankCashTimes = res_data.totalPiggyBankCashTimes;
  200. this.playerProp.turntableTimes = res_data.turntableTimes;
  201. this.playerProp.versioncfg = res_data.versioncfg;
  202. this.playerProp.isFirstRedMoney = res_data.isFirstRedMoney;
  203. gData.adData.watchNumToday = res_data.dayVideoTimesForRedMoney == null ? 0 : res_data.dayVideoTimesForRedMoney;
  204. this.playerProp.gradeLevel = res_data.farmLevel
  205. this.playerProp.userTuCaoInfo = res_data.userWelFareTaskInfo;
  206. this.playerProp.farmExpValue = res_data.userExp;
  207. this.playerProp.farmGradeData = res_data.userFarmGrageRewardInfo;
  208. this.playerProp.userNoviceWeFareInfo = res_data.userNoviceWeFareInfo;
  209. this.playerProp.redMoneyCashPayRecordList = res_data.redMoneyCashPayRecordList;
  210. this.playerProp.userFarmTaskInfo = res_data.userFarmTaskInfo;
  211. this.playerProp.speedUpLeftTimes = res_data.speedUpLeftTimes;
  212. this.playerProp.completeFarmTaskTimes = res_data.completeFarmTaskTimes;
  213. if (res_data.userOrderTaskInfo) {
  214. this.playerProp.orderData = res_data.userOrderTaskInfo;
  215. console.log("============userOrderTaskInfo123");
  216. }
  217. this.playerProp.lineRedMoney = res_data.lineRedMoney;
  218. this.playerProp.groupCode = parseInt(res_data.groupCode);
  219. //this.playerProp.orderData.overTimes = 3;
  220. //this.cloneOrderData();
  221. this.playerProp.curProductionAdTimes = res_data.dailyProductionTimes;
  222. mk.data.setTAUserID(gData.loginData.uin);
  223. mk.data.setTAEventUser(0, 'logindays_total', this.playerProp.loginDays);
  224. if (this.playerProp.completeFarmTaskTimes == 0) {
  225. mk.data.setTAEventUser(0, 'Cumulative_task', gData.gameData.playerProp.completeFarmTaskTimes);
  226. }
  227. if (gData.loginData.isFirstIn) {
  228. gData.loginData.isFirstIn = false;
  229. mk.data.setTAEventRegister();
  230. mk.data.sendDataEvent('ABTest', `触发${this.playerProp.groupCode}方案`);
  231. console.log(`ABTest=====${this.playerProp.groupCode}`);
  232. //注册时版本号
  233. mk.data.setTAEventUserStr(0, 'regtime_app_id', gData.appData.appVersion);
  234. //星云uid
  235. mk.data.setTAEventUserStr(0, 'xy_uid', gData.loginData.uin);
  236. mk.data.setTAEventUser(0, 'farm_lv', gData.gameData.playerProp.gradeLevel);
  237. }
  238. //当前版本号
  239. mk.data.setTAEventUserStr(0, 'now_app_id', gData.appData.appVersion);
  240. //渠道号
  241. mk.data.setTAEventUserStr(0, 'channel_id', gData.appData.umengChannel);
  242. //富翁银行
  243. gData.safeDepositBoxData.richBankCashAmount = res_data.richBankCashAmount;
  244. gData.safeDepositBoxData.currentRichBankCashTaskIndex = res_data.currentRichBankCashTaskIndex;
  245. //gData.safeDepositBoxData.addRichBankFinishIndex = res_data.addRichBankFinishIndex;
  246. // if (gData.safeDepositBoxData.currentRichBankCashTaskIndex > 0) {
  247. // gData.safeDepositBoxData.addRichBankFinishIndex = gData.safeDepositBoxData.currentRichBankCashTaskIndex;
  248. // }
  249. gData.safeDepositBoxData.isStartBankTask = res_data.isStartRichBankTask;
  250. gData.safeDepositBoxData.richBankDailyVideoTimes = res_data.richBankDailyVideoTimes;
  251. gData.safeDepositBoxData.richbankLoginDays = res_data.richbankLoginDays;
  252. gData.safeDepositBoxData.richBankDailyTotelVideoTimes = res_data.richBankDailyTotelVideoTimes;
  253. console.log(`richBankDailyTotelVideoTimes ======== ${res_data.richBankDailyTotelVideoTimes}`);
  254. // //test
  255. // this.playerProp.completeFarmTaskTimes = 3;
  256. }
  257. public cloneOrderData(isRefresh = false) {
  258. let value = mk.storage.getStorage(StorageKey.copyOrderData);
  259. if (value && !isRefresh) {
  260. this.playerProp.copyOrderData = [];
  261. let v = value.split(",");
  262. for (let i = 0; i != v.length; ++i) {
  263. this.playerProp.copyOrderData.push(parseInt(v[i]));
  264. }
  265. } else {
  266. let orderData = this.playerProp.orderData;
  267. if (orderData) {
  268. this.playerProp.copyOrderData = [];
  269. if (orderData && orderData.orderTaskList) {
  270. let len = orderData.orderTaskList.length;
  271. for (let i = 0; i != len; ++i) {
  272. this.playerProp.copyOrderData.push(this.playerProp.orderData.orderTaskList[i].completeCount);
  273. }
  274. mk.storage.setStorage(StorageKey.copyOrderData, this.playerProp.copyOrderData);
  275. }
  276. }
  277. }
  278. mk.console.logSingle('cloneOrderData', this.playerProp.copyOrderData);
  279. }
  280. public updateOrderTaskCopyData(id: number) {
  281. if (this.playerProp.orderData && this.playerProp.orderData.orderTaskList) {
  282. let productJson = this.configs.Product;
  283. let orderData = this.playerProp.orderData.orderTaskList;
  284. let len = orderData.length;
  285. for (let i = 0; i != len; ++i) {
  286. let dataE = orderData[i];
  287. if (dataE.Id <= productJson.length) {
  288. let productData = productJson[dataE.Id - 1];
  289. if (productData.picture == id) {
  290. this.playerProp.copyOrderData[i]++;
  291. mk.storage.setStorage(StorageKey.copyOrderData, this.playerProp.copyOrderData);
  292. break;
  293. }
  294. }
  295. }
  296. } else {
  297. this.playerProp.copyOrderData = [];
  298. cc.sys.localStorage.removeItem(StorageKey.copyOrderData);
  299. }
  300. }
  301. public setOrderAniFinishNum() {
  302. ++this.orderAinFinishNum;
  303. if (this.orderAinFinishNum >= 3) {
  304. this.orderAinFinishNum = 0;
  305. setTimeout(() => {
  306. mk.event.emit("flyOrderAni");
  307. }, 500)
  308. }
  309. }
  310. /**
  311. * 保存单个数据
  312. */
  313. public async setProp(key: GameProp, value: any) {
  314. let data = {
  315. key: key + '',
  316. value: value
  317. };
  318. this.props.set(key, value);
  319. await mk.http.sendData('savePlayerProp', data);
  320. this.savePropFinish = true;
  321. }
  322. /**
  323. * 保存多个数据
  324. */
  325. public async setProps(arr: { key: GameProp, value: any }[]) {
  326. let needProp = {};
  327. for (let i = 0; i < arr.length; i++) {
  328. needProp[arr[i].key + ''] = arr[i].value;
  329. }
  330. let data = {
  331. needProp: needProp
  332. };
  333. for (let i = 0; i < arr.length; i++) {
  334. this.props.set(arr[i].key, arr[i].value);
  335. }
  336. await mk.http.sendData('saveAllPlayerProp', data);
  337. this.savePropsFinish = true;
  338. }
  339. /** 获取属性 */
  340. public getProp(key: GameProp): any {
  341. if (this.props == null) {
  342. return 0;
  343. }
  344. let value = this.props.get(key);
  345. return value;
  346. }
  347. /**
  348. * 向服务器请求所有属性后更新
  349. */
  350. public async getAllProps() {
  351. let response = await mk.http.sendData('getAllPlayerProp', {});
  352. if (response.errcode != 0) {
  353. return;
  354. }
  355. this.initProps(response.data);
  356. this.getPropsFnish = true;
  357. }
  358. private initProps(data) {
  359. if (data == null) {
  360. return;
  361. }
  362. for (let key in data) {
  363. this.props.set(parseInt(key), data[key]);
  364. }
  365. this.setFramDataMapByServer();
  366. this.setPastureDataMapByServer();
  367. this.setFactoryDataMapByServer();
  368. this.initProductTimes();
  369. this.initLeftTimes();
  370. this.initFarmMapGetRewardData();
  371. //this.initCashOutTimes();
  372. // let isNewTask = this.getProp(GameProp.redBagTaskRefresh);
  373. // if (isNewTask != undefined) {
  374. // this.init_redBagTask = isNewTask;
  375. // }
  376. }
  377. private initLeftTimes() {
  378. let lefttimes = this.getProp(GameProp.leftTimes);
  379. if (lefttimes == undefined) {
  380. this.leftTimes = parseInt(this.configs.ServerConfig.FreeProduction);
  381. this.setProp(GameProp.leftTimes, this.leftTimes);
  382. }
  383. else {
  384. this.leftTimes = lefttimes;
  385. }
  386. this.maxTimes = parseInt(this.configs.ServerConfig.ProductionMax);
  387. this.ProductionRecovery = parseInt(this.configs.ServerConfig.ProductionRecovery);
  388. // //test
  389. // this.leftTimes = 1;
  390. // this.maxTimes = 20;
  391. // this.ProductionRecovery = 1;
  392. }
  393. /** 增加减少生产次数
  394. * @param add 增减变量
  395. */
  396. public async changeLeftTimes(add, isIgnoreMaxTimes = false, isRefresh = true) {
  397. gData.gameData.leftTimes += add;
  398. if (add > 0 && !isIgnoreMaxTimes) {
  399. gData.gameData.leftTimes = (gData.gameData.leftTimes > gData.gameData.maxTimes ? gData.gameData.maxTimes : gData.gameData.leftTimes);
  400. }
  401. if (gData.gameData.leftTimes < 0) {
  402. gData.gameData.leftTimes = 0;
  403. }
  404. await gData.gameData.setProp(GameProp.leftTimes, gData.gameData.leftTimes);
  405. if (isRefresh) {
  406. gData.gameData.init_leftTimes = true;
  407. }
  408. }
  409. //图鉴领取数据
  410. private _farmMapRewardData = [];
  411. public getFarmMapRewardState(index) {
  412. if (index.i < this._farmMapRewardData.length) {
  413. if (index.j < this._farmMapRewardData[index.i].length) {
  414. return this._farmMapRewardData[index.i][index.j];
  415. }
  416. }
  417. return 1;
  418. }
  419. public setFarmMapRewardState(index, state) {
  420. if (index.i < this._farmMapRewardData.length) {
  421. if (index.j < this._farmMapRewardData[index.i].length) {
  422. this._farmMapRewardData[index.i][index.j] = state;
  423. this.setProp(GameProp.farmMapGetRewardData, this._farmMapRewardData);
  424. }
  425. }
  426. }
  427. private initFarmMapGetRewardData() {
  428. this._farmMapRewardData = this.getProp(GameProp.farmMapGetRewardData);
  429. if (!this._farmMapRewardData) {
  430. this._farmMapRewardData = [];
  431. }
  432. let needSync = false;
  433. let index = 0;
  434. this._productTypeMap.forEach((value, key) => {
  435. if (this._farmMapRewardData.length <= index) {
  436. let len = value.length;
  437. let arr = [];
  438. for (let i = 0; i != len; ++i) {
  439. arr.push(0);
  440. }
  441. this._farmMapRewardData.push(arr);
  442. needSync = true;
  443. } else {
  444. let data = this._farmMapRewardData[index];
  445. let len = value.length;
  446. for (let i = 0; i != len; ++i) {
  447. if (i >= data.length) {
  448. data.push(0);
  449. needSync = true;
  450. }
  451. }
  452. }
  453. ++index;
  454. });
  455. if (needSync) {
  456. this.setProp(GameProp.farmMapGetRewardData, this._farmMapRewardData);
  457. }
  458. }
  459. //提现次数
  460. public _cashOutTimes = 0;
  461. public initCashOutTimes() {
  462. let v = this.getProp(GameProp.cashOutTimes);
  463. if (v) {
  464. this._cashOutTimes = v;
  465. } else {
  466. this._cashOutTimes = 0;
  467. }
  468. }
  469. public addCashOutTimes() {
  470. this._cashOutTimes += 1;
  471. console.log(`===========${this._cashOutTimes}`);
  472. this.setProp(GameProp.cashOutTimes, this._cashOutTimes);
  473. }
  474. /** 是否是新用户 */
  475. public isNewPlayer(): boolean {
  476. let v = this.getProp(GameProp.newPlayer);
  477. return v == 0;
  478. }
  479. //*********** ================= 农场数据 ================== */
  480. /** 农田数据 服务器数据 */
  481. private _farmData = [];
  482. /** 农田字典 本地数据,方便操作*/
  483. private _farmDataMap: Map<number, any> = new Map();
  484. //刷新农田
  485. public needFreshArr = [];
  486. /** 随机获取可种植物品 */
  487. getRandomPlantConfig(out?: any) {
  488. let id = 0;
  489. let isNoHaveCurTab = true;
  490. let isNoAllComplete = false;
  491. let isOrderDataInvalid = false;
  492. let isMatchSuccess = false;
  493. let productType = [];
  494. let animalId = [];
  495. let data = this.playerProp.orderData;
  496. if (data) {
  497. let orderData = data.orderTaskList;
  498. let productJson = this.configs.Product;
  499. for (let i = 0; i != orderData.length; ++i) {
  500. let dataE = orderData[i];
  501. if (dataE.completeCount < dataE.taskCount) {
  502. if (dataE.Id <= productJson.length) {
  503. isNoAllComplete = true;
  504. let productData = productJson[dataE.Id - 1];
  505. if (productData.tab == ProductType.nzw) {
  506. let max = this.getMaxProductExtra(ProductType.nzw);
  507. if (max && productData.picture <= max) {
  508. id = productData.picture;
  509. isNoHaveCurTab = false;
  510. isMatchSuccess = true;
  511. this.nextType = 1;
  512. mk.console.logSingle("getRandomPlantConfig=>", id);
  513. break;
  514. }
  515. } else if (productData.tab == ProductType.dw) {
  516. animalId.push(productData.picture);
  517. } else {
  518. productType.push(productData.tab);
  519. }
  520. } else {
  521. isOrderDataInvalid = true;
  522. break;
  523. }
  524. }
  525. }
  526. if (!isMatchSuccess) {
  527. // let picId = this.doFarmMapDataCheck(0);
  528. // if (picId) {
  529. // id = picId;
  530. // } else
  531. {
  532. id = Util.rnd(10001, this.getMaxProductExtra(ProductType.nzw));
  533. this.nextType = 1
  534. }
  535. }
  536. } else {
  537. isOrderDataInvalid = true;
  538. // let picId = this.doFarmMapDataCheck(0);
  539. // if (picId) {
  540. // id = picId;
  541. // } else
  542. {
  543. id = Util.rnd(10001, this.getMaxProductExtra(ProductType.nzw));
  544. this.nextType = 1
  545. }
  546. }
  547. //选择逻辑处理
  548. if (isOrderDataInvalid) {
  549. return this.getProductMap(id);
  550. } else {
  551. if (isNoHaveCurTab) {
  552. if (isNoAllComplete) {
  553. let isHaveEmpty = false;
  554. for (let i = 0; i != productType.length; ++i) {
  555. let factoryIcon = gData.factorySystem.factoryIcons;
  556. let len = factoryIcon.length;
  557. for (var j = 0; j < len; j++) {
  558. let tab = this.getTabByConfigID(factoryIcon[j].configID);
  559. if (tab == productType[i] && factoryIcon[j].data.state == FactroyState.Empty) {
  560. isHaveEmpty = true;
  561. out.state = 1;
  562. break;
  563. }
  564. }
  565. }
  566. if (!isHaveEmpty) {
  567. for (let i = 0; i != animalId.length; ++i) {
  568. let pastureIcon = gData.pastureSystem.pastureIcons;
  569. let len = pastureIcon.length;
  570. for (var j = 0; j < len; j++) {
  571. if (pastureIcon[j].data.productID == animalId[i] && pastureIcon[j].data.state == PastureState.Empty) {
  572. isHaveEmpty = true;
  573. out.state = 2;
  574. break;
  575. }
  576. }
  577. }
  578. }
  579. if (isHaveEmpty) {
  580. return null;
  581. } else {
  582. return this.getProductMap(id);
  583. }
  584. } else {
  585. return this.getProductMap(id);
  586. }
  587. } else {
  588. return this.getProductMap(id);
  589. }
  590. }
  591. //id = Util.rnd(10001, this.getMaxProduct(ProductType.nzw));
  592. //return this.getProductMap(id);
  593. }
  594. getRandomPlantConfigExtra(out: any) {
  595. let id = 0;
  596. let cropArray = [];
  597. let factoryArray = [];
  598. let animalArray = [];
  599. let data = this.playerProp.orderData;
  600. if (data) {
  601. let orderData = data.orderTaskList;
  602. let productJson = this.configs.Product;
  603. for (let i = 0; i != orderData.length; ++i) {
  604. let dataE = orderData[i];
  605. if (dataE.completeCount < dataE.taskCount) {
  606. if (dataE.Id <= productJson.length) {
  607. let productData = productJson[dataE.Id - 1];
  608. if (productData.tab == ProductType.nzw) {
  609. let max = this.getMaxProductExtra(ProductType.nzw);
  610. if (max && productData.picture <= max) {
  611. cropArray.push(productData.picture);
  612. }
  613. } else if (productData.tab == ProductType.dw) {
  614. animalArray.push(productData.picture);
  615. } else {
  616. factoryArray.push(productData);
  617. }
  618. }
  619. }
  620. }
  621. //从三种类型随机选择逻辑
  622. let typeArr = [];
  623. let matchSuccessFactorys = null;
  624. let matchSuccessPastures = null;
  625. if (cropArray.length > 0) {
  626. typeArr.push(0);
  627. }
  628. if (factoryArray.length > 0) {
  629. matchSuccessFactorys = gData.factorySystem.isHaveEmptyFactory(factoryArray);
  630. if (matchSuccessFactorys.length > 0) {
  631. typeArr.push(1);
  632. }
  633. }
  634. if (animalArray.length > 0) {
  635. matchSuccessPastures = gData.pastureSystem.isHaveEmptyPasture(animalArray);
  636. if (matchSuccessPastures.length > 0) {
  637. typeArr.push(2);
  638. }
  639. }
  640. if (typeArr.length > 0) {
  641. let rand = mk.math.random(0, typeArr.length - 1);
  642. let type = typeArr[rand];
  643. if (type == 0) {
  644. let randCrop = mk.math.random(0, cropArray.length - 1);
  645. id = cropArray[randCrop];
  646. this.nextType = 1
  647. return this.getProductMap(id);
  648. } else if (type == 1) {
  649. let randFactory = mk.math.random(0, matchSuccessFactorys.length - 1);
  650. let factory = matchSuccessFactorys[randFactory];
  651. this.nextCanProduct = this.getProductMap(factory.picture);
  652. this.nextMake = factory.key;
  653. this.nextType = 3;
  654. return this.nextMake;
  655. } else if (type == 2) {
  656. let randPasture = mk.math.random(0, matchSuccessPastures.length - 1);
  657. let pasture = matchSuccessPastures[randPasture];
  658. this.nextCanProduct = this.getProductMap(pasture.data.productID);
  659. this.nextMake = pasture
  660. this.nextType = 2;
  661. return pasture;
  662. }
  663. } else {
  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. if (this.playerProp.orderData.overTimes < arr[i].value) {
  1247. data = { id: id, state: PastureState.Lock, productID: arr[i].picture, growSpan: 0 };
  1248. }
  1249. else {
  1250. data = { id: id, state: PastureState.Empty, productID: arr[i].picture, growSpan: 0 };
  1251. }
  1252. } else {
  1253. data = { id: id, state: PastureState.Lock, productID: arr[i].picture, growSpan: 0 };
  1254. }
  1255. this._pastureData.push(data);
  1256. this._pastureDataMap.set(id, data);
  1257. id++;
  1258. }
  1259. //更新到服务器
  1260. this.setProp(GameProp.pastureData, this._pastureData);
  1261. }
  1262. else {
  1263. let sickTimes = 0;
  1264. for (var i = 0; i < len; i++) {
  1265. this._pastureDataMap.set(this._pastureData[i].id, this._pastureData[i]);
  1266. if (this._pastureData[i].state == PastureState.Sick) {
  1267. sickTimes++;
  1268. }
  1269. }
  1270. this.RawInsectCurArr[1] = sickTimes;
  1271. }
  1272. }
  1273. //------------- 工厂数据-----------
  1274. /** 工厂数据 服务器数据 */
  1275. private _factoryData = [];
  1276. /** 工厂字典 本地数据,方便操作*/
  1277. private _factoryDataMap: Map<number, any> = new Map();
  1278. public setFactoryDataMap(id, data, sendToServer = true) {
  1279. this._factoryDataMap.set(id, data);
  1280. let len = this._factoryData.length;
  1281. for (var i = 0; i < len; i++) {
  1282. if (this._factoryData[i].id == id) {
  1283. this._factoryData[i].state = data.state;
  1284. this._factoryData[i].productID = data.productID;
  1285. this._factoryData[i].growSpan = data.growSpan;
  1286. break;
  1287. }
  1288. }
  1289. this.needFreshArr.push(id);
  1290. //更新到服务器
  1291. if (sendToServer) {
  1292. this.freshSendToServer(3);
  1293. }
  1294. }
  1295. public getFactoryDataMap(id) {
  1296. return this._factoryDataMap.get(id);
  1297. }
  1298. /** 服务器数据设置到本地 */
  1299. public setFactoryDataMapByServer() {
  1300. this._factoryData = this.getProp(GameProp.factoryData);
  1301. if (!this._factoryData) {
  1302. this._factoryData = [];
  1303. }
  1304. let isUpdate = false;
  1305. let len = this._factoryData.length;
  1306. //新玩家初始化工厂数据
  1307. if (len < 6) {
  1308. let id = 30004;
  1309. let data = null;
  1310. let tab = null;
  1311. for (var i = 0; i < 6; i++) {
  1312. tab = this.getTabByConfigID(id);
  1313. let arr = this.getProductArrByType(tab);
  1314. if (this.playerProp.orderData) {
  1315. if (this.playerProp.orderData.overTimes < arr[0].value) {
  1316. data = { id: id, state: FactroyState.Lock, productID: 0, growSpan: 0 };
  1317. }
  1318. else {
  1319. data = { id: id, state: FactroyState.Empty, productID: 0, growSpan: 0 };
  1320. //更新最大可购买商品
  1321. //this.setMaxProduct(arr[0].picture, true);
  1322. // let is = this.addProductUnlockMaxId(tab, arr[0].picture);
  1323. // if(!isUpdate)
  1324. // {
  1325. // isUpdate = is;
  1326. // }
  1327. }
  1328. } else {
  1329. data = { id: id, state: FactroyState.Lock, productID: 0, growSpan: 0 };
  1330. }
  1331. this._factoryData.push(data);
  1332. this._factoryDataMap.set(id, data);
  1333. id++;
  1334. }
  1335. //更新到服务器
  1336. this.setProp(GameProp.factoryData, this._factoryData);
  1337. }
  1338. else {
  1339. let sickTimes = 0;
  1340. let id = 30004;
  1341. let tab = null;
  1342. for (var i = 0; i < len; i++) {
  1343. tab = this.getTabByConfigID(id);
  1344. let arr = this.getProductArrByType(tab);
  1345. this._factoryDataMap.set(this._factoryData[i].id, this._factoryData[i]);
  1346. if (this._factoryData[i].state == FactroyState.Sick) {
  1347. sickTimes++;
  1348. }
  1349. id++;
  1350. }
  1351. this.RawInsectCurArr[2] = sickTimes;
  1352. }
  1353. // if(isUpdate)
  1354. // {
  1355. // this.updateDataToSever();
  1356. // }
  1357. }
  1358. /** 通过工厂建筑物ID获取标签 */
  1359. getTabByConfigID(configID: number): ProductType {
  1360. let tab = ProductType.bmhc;
  1361. switch (configID) {
  1362. case 30004:
  1363. tab = ProductType.bmhc;
  1364. break;
  1365. case 30005:
  1366. tab = ProductType.gdp;
  1367. break;
  1368. case 30006:
  1369. tab = ProductType.ztc;
  1370. break;
  1371. case 30007:
  1372. tab = ProductType.lrc;
  1373. break;
  1374. case 30008:
  1375. tab = ProductType.gfmg;
  1376. break;
  1377. case 30009:
  1378. tab = ProductType.kcd;
  1379. break;
  1380. }
  1381. return tab;
  1382. }
  1383. /** 通过标签获取工厂建筑物ID */
  1384. getConfigIDByTab(tab: ProductType): number {
  1385. let configID = 0;
  1386. switch (tab) {
  1387. case ProductType.bmhc:
  1388. configID = 30004;
  1389. break;
  1390. case ProductType.gdp:
  1391. configID = 30005;
  1392. break;
  1393. case ProductType.ztc:
  1394. configID = 30006;
  1395. break;
  1396. case ProductType.lrc:
  1397. configID = 30007;
  1398. break;
  1399. case ProductType.gfmg:
  1400. configID = 30008;
  1401. break;
  1402. case ProductType.kcd:
  1403. configID = 30009;
  1404. break;
  1405. }
  1406. return configID;
  1407. }
  1408. getIndex(data) {
  1409. let index: any = {};
  1410. index.i = 0;
  1411. index.j = 0;
  1412. switch (data.tab) {
  1413. case '农作物':
  1414. index.i = 0;
  1415. index.j = data.picture - 10001;
  1416. break;
  1417. case '动物':
  1418. index.i = 1;
  1419. index.j = data.picture - 20001;
  1420. break;
  1421. case '爆米花厂':
  1422. index.i = 2;
  1423. index.j = data.picture - 20004;
  1424. break;
  1425. case '糕点铺':
  1426. index.i = 3;
  1427. index.j = data.picture - 20013;
  1428. break;
  1429. case '制糖厂':
  1430. index.i = 4;
  1431. index.j = data.picture - 20010;
  1432. break;
  1433. case '炼乳厂':
  1434. index.i = 5;
  1435. index.j = data.picture - 20007;
  1436. break;
  1437. case '功夫面馆':
  1438. index.i = 6;
  1439. index.j = data.picture - 20025;
  1440. break;
  1441. case '快餐店':
  1442. index.i = 7;
  1443. index.j = data.picture - 20019;
  1444. break;
  1445. }
  1446. return index;
  1447. }
  1448. /** 发送数据到服务器 */
  1449. freshSendToServer(type) {
  1450. switch (type) {
  1451. case 1:
  1452. this.setProp(GameProp.farmData, this._farmData);
  1453. break;
  1454. case 2:
  1455. this.setProp(GameProp.pastureData, this._pastureData);
  1456. break;
  1457. case 3:
  1458. this.setProp(GameProp.factoryData, this._factoryData);
  1459. break;
  1460. }
  1461. }
  1462. /** 最大可种植/生产商品数组 */
  1463. private _maxProduct = [];
  1464. public getMaxProduct(tab) {
  1465. if (this._maxProduct) {
  1466. let len = this._maxProduct.length;
  1467. let data = null;
  1468. for (var i = 0; i < len; i++) {
  1469. data = this._maxProduct[i];
  1470. if (data.tab == tab) {
  1471. return data.productID;
  1472. }
  1473. }
  1474. }
  1475. return null;
  1476. }
  1477. getMaxProductExtra(tab) {
  1478. if (this._productMakeTimesData.productUnlockMaxId) {
  1479. let productId = this._productMakeTimesData.productUnlockMaxId.get(tab);
  1480. return productId;
  1481. }
  1482. return null;
  1483. }
  1484. /** 设置最大可生产商品
  1485. * @param id 产品id
  1486. * @param unlock 是否是解锁增加
  1487. */
  1488. public setMaxProduct(id, unlock = false) {
  1489. let config = this.getProductMap(id);
  1490. if (!this._maxProduct) {
  1491. this._maxProduct = [];
  1492. }
  1493. let len = this._maxProduct.length;
  1494. let data = null;
  1495. let has = false;
  1496. for (var i = 0; i < len; i++) {
  1497. data = this._maxProduct[i];
  1498. if (data.tab == config.tab) {
  1499. if (data.productID < id) {
  1500. data.productID = id;
  1501. data.id = config.id;
  1502. }
  1503. has = true;
  1504. break;
  1505. }
  1506. }
  1507. if (!has && unlock) {
  1508. data = { tab: config.tab, productID: id, id: config.id };
  1509. this._maxProduct.push(data);
  1510. }
  1511. gData.farmMapData.isStateChange = true;
  1512. this.updateMaxProduct();
  1513. }
  1514. /** 农场升级时解锁工厂,检查最大可种植/生产商品 */
  1515. public checkTaskFinishUnLock() {
  1516. let isUpdateToSever = false;
  1517. for (var key in ProductType) {
  1518. let tab = ProductType[key];
  1519. let configArr = this.getProductArrByType(tab);
  1520. let len = configArr.length;
  1521. let data = null;
  1522. let needUpdate = false;
  1523. switch (tab) {
  1524. case ProductType.nzw:
  1525. break;
  1526. case ProductType.dw:
  1527. let id = 30001;
  1528. needUpdate = false;
  1529. let maxId = 0;
  1530. for (var i = 0; i < len; i++) {
  1531. data = this.getPastureDataMap(id);
  1532. if (this.playerProp.orderData) {
  1533. if (this.playerProp.orderData.overTimes >= configArr[i].value) {
  1534. if (data.state == PastureState.Lock) {
  1535. data = { id: id, state: PastureState.Empty, productID: configArr[i].picture, growSpan: 0 };
  1536. this.setPastureDataMap(id, data, false);
  1537. needUpdate = true;
  1538. }
  1539. maxId = configArr[i].picture;
  1540. }
  1541. }
  1542. id++;
  1543. }
  1544. console.log(`checkTaskFinishUnLock11=====${maxId}`);
  1545. if (maxId != 0) {
  1546. //更新最大可购买商品
  1547. //this.setMaxProduct(maxId, true);
  1548. let is = this.addProductUnlockMaxId(tab, maxId);
  1549. if (!isUpdateToSever) {
  1550. isUpdateToSever = is;
  1551. }
  1552. }
  1553. //更新到服务器
  1554. if (needUpdate) {
  1555. this.setProp(GameProp.pastureData, this._pastureData);
  1556. this.setNextProduct();
  1557. }
  1558. break;
  1559. default:
  1560. //工厂解锁根据第一个商品
  1561. needUpdate = false;
  1562. let configID = this.getConfigIDByTab(tab);
  1563. data = this.getFactoryDataMap(configID);
  1564. if (this.playerProp.orderData) {
  1565. if (this.playerProp.orderData.overTimes >= configArr[0].value) {
  1566. if (data.state == FactroyState.Lock) {
  1567. data = { id: id, state: FactroyState.Empty, productID: 0, growSpan: 0 };
  1568. this.setFactoryDataMap(configID, data, false);
  1569. needUpdate = true;
  1570. }
  1571. //更新最大可购买商品
  1572. //this.setMaxProduct(configArr[0].picture, true);
  1573. console.log(`checkTaskFinishUnLock222=====${maxId}`);
  1574. let is = this.addProductUnlockMaxId(tab, configArr[0].picture);
  1575. if (!isUpdateToSever) {
  1576. isUpdateToSever = is;
  1577. }
  1578. }
  1579. }
  1580. if (needUpdate) {
  1581. this.setProp(GameProp.factoryData, this._factoryData);
  1582. this.setNextProduct();
  1583. }
  1584. break;
  1585. }
  1586. }
  1587. if (isUpdateToSever) {
  1588. console.log('===================isUpdateToSever222');
  1589. this.updateDataToSever();
  1590. //需要更新最大生产id
  1591. gData.farmMapData.isStateChange = true;
  1592. this.updateMaxProduct();
  1593. }
  1594. }
  1595. checkCanSpeedUp(pop = false) {
  1596. let can = false;
  1597. can = gData.farmSystem.canSpeedUp();
  1598. if (!can) {
  1599. can = gData.pastureSystem.canSpeedUp();
  1600. if (!can) {
  1601. can = gData.factorySystem.canSpeedUp();
  1602. }
  1603. }
  1604. if (can && pop) {
  1605. mk.ui.openPanel('module/speedUpUI/speedUp');
  1606. }
  1607. return can;
  1608. }
  1609. popSpeedUpByRate() {
  1610. let isPop = false;
  1611. let rate = gData.adData.getPerByEcpm(RateConfig.RC_popSpeedUp);
  1612. if (rate >= Math.random()) {
  1613. isPop = gData.pastureSystem.canSpeedUp();
  1614. if (!isPop) {
  1615. isPop = gData.factorySystem.canSpeedUp();
  1616. }
  1617. }
  1618. if (isPop) {
  1619. mk.ui.openPanel('module/speedUpUI/speedUp');
  1620. }
  1621. return isPop;
  1622. }
  1623. setHarvest() {
  1624. gData.farmSystem.setHarvest();
  1625. gData.pastureSystem.setHarvest();
  1626. gData.factorySystem.setHarvest();
  1627. }
  1628. checkCanHarvest() {
  1629. let can = false;
  1630. can = gData.farmSystem.canHarvest();
  1631. if (!can) {
  1632. can = gData.pastureSystem.canHarvest();
  1633. if (!can) {
  1634. can = gData.factorySystem.canHarvest();
  1635. }
  1636. }
  1637. return can;
  1638. }
  1639. checkCanClearSick() {
  1640. let can = false;
  1641. can = gData.farmSystem.canClearSick();
  1642. if (!can) {
  1643. can = gData.pastureSystem.canClearSick();
  1644. if (!can) {
  1645. can = gData.factorySystem.canClearSick();
  1646. }
  1647. }
  1648. return can;
  1649. }
  1650. doPointToXYLogic() {
  1651. let value = mk.storage.getStorage('cash_out');
  1652. if (!value) {
  1653. mk.storage.setStorage('cash_out', 1);
  1654. mk.data.sendXYEvent('cash_1', `第一次提现`);
  1655. } else {
  1656. if (value == 1) {
  1657. mk.storage.setStorage('cash_out', 2);
  1658. mk.data.sendXYEvent('cash_2', `第二次提现`);
  1659. } else if (value == 2) {
  1660. mk.storage.setStorage('cash_out', 3);
  1661. mk.data.sendXYEvent('cash_3', `第三次提现`);
  1662. }
  1663. }
  1664. }
  1665. /** 更新最大可种植产品到服务器 */
  1666. async updateMaxProduct() {
  1667. if (this.maxProductToServer) {
  1668. //let data = { "unLockProductList": this._maxProduct };
  1669. let data = { "unLockProductList": [] };
  1670. let maxProductData = this._productMakeTimesData.productUnlockMaxId;
  1671. maxProductData.forEach((value, key) => {
  1672. let config = this.getProductMap(value);
  1673. let d = { tab: key, productID: value, id: config.id };
  1674. data.unLockProductList.push(d);
  1675. });
  1676. mk.console.logSingle("updateMaxProduct", data);
  1677. let respone = await mk.http.sendData('orderTask/updateUnlockProduct', data);
  1678. console.log("------");
  1679. }
  1680. }
  1681. popTableScreenADLogic(type: number) {
  1682. let str = null;
  1683. switch (type) {
  1684. case 0:
  1685. str = InterAdType.interstitial1_click_1;
  1686. break;
  1687. case 1:
  1688. str = InterAdType.interstitial1_click_2;
  1689. break;
  1690. case 2:
  1691. str = InterAdType.interstitial1_click_3;
  1692. break;
  1693. case 3:
  1694. str = InterAdType.interstitial1_click_4;
  1695. break;
  1696. case 4:
  1697. str = InterAdType.interstitial1_click_5;
  1698. break;
  1699. case 5:
  1700. str = InterAdType.interstitial1_click_6;
  1701. break;
  1702. case 6:
  1703. str = InterAdType.interstitial1_click_7;
  1704. break;
  1705. case 7:
  1706. str = InterAdType.interstitial1_click_8;
  1707. break;
  1708. case 8:
  1709. str = InterAdType.interstitial1_click_9;
  1710. break;
  1711. case 9:
  1712. str = InterAdType.interstitial1_click_10;
  1713. break;
  1714. case 10:
  1715. str = InterAdType.interstitial1_click_11;
  1716. break;
  1717. case 11:
  1718. str = InterAdType.interstitial1_click_12;
  1719. break;
  1720. case 12:
  1721. str = InterAdType.interstitial1_click_13;
  1722. break;
  1723. case 13:
  1724. str = InterAdType.interstitial1_click_14;
  1725. break;
  1726. case 14:
  1727. str = InterAdType.interstitial1_click_15;
  1728. break;
  1729. case 15:
  1730. str = InterAdType.interstitial1_click_16;
  1731. break;
  1732. case 16:
  1733. str = InterAdType.interstitial1_click_17;
  1734. break;
  1735. case 17:
  1736. str = InterAdType.interstitial1_click_18;
  1737. break;
  1738. }
  1739. let index = 0;
  1740. let rateType = null;
  1741. if(type <= 11){
  1742. index = type;
  1743. }else{
  1744. index = 12;
  1745. rateType = RateConfig.RC_afterVideo;
  1746. }
  1747. if(str != null){
  1748. let cashTimes = gData.gameData.getProp(GameProp.cashTimes);
  1749. console.log(`===========${cashTimes}`);
  1750. let is = gData.gameData.insertAdSwitch[index];
  1751. if(is == "1" && cashTimes >= gData.gameData.insertAdLimit){
  1752. gData.adData.checkPopInter(str, rateType);
  1753. }
  1754. }
  1755. }
  1756. }
  1757. /**
  1758. * 所有模块的非校验数据
  1759. */
  1760. export enum GameProp {
  1761. /** -------------------- 通用玩家数据 ------------------------- */
  1762. /** 是否新手 0新手 1老手 */
  1763. newPlayer = 1,
  1764. /** 当前新手引导步骤 */
  1765. guideID = 2,
  1766. /** 需要自动弹界面 每次登录都弹 除首次 表示今日是否要自动开 1自动开 2不自动开 其他不处理*/
  1767. isAutoOpenPanel = 3,
  1768. /** 关闭常规提现时需要自动开存钱罐 每天一次 表示今日有没有开过 */
  1769. isOpenBankOnCloseCash = 4,
  1770. //看视频次数
  1771. videoTimes = 5,
  1772. //提现次数
  1773. cashTimes = 6,
  1774. /** ------------------ 游戏核心数据 --------------------------- */
  1775. /** 农田数据 */
  1776. farmData = 11,
  1777. /** 产品生产次数 */
  1778. productMakeTimes = 12,
  1779. /** 养殖场数据 */
  1780. pastureData = 14,
  1781. /** 工厂数据 */
  1782. factoryData = 15,
  1783. /** 剩余可种植次数 */
  1784. leftTimes = 16,
  1785. /**
  1786. 图鉴领取数据*/
  1787. farmMapGetRewardData = 17,
  1788. //红包任务tag
  1789. redBagTaskRefresh = 18,
  1790. /** ------------------ 转盘数据 ------------------------------ */
  1791. turnable_leftTimes = 20,
  1792. //提现次数
  1793. cashOutTimes = 21,
  1794. }
  1795. /**
  1796. * 玩家数据
  1797. */
  1798. class PlayerProp {
  1799. /** 自定义不需要校验的数据 */
  1800. gameUserData = 0;
  1801. _isSignInToday = 0;
  1802. /**
  1803. * 今日是否有签到
  1804. * - 0 未签到,表示可以签到
  1805. * - 1 有签到,表示不可签到
  1806. */
  1807. set isSignInToday(value: number) {
  1808. this._isSignInToday = value;
  1809. gData.sign.init_data = true;
  1810. gData.gameData.init_red_point = true;
  1811. }
  1812. get isSignInToday(): number {
  1813. return this._isSignInToday;
  1814. }
  1815. private _piggyBank: number = 0;
  1816. /** 存钱罐存款 */
  1817. set piggyBank(value: number) {
  1818. if (this._piggyBank === value) return;
  1819. if (gData.gameData.playerProp.isWithdrawable && value > 0) return;// 存钱罐可提现状态,不能增加存钱罐金额
  1820. this._piggyBank = value;
  1821. gData.gameData.init_coin = true;
  1822. gData.gameData.init_red_point = true;
  1823. }
  1824. get piggyBank(): number {
  1825. return this._piggyBank;
  1826. }
  1827. /** 初始化 */
  1828. initPiggyBank(v) {
  1829. this._piggyBank = v;
  1830. }
  1831. _isWithdrawable = 0;
  1832. /**
  1833. * 存钱罐能否提现
  1834. * - 0 不能提现
  1835. * - 1 能提现
  1836. */
  1837. set isWithdrawable(value: number) {
  1838. if (this._isWithdrawable != value) {
  1839. this._isWithdrawable = value;
  1840. gData.gameData.init_red_point = true;
  1841. }
  1842. }
  1843. get isWithdrawable(): number {
  1844. return this._isWithdrawable;
  1845. }
  1846. /** 存钱罐每日提现次数 */
  1847. piggyBankCashTimes = 0;
  1848. /** 累计存钱罐每日提现次数 */
  1849. totalPiggyBankCashTimes = 0;
  1850. /** 提现进度 */
  1851. cashIndex = 0;
  1852. /** 上次登录时间 */
  1853. lastTime = 0;
  1854. /** 登录天数 */
  1855. loginDays = 0;
  1856. newPlayer = 0;
  1857. private _redMoney: number = 0;
  1858. /** 红包币数量 */
  1859. set redMoney(value: number) {
  1860. this._redMoney = value;
  1861. gData.gameData.init_coin = true;
  1862. //gData.gameData.init_red_point = true;
  1863. gData.gameData.init_wallet_redMoney = true;
  1864. mk.event.emit('refreshCoin');
  1865. mk.data.setTAEventUser(0, 'current_redmoney_stock', this._redMoney);
  1866. }
  1867. get redMoney(): number {
  1868. return this._redMoney;
  1869. }
  1870. _signInDay = 0;
  1871. /** 累计签到次数 客户端理解 上次签到天数 */
  1872. set signInDay(value: number) {
  1873. if (this._signInDay === value) return;
  1874. this._signInDay = value;
  1875. gData.sign.init_data = true;
  1876. }
  1877. get signInDay(): number {
  1878. return this._signInDay;
  1879. }
  1880. /** 转盘次数 */
  1881. turntableTimes = 0;
  1882. /** 版本号 */
  1883. versioncfg = 0;
  1884. /** 福袋数据 */
  1885. userTuCaoInfo = 0;
  1886. /** 能免费领红包 1 表示是新人第一次产出红包币,不用看视频*/
  1887. isFirstRedMoney = 0;
  1888. //农场等级
  1889. gradeLevel = 1;
  1890. //农场等级奖励数据
  1891. farmGradeData: any = {};
  1892. //农场等级名字
  1893. farmGradeName: number = 1;
  1894. //农场经验
  1895. private farmExp = 0;
  1896. set farmExpValue(value: number) {
  1897. this.farmExp = value;
  1898. gData.gameData.init_expLevel = true;
  1899. }
  1900. get farmExpValue(): number {
  1901. return this.farmExp;
  1902. }
  1903. //提现新手数据
  1904. userNoviceWeFareInfo: any = {};
  1905. //提现记录数据
  1906. redMoneyCashPayRecordList = null;
  1907. //任务红;
  1908. userFarmTaskInfo = null;
  1909. getRedMoneyCashOutTimesByIndex(index: number): number {
  1910. if (this.redMoneyCashPayRecordList) {
  1911. for (let i = 0; i != this.redMoneyCashPayRecordList.length; ++i) {
  1912. if (index === this.redMoneyCashPayRecordList[i].index) {
  1913. return this.redMoneyCashPayRecordList[i].frequency;
  1914. }
  1915. }
  1916. }
  1917. return 0;
  1918. }
  1919. /** ABTest分组id */
  1920. groupCode = 0;
  1921. //加速剩余次数
  1922. speedUpLeftTimes = 0;
  1923. /** 农场任务完成次数 */
  1924. completeFarmTaskTimes = 0;
  1925. /** 订单数据 */
  1926. orderData = null;
  1927. /** 临时订单数据, 只用于种植优先选择作用 */
  1928. copyOrderData = null;
  1929. //插队看视频次数限制
  1930. lineRedMoney = 0;
  1931. //当前生产次数
  1932. curProductionAdTimes = 0;
  1933. }
  1934. /**
  1935. * 奖励状态
  1936. */
  1937. export enum RewardState {
  1938. /** 已领取 */
  1939. none = 1,
  1940. /** 未解锁 */
  1941. lock = 2,
  1942. /** 可领取 */
  1943. unlock = 3
  1944. }
  1945. /**
  1946. * 奖励类型
  1947. */
  1948. export enum RewardType {
  1949. /** 红包币 */
  1950. redBag = 1,
  1951. /** 毛币 */
  1952. rmb = 2,
  1953. /** 金猪币 */
  1954. pigRmb = 3,
  1955. /** 生产次数 */
  1956. productTimes = 4,
  1957. }
  1958. /**
  1959. * 音频路径
  1960. */
  1961. export enum AUDIO_TYPE {
  1962. /**主界面背景音乐*/
  1963. bgm = 'bgm',
  1964. /**打开存钱罐界面播放一次*/
  1965. pigBank = 'pigBank',
  1966. /**关卡玩法背景音乐*/
  1967. missionBg = 'missionBg',
  1968. /**红包币领取界面关闭音效*/
  1969. rewardClose = 'rewardClose',
  1970. /**红包币领取界面开启音效*/
  1971. rewardOpen = 'rewardOpen',
  1972. /**红包界面打开音效*/
  1973. reward = 'reward',
  1974. /**提现到账界面打开播放一次*/
  1975. receiptNotice = 'receiptNotice',
  1976. /**通用按钮点击音效 */
  1977. button = 'button',
  1978. /**转盘转动音效*/
  1979. turnableplay = 'turnableplay',
  1980. /**转盘转动音效*/
  1981. turnplateDrawEnd = 'turnplateDrawEnd',
  1982. /**主页背景音乐 */
  1983. music_startBg = "music_startBg",
  1984. /**游戏背景音乐 */
  1985. music_gameBg = "music_gameBg",
  1986. /**按钮点击 */
  1987. ef_button_click = "ef_button_click",
  1988. /**红包打开 */
  1989. ef_redPacket_open = "ef_redPacket_open",
  1990. /**红包来了音效 */
  1991. ef_redPacket_come = "ef_redPacket_come",
  1992. /**消除4个 */
  1993. ef_bonus4 = "ef_bonus4",
  1994. /**消除5个 */
  1995. ef_bonus5 = "ef_bonus5",
  1996. /**消除6个 */
  1997. ef_bonus6 = "ef_bonus6",
  1998. /**消除7个 */
  1999. ef_bonus7 = "ef_bonus7",
  2000. /**消除8个 */
  2001. ef_bonus8 = "ef_bonus8",
  2002. /**普通消除音效 */
  2003. ef_eliminate = "ef_eliminate",
  2004. /**bouns消除音效 */
  2005. ef_eliminate_bonus = "ef_eliminate_bonus",
  2006. /**胜利音效 */
  2007. ef_win = "ef_win",
  2008. /**锤子 */
  2009. ef_change = "ef_change",
  2010. /**刷新 */
  2011. ef_refresh = "ef_refresh",
  2012. /**飞翔 */
  2013. ef_fly = "ef_fly",
  2014. /**关闭按钮音效*/
  2015. closeButton = "closeButton",
  2016. //红包界面打开
  2017. congratulations = 'congratulations',
  2018. //红包飞音效
  2019. redmoney = 'redmoney',
  2020. /**存入银行成功*/
  2021. saveSuccess = 'saveSuccess',
  2022. }
  2023. /** ECPM */
  2024. type ADShowCfg = {
  2025. average_ecpm: number,
  2026. insert_probability: number,
  2027. is_show_banner: number,
  2028. is_show_inter: number,
  2029. }
  2030. /**事件类型 */
  2031. export enum EVENT_TYPE {
  2032. BACK_WxAuth = "BACK_WxAuth",
  2033. UPDATE_CashNum = "UPDATE_CashNum",
  2034. }
  2035. /** 数据事件Id */
  2036. export enum DataEventId {
  2037. /** 点击 */
  2038. guide = "guide",
  2039. /** 点击跳过 */
  2040. guideSkip = "guideSkip",
  2041. /** 按钮点击 */
  2042. button_click = "button_click",
  2043. /** 看视频 */
  2044. video_init = "video_init",
  2045. /** 看视频完成 */
  2046. video_end = "video_end",
  2047. /** 成功拉取全屏视频 */
  2048. interstitial2_init = "interstitial2_init",
  2049. /** 广告点击 */
  2050. Ad_click = "Ad_click",
  2051. /** 全屏视频完成 */
  2052. interstitial2_end = "interstitial2_end",
  2053. /** 福袋功能 */
  2054. fudaiFunction = "fudaiFunction",
  2055. /** 互推功能 */
  2056. hutuiFunction = "hutuiFunction",
  2057. /** 激励视频ecpm */
  2058. ad_videoEcpm = 'ad_video',
  2059. /** 开屏ecpm */
  2060. ad_openEcpm = 'ad_open',
  2061. /** 提现 */
  2062. Sundry = 'Sundry',
  2063. /** 加载 */
  2064. loading = 'loading',
  2065. /** 排队 */
  2066. queue = 'queue',
  2067. /** 实名认证 */
  2068. realName = 'realName',
  2069. /** 离线生产次数弹出 */
  2070. offlineProductTimes = "offlineProductTimes",
  2071. /**触发提现到达上限 */
  2072. cashLimit = "cashLimit",
  2073. /**互推红包弹出位置 */
  2074. htRedBag_scene = "htRedBag_scene",
  2075. /**互推红包领取次数*/
  2076. htRedBag_eject = "htRedBag_eject",
  2077. /**插屏广告弹出*/
  2078. interstita11_eject = "interstita11_eject"
  2079. }
  2080. /** 视频广告类型 */
  2081. export enum VideoAdType {
  2082. video_init_1 = '农场加等级经验',
  2083. video_init_2 = '提现-加进度',
  2084. video_init_3 = '提现-加现金',
  2085. video_init_4 = '签到',
  2086. video_init_5 = '抽奖',
  2087. video_init_6 = '图鉴领奖',
  2088. video_init_7 = '消灭害虫',
  2089. video_init_8 = '恢复健康',
  2090. video_init_9 = '恢复供电',
  2091. video_init_10 = '山羊红包',
  2092. video_init_11 = '拓建',
  2093. video_init_12 = '收获',
  2094. video_init_13 = '飘浮红包',
  2095. video_init_14 = '全体加速',
  2096. video_init_15 = '福利加进度',
  2097. video_init_16 = '生产加次数',
  2098. video_init_17 = '点击生产按钮',
  2099. video_init_18 = '离开游戏领红包',
  2100. video_init_19 = '定时弹出红包',
  2101. video_init_20 = '插队',
  2102. video_init_21 = '恢复生产次数',
  2103. //video_init_22 = '长时间未操作弹出视频',
  2104. }
  2105. export enum InterFullAdType {
  2106. interstitial2_init_1 = '点击红包的关闭按钮',
  2107. interstitial2_init_2 = '普通收获',
  2108. interstitial2_init_3 = '点击鸟和狗',
  2109. interstitial2_init_4 = '长时间未操作弹出',
  2110. // interstitial2_init_4 = '关闭个人资料页',
  2111. // interstitial2_init_5 = '关闭农场等级奖励界面',
  2112. // interstitial2_init_6 = '关闭红包币提现界面',
  2113. // interstitial2_init_7 = '关闭抽奖界面',
  2114. // interstitial2_init_8 = '关闭任务红包界面',
  2115. // interstitial2_init_9 = '关闭更多游戏界面',
  2116. // interstitial2_init_10 = '关闭图鉴界面',
  2117. // interstitial2_init_11 = '关闭生虫、生病、停电弹窗',
  2118. // interstitial2_init_12 = '关闭全体加速界面',
  2119. // interstitial2_init_13 = '关闭收获弹窗',
  2120. // interstitial2_init_14 = '关闭富翁银行',
  2121. // interstitial2_init_15 = '关闭福利界面',
  2122. // interstitial2_init_16 = '一键生产-关闭领取生产次数弹窗',
  2123. // interstitial2_init_17 = '红包币提现界面,点击提现按钮',
  2124. // interstitial2_init_18 = '福利-点击提现按钮',
  2125. // interstitial2_init_19 = '订单-点击订单提现按钮',
  2126. // interstitial2_init_20 = '任务红包-点击领取按钮',
  2127. // interstitial2_init_21 = '富翁银行-点击开始任务按钮',
  2128. // interstitial2_init_22 = '富翁银行-点击提现按钮',
  2129. }
  2130. export enum InterAdType {
  2131. interstitial1_click_1 = '恭喜发财红包弹出后',
  2132. interstitial1_click_2 = '恭喜获得弹窗弹出后',
  2133. interstitial1_click_3 = '生虫/生病/停电弹出后',
  2134. interstitial1_click_4 = '关闭抽奖界面后',
  2135. interstitial1_click_5 = '关闭任务红包后',
  2136. interstitial1_click_6 = '关闭富翁银行后',
  2137. interstitial1_click_7 = '打开领取生产次数界面',
  2138. interstitial1_click_8 = '农作物点击可收获',
  2139. interstitial1_click_9 = '关闭全体加速后',
  2140. interstitial1_click_10 = '关闭福利后',
  2141. interstitial1_click_11 = '打开个人资料页',
  2142. interstitial1_click_12 = '打开更多游戏页',
  2143. interstitial1_click_13 = '全体加速激励视频播完后',
  2144. interstitial1_click_14 = '离线奖励激励视频播完后',
  2145. interstitial1_click_15 = '抽奖激励视频播完后',
  2146. interstitial1_click_16 = '图鉴领奖激励视频播完后',
  2147. interstitial1_click_17 = '拓建激励视频播完后',
  2148. interstitial1_click_18 = '收获超级加倍激励视频播完后',
  2149. //interstitial1_click_19 = '定时弹出插屏',
  2150. }
  2151. export enum BannerAdType {
  2152. banner_click_1 = '恭喜获得弹窗弹出后',
  2153. banner_click_2 = '任务红包',
  2154. banner_click_3 = '恭喜发财红包',
  2155. banner_click_4 = '图鉴',
  2156. banner_click_5 = '全体加速',
  2157. banner_click_6 = '收获弹窗',
  2158. banner_click_7 = '拓建弹窗',
  2159. banner_click_8 = '三个恢复弹窗',
  2160. banner_click_9 = '抽奖'
  2161. }
  2162. export enum ExpAddType {
  2163. EAT_video = 1,
  2164. EAT_harvest = 2,
  2165. EAT_others = 3,
  2166. }
  2167. export enum FarmState {
  2168. Lock,
  2169. CanUnlock,
  2170. Empty,
  2171. Growing,
  2172. Ripe,
  2173. Sick
  2174. }
  2175. export enum PastureState {
  2176. Lock,
  2177. Empty,
  2178. Growing,
  2179. Ripe,
  2180. Sick
  2181. }
  2182. export enum ProductType {
  2183. nzw = '农作物',
  2184. dw = '动物',
  2185. bmhc = '爆米花厂',
  2186. gdp = '糕点铺',
  2187. ztc = '制糖厂',
  2188. lrc = '炼乳厂',
  2189. gfmg = '功夫面馆',
  2190. kcd = '快餐店'
  2191. }
  2192. /** 动物状态 */
  2193. export enum AnimalState {
  2194. Hanger,
  2195. Eat,
  2196. Wait
  2197. }
  2198. export enum FactroyState {
  2199. Lock,
  2200. Empty,
  2201. Producting,
  2202. Ripe,
  2203. Sick
  2204. }
  2205. //功能开关含义
  2206. export enum FunctionSwitch {
  2207. FS_farmGrade = 0, //农场等级奖励
  2208. FS_cashOutBtn = 1, //主界面提现按钮
  2209. FS_sign = 2, //签到
  2210. FS_turntable = 3, //抽奖转盘
  2211. FS_redPacketTash = 4, //任务红包
  2212. FS_welfareBtn = 5, //福利按钮
  2213. FS_inviteBtn = 6, //邀请按钮
  2214. FS_floatRedPacket = 7, //漂浮红包
  2215. FS_electBtn = 8, //互推按钮
  2216. FS_sheepRedPacket = 9, //山羊红包
  2217. FS_addCashBtn = 10, //提现界面的加现金按钮
  2218. FS_order = 11, //订单
  2219. FS_floatFarmMap = 12, //图鉴浮窗
  2220. FS_richManBank = 13 //富翁银行
  2221. }