GameData.ts 80 KB

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