GameData.ts 86 KB

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