GameData.ts 84 KB

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