GameData.ts 81 KB

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