GameData.ts 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626
  1. import Util from "../../before/util/Util";
  2. import FunBtns from "../game/FunBtns";
  3. import Game from "../game/Game";
  4. /**
  5. * @description 游戏核心玩法数据
  6. * @author 邹勇
  7. */
  8. export class GameData {
  9. public dataFinish: boolean = false;
  10. public savePropFinish: boolean = false;
  11. public savePropsFinish: boolean = false;
  12. public getPropsFnish: boolean = false;
  13. //是否触摸屏幕
  14. public isTouchScreen: boolean = false;
  15. public configs: any = {};
  16. public adShowConfig: ADShowCfg;
  17. /** 功能开启 */
  18. public funOpenData: string[] = [];
  19. public playerProp: PlayerProp = null;
  20. /** 标志位:刷新主界面货币 */
  21. public init_coin: boolean = false;
  22. public addHb: number = 0;
  23. public updatePiggyBankValue: boolean = false;
  24. /** 标志位:刷新主界面头像 */
  25. public init_head: boolean = false;
  26. public init_add: boolean = false;
  27. /** 标志位:刷新主界面红点 */
  28. public init_red_point: boolean = true;
  29. //标志位,刷新提现界面的红包币
  30. public init_wallet_redMoney = false;
  31. /** 属性存储字典 */
  32. public props: Map<number, any> = new Map<number, any>();
  33. public pools = [
  34. { url: "game/prefab/tips", num: 20 },
  35. { url: "game/prefab/coin", num: 20 }
  36. ];
  37. /** 主页样式脚本 */
  38. public gameStyle: Game = null;
  39. /** 入口按钮 */
  40. public funBtns: FunBtns = null;
  41. /** 剩余可种植次数 */
  42. public leftTimes: number = -1;
  43. /** 最大可种植次数 */
  44. public maxTimes: number = -1;
  45. /** 恢复种植次数间隔 */
  46. public ProductionRecovery: number = 15;
  47. public init_leftTimes: boolean = false;
  48. /** 可生产商品配置 */
  49. public nextCanProduct = null;
  50. /** 按钮生产选中的农田、牧场或工厂 */
  51. public nextMake = null;
  52. /** 类型标识 */
  53. private nextType = 0;
  54. /** 刷新生产按钮信息 */
  55. public init_makeInfo = false;
  56. /** 正在生产 */
  57. public isProducting = false;
  58. /** 标志位 刷新任务描述 */
  59. public init_task = false;
  60. public init_expLevel = false;
  61. //标志位任务跟新
  62. public init_redBagTask = false;
  63. //标志位 生产奖励的任务ui刷新
  64. public init_productTask = false;
  65. public init_speedup = false;
  66. 标志位
  67. public init_hideRedBag = false;
  68. public shareUrl = '';
  69. public shareTitle = '';
  70. public shareDes = '';
  71. public shareImgUrl = '';
  72. /** 生虫/生病/停电最多个数 */
  73. public RawInsectArr = [];
  74. /** 生虫/生病/停电当前个数 */
  75. public RawInsectCurArr = [0, 0, 0];
  76. //恢复生产次数
  77. public restoreProductTimes = 0;
  78. /** 最大可种植产品可更新到服务器标识 */
  79. public maxProductToServer = false;
  80. /**
  81. * 初始化游戏数据:网络配置信息,用户信息
  82. * @returns
  83. */
  84. public async init() {
  85. let data: any = { "versionCode": gData.appData.version };
  86. let response = await mk.http.sendData('getAllConfigInfo', data);
  87. if (response.errcode != 0) {
  88. if (response.errcode == -10003 || response.errcode == -20003) {
  89. //清除缓存
  90. gData.loginData.reload();
  91. }
  92. return;
  93. }
  94. mk.console.logSingle("getAllConfigInfo", response.data);
  95. this.initConfigs(response.data);
  96. //初始化topon
  97. mk.ad.init();
  98. data = {};
  99. response = await mk.http.sendData('getInfoCrypt', data);
  100. if (response.errcode != 0) {
  101. return;
  102. }
  103. mk.console.logSingle("getInfoCrypt", response.data);
  104. this.initPlayerProp(response.data)
  105. this.initProps(response.data.gameUserData);
  106. data = {};
  107. response = await mk.http.sendData('user/adShowConfig', data);
  108. if (response.errcode != 0) {
  109. return;
  110. }
  111. this.adShowConfig = response.data;
  112. mk.console.logSingle("user/adShowConfig", response.data);
  113. gData.adData.initEcpmData();
  114. // data = {};
  115. // response = await mk.http.sendData('noviceWeFare/getNoviceWeFareInfo', data);
  116. // if (response.errcode != 0) {
  117. // return;
  118. // }
  119. // this.playerProp.userTuCaoInfo = response.data.userWelFareTaskInfo;
  120. // mk.console.logSingle("welFare/getUserWelFareTaskInfo", response.data);
  121. gData.guideData.init();
  122. gData.guideWeakData.init();
  123. gData.moduleData.forEach(element => {
  124. element.init();
  125. });
  126. this.dataFinish = true;
  127. }
  128. private initConfigs(data) {
  129. // console.log('config ', data);
  130. this.configs = data;
  131. this.funOpenData = this.configs.ServerConfig.Functionswitch.split(",");
  132. //从服务器解析配置
  133. this.setProductMapFromJson();
  134. gData.loginData.popIdentifySwitch = this.configs.ServerConfig.popIdentifySwitch == '1';
  135. gData.gameData.shareUrl = this.configs.ServerConfig.shareUrl;
  136. gData.gameData.shareTitle = this.configs.ServerConfig.shareTitle;
  137. gData.gameData.shareDes = this.configs.ServerConfig.shareDes;
  138. gData.gameData.shareImgUrl = this.configs.ServerConfig.shareImgUrl;
  139. gData.gameData.RawInsectArr = this.configs.ServerConfig.RawInsect.split(',');
  140. }
  141. /**
  142. * 初始化玩家数据
  143. */
  144. private initPlayerProp(res_data) {
  145. this.playerProp = new PlayerProp();
  146. this.playerProp.cashIndex = res_data.cashIndex;
  147. this.playerProp.gameUserData = res_data.gameUserData;
  148. this.playerProp.isSignInToday = res_data.isSignInToday;
  149. this.playerProp.isWithdrawable = res_data.isWithdrawable;
  150. this.playerProp.lastTime = res_data.lastTime;
  151. this.playerProp.loginDays = res_data.loginDays;
  152. this.playerProp.newPlayer = res_data.newPlayer;
  153. this.playerProp.initPiggyBank(res_data.piggyBank);
  154. this.playerProp.piggyBankCashTimes = res_data.piggyBankCashTimes;
  155. this.playerProp.redMoney = res_data.redMoney == null ? 0 : res_data.redMoney;
  156. this.playerProp.signInDay = res_data.signInDay;
  157. this.playerProp.totalPiggyBankCashTimes = res_data.totalPiggyBankCashTimes;
  158. this.playerProp.turntableTimes = res_data.turntableTimes;
  159. this.playerProp.versioncfg = res_data.versioncfg;
  160. this.playerProp.isFirstRedMoney = res_data.isFirstRedMoney;
  161. gData.adData.watchNumToday = res_data.dayVideoTimesForRedMoney == null ? 0 : res_data.dayVideoTimesForRedMoney;
  162. this.playerProp.gradeLevel = res_data.farmLevel
  163. this.playerProp.userTuCaoInfo = res_data.userWelFareTaskInfo;
  164. this.playerProp.farmExpValue = res_data.userExp;
  165. this.playerProp.farmGradeData = res_data.userFarmGrageRewardInfo;
  166. this.playerProp.userNoviceWeFareInfo = res_data.userNoviceWeFareInfo;
  167. this.playerProp.redMoneyCashPayRecordList = res_data.redMoneyCashPayRecordList;
  168. mk.console.logSingle('userNoviceWeFareInfo==>', res_data.userNoviceWeFareInfo);
  169. //mk.console.logSingle('redMoneyCashPayRecordList==>', res_data.redMoneyCashPayRecordList);
  170. this.playerProp.userFarmTaskInfo = res_data.userFarmTaskInfo;
  171. this.playerProp.speedUpLeftTimes = res_data.speedUpLeftTimes;
  172. this.playerProp.completeFarmTaskTimes = res_data.completeFarmTaskTimes;
  173. this.playerProp.orderData = res_data.userOrderTaskInfo;
  174. mk.data.setTAUserID(gData.loginData.uin);
  175. mk.data.setTAEventUser(0, 'logindays_total', this.playerProp.loginDays);
  176. if (this.playerProp.completeFarmTaskTimes == 0) {
  177. mk.data.setTAEventUser(0, 'Cumulative_task', gData.gameData.playerProp.completeFarmTaskTimes);
  178. }
  179. if (gData.loginData.isFirstIn) {
  180. gData.loginData.isFirstIn = false;
  181. mk.data.setTAEventRegister();
  182. mk.data.sendDataEvent('ABTest', `触发${this.playerProp.groupCode}方案`);
  183. //注册时版本号
  184. mk.data.setTAEventUserStr(0, 'regtime_app_id', gData.appData.appVersion);
  185. //星云uid
  186. mk.data.setTAEventUserStr(0, 'xy_uid', gData.loginData.uin);
  187. mk.data.setTAEventUser(0, 'farm_lv', gData.gameData.playerProp.gradeLevel);
  188. }
  189. //当前版本号
  190. mk.data.setTAEventUserStr(0, 'now_app_id', gData.appData.appVersion);
  191. //渠道号
  192. mk.data.setTAEventUserStr(0, 'channel_id', gData.appData.umengChannel);
  193. // //test
  194. // this.playerProp.completeFarmTaskTimes = 3;
  195. }
  196. /**
  197. * 保存单个数据
  198. */
  199. public async setProp(key: GameProp, value: any) {
  200. let data = {
  201. key: key + '',
  202. value: value
  203. };
  204. this.props.set(key, value);
  205. await mk.http.sendData('savePlayerProp', data);
  206. this.savePropFinish = true;
  207. }
  208. /**
  209. * 保存多个数据
  210. */
  211. public async setProps(arr: { key: GameProp, value: any }[]) {
  212. let needProp = {};
  213. for (let i = 0; i < arr.length; i++) {
  214. needProp[arr[i].key + ''] = arr[i].value;
  215. }
  216. let data = {
  217. needProp: needProp
  218. };
  219. for (let i = 0; i < arr.length; i++) {
  220. this.props.set(arr[i].key, arr[i].value);
  221. }
  222. await mk.http.sendData('saveAllPlayerProp', data);
  223. this.savePropsFinish = true;
  224. }
  225. /** 获取属性 */
  226. public getProp(key: GameProp): any {
  227. if (this.props == null) {
  228. return 0;
  229. }
  230. let value = this.props.get(key);
  231. return value;
  232. }
  233. /**
  234. * 向服务器请求所有属性后更新
  235. */
  236. public async getAllProps() {
  237. let response = await mk.http.sendData('getAllPlayerProp', {});
  238. if (response.errcode != 0) {
  239. return;
  240. }
  241. this.initProps(response.data);
  242. this.getPropsFnish = true;
  243. }
  244. private initProps(data) {
  245. if (data == null) {
  246. return;
  247. }
  248. for (let key in data) {
  249. this.props.set(parseInt(key), data[key]);
  250. }
  251. this.setFramDataMapByServer();
  252. this.setPastureDataMapByServer();
  253. this.setFactoryDataMapByServer();
  254. this.initProductTimes();
  255. this.initLeftTimes();
  256. this.initFarmMapGetRewardData();
  257. this.initCashOutTimes();
  258. // let isNewTask = this.getProp(GameProp.redBagTaskRefresh);
  259. // if (isNewTask != undefined) {
  260. // this.init_redBagTask = isNewTask;
  261. // }
  262. }
  263. private initLeftTimes() {
  264. let lefttimes = this.getProp(GameProp.leftTimes);
  265. if (lefttimes == undefined) {
  266. this.leftTimes = parseInt(this.configs.ServerConfig.FreeProduction);
  267. this.setProp(GameProp.leftTimes, this.leftTimes);
  268. }
  269. else {
  270. this.leftTimes = lefttimes;
  271. }
  272. this.maxTimes = parseInt(this.configs.ServerConfig.ProductionMax);
  273. this.ProductionRecovery = parseInt(this.configs.ServerConfig.ProductionRecovery);
  274. // //test
  275. // this.leftTimes = 1;
  276. // this.maxTimes = 20;
  277. // this.ProductionRecovery = 1;
  278. }
  279. /** 增加减少生产次数
  280. * @param add 增减变量
  281. */
  282. public changeLeftTimes(add, isIgnoreMaxTimes = false) {
  283. gData.gameData.leftTimes += add;
  284. if (add > 0 && !isIgnoreMaxTimes) {
  285. gData.gameData.leftTimes = (gData.gameData.leftTimes > gData.gameData.maxTimes ? gData.gameData.maxTimes : gData.gameData.leftTimes);
  286. }
  287. if (gData.gameData.leftTimes < 0) {
  288. gData.gameData.leftTimes = 0;
  289. }
  290. gData.gameData.setProp(GameProp.leftTimes, gData.gameData.leftTimes);
  291. gData.gameData.init_leftTimes = true;
  292. }
  293. //图鉴领取数据
  294. private _farmMapRewardData = [];
  295. public getFarmMapRewardState(index) {
  296. if (index.i < this._farmMapRewardData.length) {
  297. if (index.j < this._farmMapRewardData[index.i].length) {
  298. return this._farmMapRewardData[index.i][index.j];
  299. }
  300. }
  301. return 1;
  302. }
  303. public setFarmMapRewardState(index, state) {
  304. if (index.i < this._farmMapRewardData.length) {
  305. if (index.j < this._farmMapRewardData[index.i].length) {
  306. this._farmMapRewardData[index.i][index.j] = state;
  307. this.setProp(GameProp.farmMapGetRewardData, this._farmMapRewardData);
  308. }
  309. }
  310. }
  311. private initFarmMapGetRewardData() {
  312. this._farmMapRewardData = this.getProp(GameProp.farmMapGetRewardData);
  313. if (!this._farmMapRewardData) {
  314. this._farmMapRewardData = [];
  315. }
  316. let needSync = false;
  317. let index = 0;
  318. this._productTypeMap.forEach((value, key) => {
  319. if (this._farmMapRewardData.length <= index) {
  320. let len = value.length;
  321. let arr = [];
  322. for (let i = 0; i != len; ++i) {
  323. arr.push(0);
  324. }
  325. this._farmMapRewardData.push(arr);
  326. needSync = true;
  327. console.log("-----add 数组数据")
  328. } else {
  329. let data = this._farmMapRewardData[index];
  330. let len = value.length;
  331. for (let i = 0; i != len; ++i) {
  332. if (i >= data.length) {
  333. data.push(0);
  334. needSync = true;
  335. console.log("-----add 单个数据")
  336. }
  337. }
  338. }
  339. ++index;
  340. });
  341. if (needSync) {
  342. this.setProp(GameProp.farmMapGetRewardData, this._farmMapRewardData);
  343. }
  344. }
  345. //提现次数
  346. public _cashOutTimes = 0;
  347. public initCashOutTimes() {
  348. let v = this.getProp(GameProp.cashOutTimes);
  349. if (v) {
  350. this._cashOutTimes = v;
  351. } else {
  352. this._cashOutTimes = 0;
  353. }
  354. console.log(`initCashOutTimes====>${this._cashOutTimes}`);
  355. }
  356. public addCashOutTimes() {
  357. this._cashOutTimes += 1;
  358. this.setProp(GameProp.cashOutTimes, this._cashOutTimes);
  359. console.log(`addCashOutTimes====>${this._cashOutTimes}`);
  360. }
  361. /** 是否是新用户 */
  362. public isNewPlayer(): boolean {
  363. let v = this.getProp(GameProp.newPlayer);
  364. return v == 0;
  365. }
  366. //*********** ================= 农场数据 ================== */
  367. /** 农田数据 服务器数据 */
  368. private _farmData = [];
  369. /** 农田字典 本地数据,方便操作*/
  370. private _farmDataMap: Map<number, any> = new Map();
  371. //刷新农田
  372. public needFreshArr = [];
  373. /** 随机获取可种植物品 */
  374. getRandomPlantConfig() {
  375. let id = Util.rnd(10001, this.getMaxProduct(ProductType.nzw));
  376. return this.getProductMap(id);
  377. }
  378. /** 随机获取可生产产品 */
  379. getRandomFactoryConfig(configID) {
  380. let tab = gData.gameData.getTabByConfigID(configID);
  381. let arr = this.getProductArrByType(tab);
  382. let max = this.getMaxProduct(tab);
  383. let canArr = [];
  384. let len = arr.length;
  385. for (var i = 0; i < len; i++) {
  386. if (arr[i].picture <= max) {
  387. canArr.push(arr[i].picture);
  388. if (arr[i].picture == max) {
  389. break;
  390. }
  391. }
  392. }
  393. let index = Util.rnd(0, canArr.length - 1);
  394. let id = canArr[index];
  395. return this.getProductMap(id);
  396. }
  397. /** 自动生产选中下一个 */
  398. setNextProduct(sel = true) {
  399. if (this.nextMake) {
  400. return;
  401. }
  402. let next = gData.farmSystem.selectNextFarm(sel);
  403. if (!next) {
  404. let next1 = gData.pastureSystem.nextPasture();
  405. if (!next1) {
  406. let next2 = gData.factorySystem.nextFactory();
  407. if (!next2) {
  408. this.nextType = 0;
  409. }
  410. else {
  411. this.nextType = 3;
  412. }
  413. }
  414. else {
  415. this.nextType = 2;
  416. }
  417. }
  418. else {
  419. this.nextType = 1;
  420. }
  421. this.init_makeInfo = true;
  422. }
  423. hasFirstCheck = false;
  424. firstCheckNext() {
  425. if (!this.hasFirstCheck && gData.farmSystem.farms.length >= 18
  426. && gData.pastureSystem.pastureIcons.length >= 3 && gData.factorySystem.factoryIcons.length >= 6) {
  427. this.hasFirstCheck = true;
  428. Util.objSortByKey(gData.farmSystem.farms, 'sortID');
  429. Util.objSortByKey(gData.pastureSystem.pastureIcons, 'sortID');
  430. Util.objSortByKey(gData.factorySystem.factoryIcons, 'sortID');
  431. gData.gameData.setNextProduct(false);
  432. }
  433. }
  434. async makeProduct() {
  435. let flyRed = true;
  436. switch (this.nextType) {
  437. case 0:
  438. //mk.tip.pop('农场已满,无法继续生产');
  439. //弹出收获、生虫、加速
  440. if (!this.checkCanHarvest()) {
  441. if (!this.checkCanClearSick()) {
  442. this.checkCanSpeedUp(true);
  443. }
  444. }
  445. flyRed = false;
  446. break;
  447. case 1:
  448. flyRed = await gData.farmSystem.btnMake();
  449. gData.adData.checkPopRed();
  450. break;
  451. case 2:
  452. flyRed = await gData.pastureSystem.btnMake();
  453. gData.adData.checkPopRed();
  454. break;
  455. case 3:
  456. flyRed = await gData.factorySystem.btnMake();
  457. gData.adData.checkPopRed();
  458. break;
  459. }
  460. return flyRed;
  461. }
  462. public async updateNewTaskProgress(isNeedRefresh = false) {
  463. // if (gData.gameData.init_redBagTask) {
  464. // return;
  465. // }
  466. if (this.playerProp.userFarmTaskInfo) {
  467. let com = this.playerProp.userFarmTaskInfo.completeCount;
  468. let count = this.playerProp.userFarmTaskInfo.taskCount;
  469. if (com >= count) {
  470. mk.tip.pop('任务红包进度已满,快去提现');
  471. return false;
  472. }
  473. }
  474. let data = {};
  475. let response = await mk.http.sendData('farmTask/updateUserFarmTaskInfo', data);
  476. mk.console.logSingle('refrehTask=>', response);
  477. if (response.errcode != 0) {
  478. return false;
  479. }
  480. gData.gameData.init_task = true;
  481. this.playerProp.userFarmTaskInfo = response.data.userFarmTaskInfo;
  482. if (this.playerProp.userFarmTaskInfo.completeCount >= this.playerProp.userFarmTaskInfo.taskCount) {
  483. mk.ui.closeAllUI();
  484. mk.guide.open(4);
  485. }
  486. // if (isNeedRefresh) {
  487. // gData.gameData.init_task = true;
  488. // }
  489. return true;
  490. }
  491. public setFarmDataMap(id, data, sendToServer = true) {
  492. this._farmDataMap.set(id, data);
  493. let len = this._farmData.length;
  494. for (var i = 0; i < len; i++) {
  495. if (this._farmData[i].id == id) {
  496. this._farmData[i].state = data.state;
  497. this._farmData[i].productID = data.productID;
  498. this._farmData[i].growSpan = data.growSpan;
  499. break;
  500. }
  501. }
  502. this.needFreshArr.push(id);
  503. //更新到服务器
  504. if (sendToServer) {
  505. this.freshSendToServer(1);
  506. }
  507. }
  508. public getFarmDataMap(id) {
  509. return this._farmDataMap.get(id);
  510. }
  511. /** 服务器数据设置到本地 */
  512. public setFramDataMapByServer() {
  513. this._farmData = this.getProp(GameProp.farmData);
  514. if (!this._farmData) {
  515. this._farmData = [];
  516. }
  517. let len = this._farmData.length;
  518. //新玩家初始化农田数据
  519. if (len < 18) {
  520. let id = 31000;
  521. let data = null;
  522. let unluckNum = parseInt(gData.gameData.configs.ServerConfig.unluckNum);
  523. for (var i = 0; i < 18; i++) {
  524. if (i < unluckNum) {
  525. data = { id: id, state: FarmState.Empty, productID: 0, growSpan: 0 };
  526. }
  527. else if (i == unluckNum) {
  528. data = { id: id, state: FarmState.CanUnlock, productID: 0, growSpan: 0 };
  529. }
  530. else {
  531. data = { id: id, state: FarmState.Lock, productID: 0, growSpan: 0 };
  532. }
  533. this._farmData.push(data);
  534. this._farmDataMap.set(id, data);
  535. id++;
  536. }
  537. //第一次初始数据
  538. // this.setMaxProduct(10003);
  539. //更新到服务器
  540. this.setProp(GameProp.farmData, this._farmData);
  541. }
  542. else {
  543. let sickTimes = 0;
  544. for (var i = 0; i < len; i++) {
  545. this._farmDataMap.set(this._farmData[i].id, this._farmData[i]);
  546. if (this._farmData[i].state == FarmState.Sick) {
  547. sickTimes++;
  548. }
  549. }
  550. this.RawInsectCurArr[0] = sickTimes;
  551. }
  552. this.setMaxProduct(10003, true);
  553. }
  554. /** puduct配置数据 <picture, config> */
  555. private _productMap: Map<number, any> = new Map();
  556. /** puduct类型配置数据 <tab, 类型数组> */
  557. private _productTypeMap: Map<string, any> = new Map();
  558. /** 设置puduct配置数据 */
  559. public setProductMapFromJson() {
  560. let productJson = this.configs.Product;
  561. // // 先用本地数据
  562. // let productJson = gData.configData.configMap.get('product');
  563. let len = productJson.length;
  564. let product = null;
  565. let tab = '';
  566. let arr = [];
  567. for (var i = 0; i < len; i++) {
  568. product = productJson[i];
  569. this._productMap.set(product.picture, product);
  570. if (tab != product.tab) {
  571. arr = [];
  572. this._productTypeMap.set(product.tab, arr);
  573. tab = product.tab;
  574. }
  575. arr.push(product);
  576. }
  577. }
  578. /** 根据id获取单个数据 */
  579. public getProductMap(id) {
  580. return this._productMap.get(id);
  581. }
  582. /** 根据tab获取数组 */
  583. public getProductArrByType(type: ProductType) {
  584. return this._productTypeMap.get(type);
  585. }
  586. /** 产品生产/种植次数 服务器数据 */
  587. private _productMakeTimesData = [];
  588. /** 产品生产/种植次数 */
  589. private _productMakeTimesMap: Map<number, number> = new Map();
  590. private initProductTimes() {
  591. this._productMakeTimesData = this.getProp(GameProp.productMakeTimes);
  592. if (!this._productMakeTimesData) {
  593. this._productMakeTimesData = [];
  594. }
  595. let len = this._productMakeTimesData.length;
  596. for (var i = 0; i < len; i++) {
  597. this._productMakeTimesMap.set(this._productMakeTimesData[i].id, this._productMakeTimesData[i].times);
  598. this.setMaxProduct(this._productMakeTimesData[i].id);
  599. }
  600. }
  601. addProductMakeTimesById(id: number) {
  602. let isAddMaxProduct = false;
  603. let times = this._productMakeTimesMap.get(id);
  604. if (!times) {
  605. times = 0;
  606. }
  607. times++;
  608. this._productMakeTimesMap.set(id, times);
  609. //更新到服务器
  610. let has = false;
  611. let len = this._productMakeTimesData.length;
  612. for (var i = 0; i < len; i++) {
  613. if (this._productMakeTimesData[i].id == id) {
  614. this._productMakeTimesData[i].times = times;
  615. has = true;
  616. break;
  617. }
  618. }
  619. if (!has) {
  620. let data = { 'id': id, 'times': times };
  621. this._productMakeTimesData.push(data);
  622. }
  623. //设置可种植/生产最大id
  624. let nextID = id + 1;
  625. let curConfig = this.getProductMap(id);
  626. let nextConfig = this.getProductMap(nextID);
  627. if (id == this.getMaxProduct(curConfig.tab)) {
  628. if (nextConfig) {
  629. gData.plantData.init_itemIndex = nextID;
  630. }
  631. }
  632. if (nextConfig) {
  633. if (nextConfig.tab == curConfig.tab && nextID > this.getMaxProduct(curConfig.tab)) {
  634. if (nextConfig.unlock == 1 && nextConfig.value <= times) {
  635. isAddMaxProduct = true;
  636. this._productMakeTimesMap.set(nextID, 0);
  637. let data = { 'id': nextID, 'times': 0 };
  638. this._productMakeTimesData.push(data);
  639. this.setMaxProduct(nextID);
  640. let nConfig = this.getProductMap(nextID + 1);
  641. if (nConfig) {
  642. gData.plantData.init_lock = nextID + 1;
  643. }
  644. }
  645. }
  646. }
  647. if(!isAddMaxProduct)
  648. {
  649. mk.event.emit("refreshFarmMapUI");
  650. }
  651. this.setProp(GameProp.productMakeTimes, this._productMakeTimesData);
  652. }
  653. getProductMakeTimesById(id: number) {
  654. let times = this._productMakeTimesMap.get(id);
  655. if (!times) {
  656. times = 0
  657. }
  658. return times;
  659. }
  660. //------------- 养殖场数据-----------
  661. /** 养殖场数据 服务器数据 */
  662. private _pastureData = [];
  663. /** 养殖场字典 本地数据,方便操作*/
  664. private _pastureDataMap: Map<number, any> = new Map();
  665. public setPastureDataMap(id, data, sendToServer = true) {
  666. this._pastureDataMap.set(id, data);
  667. let len = this._pastureData.length;
  668. for (var i = 0; i < len; i++) {
  669. if (this._pastureData[i].id == id) {
  670. this._pastureData[i].state = data.state;
  671. this._pastureData[i].productID = data.productID;
  672. this._pastureData[i].growSpan = data.growSpan;
  673. break;
  674. }
  675. }
  676. this.needFreshArr.push(id);
  677. //更新到服务器
  678. if (sendToServer) {
  679. this.freshSendToServer(2);
  680. }
  681. }
  682. public getPastureDataMap(id) {
  683. return this._pastureDataMap.get(id);
  684. }
  685. /** 服务器数据设置到本地 */
  686. public setPastureDataMapByServer() {
  687. this._pastureData = this.getProp(GameProp.pastureData);
  688. if (!this._pastureData) {
  689. this._pastureData = [];
  690. }
  691. let len = this._pastureData.length;
  692. //新玩家初始化养殖场数据
  693. if (len < 3) {
  694. let arr = this.getProductArrByType(ProductType.dw);
  695. let len1 = arr.length;
  696. let id = 30001;
  697. let data = null;
  698. for (var i = 0; i < len1; i++) {
  699. if (this.playerProp.completeFarmTaskTimes < arr[i].value) {
  700. data = { id: id, state: PastureState.Lock, productID: arr[i].picture, growSpan: 0 };
  701. }
  702. else {
  703. data = { id: id, state: PastureState.Empty, productID: arr[i].picture, growSpan: 0 };
  704. }
  705. this._pastureData.push(data);
  706. this._pastureDataMap.set(id, data);
  707. id++;
  708. }
  709. //更新到服务器
  710. this.setProp(GameProp.pastureData, this._pastureData);
  711. }
  712. else {
  713. let sickTimes = 0;
  714. for (var i = 0; i < len; i++) {
  715. this._pastureDataMap.set(this._pastureData[i].id, this._pastureData[i]);
  716. if (this._pastureData[i].state == PastureState.Sick) {
  717. sickTimes++;
  718. }
  719. }
  720. this.RawInsectCurArr[1] = sickTimes;
  721. }
  722. }
  723. //------------- 工厂数据-----------
  724. /** 工厂数据 服务器数据 */
  725. private _factoryData = [];
  726. /** 工厂字典 本地数据,方便操作*/
  727. private _factoryDataMap: Map<number, any> = new Map();
  728. public setFactoryDataMap(id, data, sendToServer = true) {
  729. this._factoryDataMap.set(id, data);
  730. let len = this._factoryData.length;
  731. for (var i = 0; i < len; i++) {
  732. if (this._factoryData[i].id == id) {
  733. this._factoryData[i].state = data.state;
  734. this._factoryData[i].productID = data.productID;
  735. this._factoryData[i].growSpan = data.growSpan;
  736. break;
  737. }
  738. }
  739. this.needFreshArr.push(id);
  740. //更新到服务器
  741. if (sendToServer) {
  742. this.freshSendToServer(3);
  743. }
  744. }
  745. public getFactoryDataMap(id) {
  746. return this._factoryDataMap.get(id);
  747. }
  748. /** 服务器数据设置到本地 */
  749. public setFactoryDataMapByServer() {
  750. this._factoryData = this.getProp(GameProp.factoryData);
  751. if (!this._factoryData) {
  752. this._factoryData = [];
  753. }
  754. let len = this._factoryData.length;
  755. //新玩家初始化工厂数据
  756. if (len < 6) {
  757. let id = 30004;
  758. let data = null;
  759. let tab = null;
  760. for (var i = 0; i < 6; i++) {
  761. tab = this.getTabByConfigID(id);
  762. let arr = this.getProductArrByType(tab);
  763. if (this.playerProp.completeFarmTaskTimes < arr[0].value) {
  764. data = { id: id, state: FactroyState.Lock, productID: 0, growSpan: 0 };
  765. }
  766. else {
  767. data = { id: id, state: FactroyState.Empty, productID: 0, growSpan: 0 };
  768. //更新最大可购买商品
  769. this.setMaxProduct(arr[0].picture, true);
  770. }
  771. this._factoryData.push(data);
  772. this._factoryDataMap.set(id, data);
  773. id++;
  774. }
  775. //更新到服务器
  776. this.setProp(GameProp.factoryData, this._factoryData);
  777. }
  778. else {
  779. let sickTimes = 0;
  780. let id = 30004;
  781. let tab = null;
  782. for (var i = 0; i < len; i++) {
  783. tab = this.getTabByConfigID(id);
  784. let arr = this.getProductArrByType(tab);
  785. this._factoryDataMap.set(this._factoryData[i].id, this._factoryData[i]);
  786. if (this._factoryData[i].state == FactroyState.Sick) {
  787. sickTimes++;
  788. }
  789. if (this.playerProp.completeFarmTaskTimes >= arr[0].value) {
  790. //更新最大可购买商品
  791. this.setMaxProduct(arr[0].picture, true);
  792. }
  793. id++;
  794. }
  795. this.RawInsectCurArr[2] = sickTimes;
  796. }
  797. }
  798. /** 通过工厂建筑物ID获取标签 */
  799. getTabByConfigID(configID: number): ProductType {
  800. let tab = ProductType.bmhc;
  801. switch (configID) {
  802. case 30004:
  803. tab = ProductType.bmhc;
  804. break;
  805. case 30005:
  806. tab = ProductType.gdp;
  807. break;
  808. case 30006:
  809. tab = ProductType.ztc;
  810. break;
  811. case 30007:
  812. tab = ProductType.lrc;
  813. break;
  814. case 30008:
  815. tab = ProductType.gfmg;
  816. break;
  817. case 30009:
  818. tab = ProductType.kcd;
  819. break;
  820. }
  821. return tab;
  822. }
  823. /** 通过标签获取工厂建筑物ID */
  824. getConfigIDByTab(tab: ProductType): number {
  825. let configID = 0;
  826. switch (tab) {
  827. case ProductType.bmhc:
  828. configID = 30004;
  829. break;
  830. case ProductType.gdp:
  831. configID = 30005;
  832. break;
  833. case ProductType.ztc:
  834. configID = 30006;
  835. break;
  836. case ProductType.lrc:
  837. configID = 30007;
  838. break;
  839. case ProductType.gfmg:
  840. configID = 30008;
  841. break;
  842. case ProductType.kcd:
  843. configID = 30009;
  844. break;
  845. }
  846. return configID;
  847. }
  848. /** 发送数据到服务器 */
  849. freshSendToServer(type) {
  850. switch (type) {
  851. case 1:
  852. this.setProp(GameProp.farmData, this._farmData);
  853. break;
  854. case 2:
  855. this.setProp(GameProp.pastureData, this._pastureData);
  856. break;
  857. case 3:
  858. this.setProp(GameProp.factoryData, this._factoryData);
  859. break;
  860. }
  861. }
  862. /** 最大可种植/生产商品数组 */
  863. private _maxProduct = [];
  864. public getMaxProduct(tab) {
  865. if (this._maxProduct) {
  866. let len = this._maxProduct.length;
  867. let data = null;
  868. for (var i = 0; i < len; i++) {
  869. data = this._maxProduct[i];
  870. if (data.tab == tab) {
  871. return data.productID;
  872. }
  873. }
  874. }
  875. return null;
  876. }
  877. /** 设置最大可生产商品
  878. * @param id 产品id
  879. * @param unlock 是否是解锁增加
  880. */
  881. public setMaxProduct(id, unlock = false) {
  882. let config = this.getProductMap(id);
  883. if (!this._maxProduct) {
  884. this._maxProduct = [];
  885. }
  886. let len = this._maxProduct.length;
  887. let data = null;
  888. let has = false;
  889. for (var i = 0; i < len; i++) {
  890. data = this._maxProduct[i];
  891. if (data.tab == config.tab) {
  892. if (data.productID < id) {
  893. data.productID = id;
  894. }
  895. has = true;
  896. break;
  897. }
  898. }
  899. if (!has && unlock) {
  900. data = { tab: config.tab, productID: id };
  901. this._maxProduct.push(data);
  902. }
  903. gData.farmMapData.isStateChange = true;
  904. this.updateMaxProduct();
  905. }
  906. /** 农场升级时解锁工厂,检查最大可种植/生产商品 */
  907. public checkTaskFinishUnLock() {
  908. for (var key in ProductType) {
  909. let tab = ProductType[key];
  910. let configArr = this.getProductArrByType(tab);
  911. let len = configArr.length;
  912. let data = null;
  913. let needUpdate = false;
  914. switch (tab) {
  915. case ProductType.nzw:
  916. break;
  917. case ProductType.dw:
  918. let id = 30001;
  919. needUpdate = false;
  920. let maxId = 0;
  921. for (var i = 0; i < len; i++) {
  922. data = this.getPastureDataMap(id);
  923. if (this.playerProp.completeFarmTaskTimes >= configArr[i].value) {
  924. if (data.state == PastureState.Lock) {
  925. data = { id: id, state: PastureState.Empty, productID: configArr[i].picture, growSpan: 0 };
  926. this.setPastureDataMap(id, data, false);
  927. needUpdate = true;
  928. }
  929. maxId = configArr[i].picture;
  930. }
  931. id++;
  932. }
  933. if (maxId != 0) {
  934. //更新最大可购买商品
  935. this.setMaxProduct(maxId, true);
  936. }
  937. //更新到服务器
  938. if (needUpdate) {
  939. this.setProp(GameProp.pastureData, this._pastureData);
  940. this.setNextProduct();
  941. }
  942. break;
  943. default:
  944. //工厂解锁根据第一个商品
  945. needUpdate = false;
  946. let configID = this.getConfigIDByTab(tab);
  947. data = this.getFactoryDataMap(configID);
  948. if (this.playerProp.completeFarmTaskTimes >= configArr[0].value) {
  949. if (data.state == FactroyState.Lock) {
  950. data = { id: id, state: FactroyState.Empty, productID: 0, growSpan: 0 };
  951. this.setFactoryDataMap(configID, data, false);
  952. needUpdate = true;
  953. }
  954. //更新最大可购买商品
  955. this.setMaxProduct(configArr[0].picture, true);
  956. }
  957. if (needUpdate) {
  958. this.setProp(GameProp.factoryData, this._factoryData);
  959. this.setNextProduct();
  960. }
  961. break;
  962. }
  963. }
  964. }
  965. checkCanSpeedUp(pop = false) {
  966. let can = false;
  967. can = gData.farmSystem.canSpeedUp();
  968. if (!can) {
  969. can = gData.pastureSystem.canSpeedUp();
  970. if (!can) {
  971. can = gData.factorySystem.canSpeedUp();
  972. }
  973. }
  974. if (can && pop) {
  975. mk.ui.openPanel('module/speedUpUI/speedUp');
  976. }
  977. return can;
  978. }
  979. setHarvest() {
  980. gData.farmSystem.setHarvest();
  981. gData.pastureSystem.setHarvest();
  982. gData.factorySystem.setHarvest();
  983. }
  984. checkCanHarvest() {
  985. let can = false;
  986. can = gData.farmSystem.canHarvest();
  987. if (!can) {
  988. can = gData.pastureSystem.canHarvest();
  989. if (!can) {
  990. can = gData.factorySystem.canHarvest();
  991. }
  992. }
  993. return can;
  994. }
  995. checkCanClearSick() {
  996. let can = false;
  997. can = gData.farmSystem.canClearSick();
  998. if (!can) {
  999. can = gData.pastureSystem.canClearSick();
  1000. if (!can) {
  1001. can = gData.factorySystem.canClearSick();
  1002. }
  1003. }
  1004. return can;
  1005. }
  1006. doPointToXYLogic() {
  1007. let value = mk.storage.getStorage('cash_out');
  1008. if (!value) {
  1009. mk.storage.setStorage('cash_out', 1);
  1010. mk.data.sendXYEvent('cash_1', `第一次提现`);
  1011. } else {
  1012. if (value == 1) {
  1013. mk.storage.setStorage('cash_out', 2);
  1014. mk.data.sendXYEvent('cash_2', `第二次提现`);
  1015. } else if (value == 2) {
  1016. mk.storage.setStorage('cash_out', 3);
  1017. mk.data.sendXYEvent('cash_3', `第三次提现`);
  1018. }
  1019. }
  1020. }
  1021. /** 更新最大可种植产品到服务器 */
  1022. async updateMaxProduct() {
  1023. if (this.maxProductToServer) {
  1024. let data = {"unLockProductList": []};
  1025. for(let i = 0; i != this._maxProduct.length; ++i)
  1026. {
  1027. let dataE = this._maxProduct[i];
  1028. let d = {id: dataE.productID, tab: dataE.tab};
  1029. data.unLockProductList.push(d);
  1030. }
  1031. let respone =await mk.http.sendData('orderTask/updateUnlockProduct', data);
  1032. console.log("------");
  1033. }
  1034. }
  1035. }
  1036. /**
  1037. * 所有模块的非校验数据
  1038. */
  1039. export enum GameProp {
  1040. /** -------------------- 通用玩家数据 ------------------------- */
  1041. /** 是否新手 0新手 1老手 */
  1042. newPlayer = 1,
  1043. /** 当前新手引导步骤 */
  1044. guideID = 2,
  1045. /** 需要自动弹界面 每次登录都弹 除首次 表示今日是否要自动开 1自动开 2不自动开 其他不处理*/
  1046. isAutoOpenPanel = 3,
  1047. /** 关闭常规提现时需要自动开存钱罐 每天一次 表示今日有没有开过 */
  1048. isOpenBankOnCloseCash = 4,
  1049. //看视频次数
  1050. videoTimes = 5,
  1051. //提现次数
  1052. cashTimes = 6,
  1053. /** ------------------ 游戏核心数据 --------------------------- */
  1054. /** 农田数据 */
  1055. farmData = 11,
  1056. /** 产品生产次数 */
  1057. productMakeTimes = 12,
  1058. /** 养殖场数据 */
  1059. pastureData = 14,
  1060. /** 工厂数据 */
  1061. factoryData = 15,
  1062. /** 剩余可种植次数 */
  1063. leftTimes = 16,
  1064. /**
  1065. 图鉴领取数据*/
  1066. farmMapGetRewardData = 17,
  1067. //红包任务tag
  1068. redBagTaskRefresh = 18,
  1069. /** ------------------ 转盘数据 ------------------------------ */
  1070. turnable_leftTimes = 20,
  1071. //提现次数
  1072. cashOutTimes = 21,
  1073. }
  1074. /**
  1075. * 玩家数据
  1076. */
  1077. class PlayerProp {
  1078. /** 自定义不需要校验的数据 */
  1079. gameUserData = 0;
  1080. _isSignInToday = 0;
  1081. /**
  1082. * 今日是否有签到
  1083. * - 0 未签到,表示可以签到
  1084. * - 1 有签到,表示不可签到
  1085. */
  1086. set isSignInToday(value: number) {
  1087. this._isSignInToday = value;
  1088. gData.sign.init_data = true;
  1089. gData.gameData.init_red_point = true;
  1090. }
  1091. get isSignInToday(): number {
  1092. return this._isSignInToday;
  1093. }
  1094. private _piggyBank: number = 0;
  1095. /** 存钱罐存款 */
  1096. set piggyBank(value: number) {
  1097. if (this._piggyBank === value) return;
  1098. if (gData.gameData.playerProp.isWithdrawable && value > 0) return;// 存钱罐可提现状态,不能增加存钱罐金额
  1099. this._piggyBank = value;
  1100. gData.gameData.init_coin = true;
  1101. gData.gameData.init_red_point = true;
  1102. }
  1103. get piggyBank(): number {
  1104. return this._piggyBank;
  1105. }
  1106. /** 初始化 */
  1107. initPiggyBank(v) {
  1108. this._piggyBank = v;
  1109. }
  1110. _isWithdrawable = 0;
  1111. /**
  1112. * 存钱罐能否提现
  1113. * - 0 不能提现
  1114. * - 1 能提现
  1115. */
  1116. set isWithdrawable(value: number) {
  1117. if (this._isWithdrawable != value) {
  1118. this._isWithdrawable = value;
  1119. gData.gameData.init_red_point = true;
  1120. }
  1121. }
  1122. get isWithdrawable(): number {
  1123. return this._isWithdrawable;
  1124. }
  1125. /** 存钱罐每日提现次数 */
  1126. piggyBankCashTimes = 0;
  1127. /** 累计存钱罐每日提现次数 */
  1128. totalPiggyBankCashTimes = 0;
  1129. /** 提现进度 */
  1130. cashIndex = 0;
  1131. /** 上次登录时间 */
  1132. lastTime = 0;
  1133. /** 登录天数 */
  1134. loginDays = 0;
  1135. newPlayer = 0;
  1136. private _redMoney: number = 0;
  1137. /** 红包币数量 */
  1138. set redMoney(value: number) {
  1139. this._redMoney = value;
  1140. gData.gameData.init_coin = true;
  1141. //gData.gameData.init_red_point = true;
  1142. gData.gameData.init_wallet_redMoney = true;
  1143. mk.event.emit('refreshCoin');
  1144. mk.data.setTAEventUser(0, 'current_redmoney_stock', this._redMoney);
  1145. }
  1146. get redMoney(): number {
  1147. return this._redMoney;
  1148. }
  1149. _signInDay = 0;
  1150. /** 累计签到次数 客户端理解 上次签到天数 */
  1151. set signInDay(value: number) {
  1152. if (this._signInDay === value) return;
  1153. this._signInDay = value;
  1154. gData.sign.init_data = true;
  1155. }
  1156. get signInDay(): number {
  1157. return this._signInDay;
  1158. }
  1159. /** 转盘次数 */
  1160. turntableTimes = 0;
  1161. /** 版本号 */
  1162. versioncfg = 0;
  1163. /** 福袋数据 */
  1164. userTuCaoInfo = 0;
  1165. /** 能免费领红包 1 表示是新人第一次产出红包币,不用看视频*/
  1166. isFirstRedMoney = 0;
  1167. //农场等级
  1168. gradeLevel = 1;
  1169. //农场等级奖励数据
  1170. farmGradeData: any = {};
  1171. //农场等级名字
  1172. farmGradeName: number = 1;
  1173. //农场经验
  1174. private farmExp = 0;
  1175. set farmExpValue(value: number) {
  1176. this.farmExp = value;
  1177. gData.gameData.init_expLevel = true;
  1178. }
  1179. get farmExpValue(): number {
  1180. return this.farmExp;
  1181. }
  1182. //提现新手数据
  1183. userNoviceWeFareInfo: any = {};
  1184. //提现记录数据
  1185. redMoneyCashPayRecordList = null;
  1186. //任务红;
  1187. userFarmTaskInfo = null;
  1188. getRedMoneyCashOutTimesByIndex(index: number): number {
  1189. if (this.redMoneyCashPayRecordList) {
  1190. for (let i = 0; i != this.redMoneyCashPayRecordList.length; ++i) {
  1191. if (index === this.redMoneyCashPayRecordList[i].index) {
  1192. return this.redMoneyCashPayRecordList[i].frequency;
  1193. }
  1194. }
  1195. }
  1196. return 0;
  1197. }
  1198. /** ABTest分组id */
  1199. groupCode = 0;
  1200. //加速剩余次数
  1201. speedUpLeftTimes = 0;
  1202. /** 农场任务完成次数 */
  1203. completeFarmTaskTimes = 0;
  1204. /** 订单数据 */
  1205. orderData = null;
  1206. }
  1207. /**
  1208. * 奖励状态
  1209. */
  1210. export enum RewardState {
  1211. /** 已领取 */
  1212. none = 1,
  1213. /** 未解锁 */
  1214. lock = 2,
  1215. /** 可领取 */
  1216. unlock = 3
  1217. }
  1218. /**
  1219. * 奖励类型
  1220. */
  1221. export enum RewardType {
  1222. /** 红包币 */
  1223. redBag = 1,
  1224. /** 毛币 */
  1225. rmb = 2,
  1226. /** 金猪币 */
  1227. pigRmb = 3,
  1228. /** 生产次数 */
  1229. productTimes = 4,
  1230. }
  1231. /**
  1232. * 音频路径
  1233. */
  1234. export enum AUDIO_TYPE {
  1235. /**主界面背景音乐*/
  1236. bgm = 'bgm',
  1237. /**打开存钱罐界面播放一次*/
  1238. pigBank = 'pigBank',
  1239. /**关卡玩法背景音乐*/
  1240. missionBg = 'missionBg',
  1241. /**红包币领取界面关闭音效*/
  1242. rewardClose = 'rewardClose',
  1243. /**红包币领取界面开启音效*/
  1244. rewardOpen = 'rewardOpen',
  1245. /**红包界面打开音效*/
  1246. reward = 'reward',
  1247. /**提现到账界面打开播放一次*/
  1248. receiptNotice = 'receiptNotice',
  1249. /**通用按钮点击音效 */
  1250. button = 'button',
  1251. /**转盘转动音效*/
  1252. turnableplay = 'turnableplay',
  1253. /**转盘转动音效*/
  1254. turnplateDrawEnd = 'turnplateDrawEnd',
  1255. /**主页背景音乐 */
  1256. music_startBg = "music_startBg",
  1257. /**游戏背景音乐 */
  1258. music_gameBg = "music_gameBg",
  1259. /**按钮点击 */
  1260. ef_button_click = "ef_button_click",
  1261. /**红包打开 */
  1262. ef_redPacket_open = "ef_redPacket_open",
  1263. /**红包来了音效 */
  1264. ef_redPacket_come = "ef_redPacket_come",
  1265. /**消除4个 */
  1266. ef_bonus4 = "ef_bonus4",
  1267. /**消除5个 */
  1268. ef_bonus5 = "ef_bonus5",
  1269. /**消除6个 */
  1270. ef_bonus6 = "ef_bonus6",
  1271. /**消除7个 */
  1272. ef_bonus7 = "ef_bonus7",
  1273. /**消除8个 */
  1274. ef_bonus8 = "ef_bonus8",
  1275. /**普通消除音效 */
  1276. ef_eliminate = "ef_eliminate",
  1277. /**bouns消除音效 */
  1278. ef_eliminate_bonus = "ef_eliminate_bonus",
  1279. /**胜利音效 */
  1280. ef_win = "ef_win",
  1281. /**锤子 */
  1282. ef_change = "ef_change",
  1283. /**刷新 */
  1284. ef_refresh = "ef_refresh",
  1285. /**飞翔 */
  1286. ef_fly = "ef_fly",
  1287. /**关闭按钮音效*/
  1288. closeButton = "closeButton",
  1289. //红包界面打开
  1290. congratulations = 'congratulations',
  1291. //红包飞音效
  1292. redmoney = 'redmoney'
  1293. }
  1294. /** ECPM */
  1295. type ADShowCfg = {
  1296. average_ecpm: number,
  1297. insert_probability: number,
  1298. is_show_banner: number,
  1299. is_show_inter: number,
  1300. }
  1301. /**事件类型 */
  1302. export enum EVENT_TYPE {
  1303. BACK_WxAuth = "BACK_WxAuth",
  1304. UPDATE_CashNum = "UPDATE_CashNum",
  1305. }
  1306. /** 数据事件Id */
  1307. export enum DataEventId {
  1308. /** 点击 */
  1309. guide = "guide",
  1310. /** 点击跳过 */
  1311. guideSkip = "guideSkip",
  1312. /** 按钮点击 */
  1313. button_click = "button_click",
  1314. /** 看视频 */
  1315. video_init = "video_init",
  1316. /** 看视频完成 */
  1317. video_end = "video_end",
  1318. /** 成功拉取全屏视频 */
  1319. interstitial2_init = "interstitial2_init",
  1320. /** 广告点击 */
  1321. Ad_click = "Ad_click",
  1322. /** 全屏视频完成 */
  1323. interstitial2_end = "interstitial2_end",
  1324. /** 福袋功能 */
  1325. fudaiFunction = "fudaiFunction",
  1326. /** 互推功能 */
  1327. hutuiFunction = "hutuiFunction",
  1328. /** 激励视频ecpm */
  1329. ad_videoEcpm = 'ad_video',
  1330. /** 开屏ecpm */
  1331. ad_openEcpm = 'ad_open',
  1332. /** 提现 */
  1333. Sundry = 'Sundry',
  1334. /** 加载 */
  1335. loading = 'loading',
  1336. /** 排队 */
  1337. queue = 'queue'
  1338. }
  1339. /** 视频广告类型 */
  1340. export enum VideoAdType {
  1341. video_init_1 = '农场加等级经验',
  1342. video_init_2 = '提现-加进度',
  1343. video_init_3 = '提现-加现金',
  1344. video_init_4 = '签到',
  1345. video_init_5 = '抽奖',
  1346. video_init_6 = '图鉴领奖',
  1347. video_init_7 = '消灭害虫',
  1348. video_init_8 = '恢复健康',
  1349. video_init_9 = '恢复供电',
  1350. video_init_10 = '山羊红包',
  1351. video_init_11 = '拓建',
  1352. video_init_12 = '收获',
  1353. video_init_13 = '飘浮红包',
  1354. video_init_14 = '全体加速',
  1355. video_init_15 = '福利加进度',
  1356. video_init_16 = '生产加次数',
  1357. video_init_17 = '点击生产按钮',
  1358. video_init_18 = '离开游戏领红包',
  1359. video_init_19 = '定时弹出红包',
  1360. video_init_20 = '插队',
  1361. video_init_21 = '恢复生产次数',
  1362. }
  1363. export enum InterFullAdType {
  1364. interstitial2_init_1 = '点击红包的关闭按钮',
  1365. interstitial2_init_2 = '普通收获',
  1366. interstitial2_init_3 = '点击鸟和狗'
  1367. }
  1368. export enum InterAdType {
  1369. interstitial1_click_1 = '恭喜发财红包弹出后',
  1370. interstitial1_click_2 = '恭喜获得弹窗弹出后',
  1371. interstitial1_click_3 = '生虫/生病/停电弹出后'
  1372. }
  1373. export enum BannerAdType {
  1374. banner_click_1 = '恭喜获得弹窗弹出后',
  1375. banner_click_2 = '任务红包',
  1376. banner_click_3 = '恭喜发财红包',
  1377. banner_click_4 = '图鉴',
  1378. banner_click_5 = '全体加速',
  1379. banner_click_6 = '收获弹窗',
  1380. banner_click_7 = '拓建弹窗',
  1381. banner_click_8 = '三个恢复弹窗',
  1382. banner_click_9 = '抽奖'
  1383. }
  1384. export enum ExpAddType {
  1385. EAT_video = 1,
  1386. EAT_harvest = 2,
  1387. EAT_others = 3,
  1388. }
  1389. export enum FarmState {
  1390. Lock,
  1391. CanUnlock,
  1392. Empty,
  1393. Growing,
  1394. Ripe,
  1395. Sick
  1396. }
  1397. export enum PastureState {
  1398. Lock,
  1399. Empty,
  1400. Growing,
  1401. Ripe,
  1402. Sick
  1403. }
  1404. export enum ProductType {
  1405. nzw = '农作物',
  1406. dw = '动物',
  1407. bmhc = '爆米花厂',
  1408. gdp = '糕点铺',
  1409. ztc = '制糖厂',
  1410. lrc = '炼乳厂',
  1411. gfmg = '功夫面馆',
  1412. kcd = '快餐店'
  1413. }
  1414. /** 动物状态 */
  1415. export enum AnimalState {
  1416. Hanger,
  1417. Eat,
  1418. Wait
  1419. }
  1420. export enum FactroyState {
  1421. Lock,
  1422. Empty,
  1423. Producting,
  1424. Ripe,
  1425. Sick
  1426. }