GameData.ts 42 KB

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