GameData.ts 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. import FunBtns from "../game/FunBtns";
  2. import Game from "../game/Game";
  3. /**
  4. * @description 游戏核心玩法数据
  5. * @author 邹勇
  6. */
  7. export class GameData {
  8. public dataFinish: boolean = false;
  9. public savePropFinish: boolean = false;
  10. public savePropsFinish: boolean = false;
  11. public getPropsFnish: boolean = false;
  12. public configs: any = {};
  13. public adShowConfig: ADShowCfg;
  14. /** 功能开启 */
  15. public funOpenData: string[] = [];
  16. public gameData: PlayerProp = null;
  17. /** 标志位:刷新主界面货币 */
  18. public init_coin: boolean = false;
  19. public updatePiggyBankValue: boolean = false;
  20. /** 标志位:刷新主界面头像 */
  21. public init_head: boolean = false;
  22. /** 标志位:刷新主界面红点 */
  23. public init_red_point: boolean = true;
  24. /** 属性存储字典 */
  25. public props: Map<number, any> = new Map<number, any>();
  26. public pools = [
  27. { url: "game/prefab/tips", num: 20 },
  28. { url: "game/prefab/coin", num: 20 }
  29. ];
  30. /** 主页样式脚本 */
  31. public gameStyle: Game = null;
  32. /** 入口按钮 */
  33. public funBtns: FunBtns = null;
  34. /**
  35. * 初始化游戏数据:网络配置信息,用户信息
  36. * @returns
  37. */
  38. public async init() {
  39. let data: any = { "versionCode": gData.appData.version };
  40. let response = await mk.http.sendData('getAllConfigInfo', data);
  41. if (response.errcode != 0) {
  42. if (response.errcode == -10003 || response.errcode == -20003) {
  43. //清除缓存
  44. gData.loginData.reload();
  45. }
  46. return;
  47. }
  48. mk.console.logSingle("getAllConfigInfo", response.data);
  49. this.initConfigs(response.data);
  50. data = {};
  51. response = await mk.http.sendData('getInfoCrypt', data);
  52. if (response.errcode != 0) {
  53. return;
  54. }
  55. mk.console.logSingle("getInfoCrypt", response.data);
  56. this.initPlayerProp(response.data)
  57. this.initProps(response.data.gameUserData);
  58. gData.guideData.init();
  59. gData.guideWeakData.init();
  60. gData.moduleData.forEach(element => {
  61. element.init();
  62. });
  63. data = {};
  64. response = await mk.http.sendData('user/adShowConfig', data);
  65. if (response.errcode != 0) {
  66. return;
  67. }
  68. this.adShowConfig = response.data;
  69. mk.console.logSingle("user/adShowConfig", response.data);
  70. this.dataFinish = true;
  71. }
  72. private initConfigs(data) {
  73. // console.log('config ', data);
  74. this.configs = data;
  75. this.funOpenData = this.configs.ServerConfig.Functionswitch.split(",");
  76. }
  77. /**
  78. * 初始化玩家数据
  79. */
  80. private initPlayerProp(res_data) {
  81. this.gameData = new PlayerProp();
  82. this.gameData.cashIndex = res_data.cashIndex;
  83. this.gameData.gameUserData = res_data.gameUserData;
  84. this.gameData.isSignInToday = res_data.isSignInToday;
  85. this.gameData.isWithdrawable = res_data.isWithdrawable;
  86. this.gameData.lastTime = res_data.lastTime;
  87. this.gameData.loginDays = res_data.loginDays;
  88. this.gameData.newPlayer = res_data.newPlayer;
  89. this.gameData.initPiggyBank(res_data.piggyBank);
  90. this.gameData.piggyBankCashTimes = res_data.piggyBankCashTimes;
  91. this.gameData.redMoney = res_data.redMoney == null ? 0 : res_data.redMoney;
  92. this.gameData.signInDay = res_data.signInDay;
  93. this.gameData.totalPiggyBankCashTimes = res_data.totalPiggyBankCashTimes;
  94. this.gameData.turntableTimes = res_data.turntableTimes;
  95. this.gameData.userTuCaoInfo = res_data.userTuCaoInfo;
  96. this.gameData.versioncfg = res_data.versioncfg;
  97. this.gameData.isFirstRedMoney = res_data.isFirstRedMoney;
  98. gData.adData.watchNumToday = res_data.dayVideoTimesForRedMoney == null ? 0 : res_data.dayVideoTimesForRedMoney;
  99. }
  100. /**
  101. * 保存单个数据
  102. */
  103. public async setProp(key: GameProp, value: any) {
  104. let data = {
  105. key: key + '',
  106. value: value
  107. };
  108. this.props.set(key, value);
  109. await mk.http.sendData('savePlayerProp', data);
  110. this.savePropFinish = true;
  111. }
  112. /**
  113. * 保存多个数据
  114. */
  115. public async setProps(arr: { key: GameProp, value: any }[]) {
  116. let needProp = {};
  117. for (let i = 0; i < arr.length; i++) {
  118. needProp[arr[i].key + ''] = arr[i].value;
  119. }
  120. let data = {
  121. needProp: needProp
  122. };
  123. for (let i = 0; i < arr.length; i++) {
  124. this.props.set(arr[i].key, arr[i].value);
  125. }
  126. await mk.http.sendData('saveAllPlayerProp', data);
  127. this.savePropsFinish = true;
  128. }
  129. /** 获取属性 */
  130. public getProp(key: GameProp): number {
  131. if (this.props == null) {
  132. return 0;
  133. }
  134. let value = this.props.get(key);
  135. return value;
  136. }
  137. /**
  138. * 向服务器请求所有属性后更新
  139. */
  140. public async getAllProps() {
  141. let response = await mk.http.sendData('getAllPlayerProp', {});
  142. if (response.errcode != 0) {
  143. return;
  144. }
  145. this.initProps(response.data);
  146. this.getPropsFnish = true;
  147. }
  148. private initProps(data) {
  149. if (data == null) {
  150. return;
  151. }
  152. for (let key in data) {
  153. this.props.set(parseInt(key), data[key]);
  154. }
  155. }
  156. /**
  157. * 第二天需要重置的数据
  158. */
  159. public resetProps() {
  160. let arr = [];
  161. arr.push({ key: GameProp.sign_can, value: 1 });
  162. arr.push({ key: GameProp.isAutoOpenPanel, value: 1 });
  163. arr.push({ key: GameProp.isOpenBankOnCloseCash, value: 0 });
  164. this.setProps(arr);
  165. }
  166. /** 是否是新用户 */
  167. public isNewPlayer(): boolean {
  168. let v = this.getProp(GameProp.newPlayer);
  169. return v == 0;
  170. }
  171. //*********** ================= 农场数据 ================== */
  172. public needReloadData = false;
  173. private _productingListMap: Map<number, Array<{ productID: number, ripeDate: number }>> = new Map();
  174. /**建筑生产队列列表 */
  175. public getProductingList(id: number): Array<{ productID: number, ripeDate: number }> {
  176. if (!this._productingListMap.has(id)) {
  177. this._productingListMap.set(id, []);
  178. }
  179. return this._productingListMap.get(id);
  180. }
  181. private _unlockMap: Map<number, number> = new Map();
  182. /**建筑解锁流水线数量列表 */
  183. public getUnlock(id: number): number {
  184. if (!this._unlockMap.has(id)) {
  185. if (id <= 30003) {
  186. this._unlockMap.set(id, 5);
  187. } else {
  188. this._unlockMap.set(id, 1);
  189. }
  190. }
  191. return this._unlockMap.get(id);
  192. }
  193. public setUnlock(id: number, count: number): void {
  194. this._unlockMap.set(id, count);
  195. }
  196. /**已激活的建筑列表 */
  197. private buildDataMap: Map<number, number> = new Map();
  198. public hasBuildData(id: number): boolean {
  199. return this.buildDataMap.has(id);
  200. }
  201. public getBuildData(id: number): number {
  202. return this.buildDataMap.get(id);
  203. }
  204. public setBuildData(id: number, userBuildID: number): void {
  205. this.buildDataMap.set(id, userBuildID);
  206. }
  207. // /**设置建筑数据(生产队列,流水线数量,激活情况等) */
  208. // public async setGameData(data: any) {
  209. // this._productingListMap = new Map();
  210. // this._unlockMap = new Map();
  211. // this.buildDataMap = new Map();
  212. // let product = ConfigData.configMap.get("product");
  213. // for (let i = 0; i < data.length; i++) {
  214. // const build = data[i];
  215. // if (!this.buildDataMap.has(build.buildID)) {
  216. // this.buildDataMap.set(build.buildID, build.userBuildID);
  217. // this.setUnlock(build.buildID, build.addValue + 1);
  218. // }
  219. // if (build.productID != 0) {
  220. // let result = product[build.productID];
  221. // this.getProductingList(build.buildID).push({ productID: build.productID, ripeDate: build.plantTime * 1000 + result["time"] * 1000 });
  222. // }
  223. // }
  224. // }
  225. /**是否有任务可领取 */
  226. public taskReceive = false;
  227. /**是否有3日活动任务可领取 */
  228. public threeDayTaskReceive = 0;
  229. /**3日活动还需要邀请人数 */
  230. public needChildCount: number = 0;
  231. /**3日活动激活后结束时间 */
  232. public threedayTaskTime: number = 0
  233. /**种植奖励数据 */
  234. public productPrize = null;
  235. // /**排行榜数据*/
  236. // public rankData: RankData;
  237. // /**排行榜积分数据*/
  238. // public rankScore: number = 0;
  239. // /**是否刷新排行榜活动倒计时*/
  240. // public isRefreshRankTime: boolean;
  241. // /**是否可以领取排行榜奖励*/
  242. // public isCanGetRankReward: boolean;
  243. }
  244. /**
  245. * 所有模块的非校验数据
  246. */
  247. export enum GameProp {
  248. /** -------------------- 通用玩家数据 ------------------------- */
  249. /** 是否新手 0新手 1老手 */
  250. newPlayer = 1,
  251. /** 当前新手引导步骤 */
  252. guideID = 2,
  253. /** 需要自动弹界面 每次登录都弹 除首次 表示今日是否要自动开 1自动开 2不自动开 其他不处理*/
  254. isAutoOpenPanel = 3,
  255. /** 关闭常规提现时需要自动开存钱罐 每天一次 表示今日有没有开过 */
  256. isOpenBankOnCloseCash = 4,
  257. //看视频次数
  258. videoTimes = 5,
  259. //提现次数
  260. cashTimes = 6,
  261. /** ------------------ 游戏核心数据 --------------------------- */
  262. /** 农场等级 */
  263. levelNum = 10,
  264. /** ------------------ 转盘数据 ------------------------------ */
  265. turnable_leftTimes = 20,
  266. /** ------------------ 存钱罐数据 ----------------------------- */
  267. /** ------------------ 签到数据 ----------------------------- */
  268. /** 上次签到进度 */
  269. sign_last_bar = 120,
  270. /** 当前能否签到 */
  271. sign_can = 121,
  272. /** ------------------ 红包提现 ----------------------------- */
  273. /** 提现进度 */
  274. redBag_cash_bar = 220,
  275. }
  276. /**
  277. * 玩家数据
  278. */
  279. class PlayerProp {
  280. /** 自定义不需要校验的数据 */
  281. gameUserData = 0;
  282. _isSignInToday = 0;
  283. /**
  284. * 今日是否有签到
  285. * - 0 未签到,表示可以签到
  286. * - 1 有签到,表示不可签到
  287. */
  288. set isSignInToday(value: number) {
  289. this._isSignInToday = value;
  290. gData.sign.init_data = true;
  291. gData.gameData.init_red_point = true;
  292. }
  293. get isSignInToday(): number {
  294. return this._isSignInToday;
  295. }
  296. private _piggyBank: number = 0;
  297. /** 存钱罐存款 */
  298. set piggyBank(value: number) {
  299. if (this._piggyBank === value) return;
  300. if (gData.gameData.gameData.isWithdrawable && value > 0) return;// 存钱罐可提现状态,不能增加存钱罐金额
  301. this._piggyBank = value;
  302. gData.gameData.init_coin = true;
  303. gData.pigbank.init_data = true;
  304. gData.gameData.init_red_point = true;
  305. }
  306. get piggyBank(): number {
  307. return this._piggyBank;
  308. }
  309. /** 初始化 */
  310. initPiggyBank(v) {
  311. this._piggyBank = v;
  312. }
  313. _isWithdrawable = 0;
  314. /**
  315. * 存钱罐能否提现
  316. * - 0 不能提现
  317. * - 1 能提现
  318. */
  319. set isWithdrawable(value: number) {
  320. if (this._isWithdrawable != value) {
  321. this._isWithdrawable = value;
  322. gData.pigbank.init_data = true;
  323. gData.gameData.init_red_point = true;
  324. }
  325. }
  326. get isWithdrawable(): number {
  327. return this._isWithdrawable;
  328. }
  329. /** 存钱罐每日提现次数 */
  330. piggyBankCashTimes = 0;
  331. /** 累计存钱罐每日提现次数 */
  332. totalPiggyBankCashTimes = 0;
  333. /** 提现进度 */
  334. cashIndex = 0;
  335. /** 上次登录时间 */
  336. lastTime = 0;
  337. /** 登录天数 */
  338. loginDays = 0;
  339. newPlayer = 0;
  340. private _redMoney: number = 0;
  341. /** 红包币数量 */
  342. set redMoney(value: number) {
  343. this._redMoney = value;
  344. gData.gameData.init_coin = true;
  345. gData.gameData.init_red_point = true;
  346. }
  347. get redMoney(): number {
  348. return this._redMoney;
  349. }
  350. _signInDay = 0;
  351. /** 累计签到次数 客户端理解 上次签到天数 */
  352. set signInDay(value: number) {
  353. if (this._signInDay === value) return;
  354. this._signInDay = value;
  355. gData.sign.init_data = true;
  356. }
  357. get signInDay(): number {
  358. return this._signInDay;
  359. }
  360. /** 转盘次数 */
  361. turntableTimes = 0;
  362. /** 版本号 */
  363. versioncfg = 0;
  364. /** 福袋数据 */
  365. userTuCaoInfo = 0;
  366. /** 关卡数 */
  367. levelNum = 0;
  368. /** 锤子道具数目 */
  369. hammerPropNum = 0;
  370. /** 重设道具数目 */
  371. resetPropNum = 0;
  372. /** 变色道具数目 */
  373. changePropNum = 0;
  374. /** 能免费领红包 1 表示是新人第一次产出红包币,不用看视频*/
  375. isFirstRedMoney = 0;
  376. //玩家等级
  377. gradeLevel = 0;
  378. }
  379. /**
  380. * 奖励状态
  381. */
  382. export enum RewardState {
  383. /** 已领取 */
  384. none = 1,
  385. /** 未解锁 */
  386. lock = 2,
  387. /** 可领取 */
  388. unlock = 3
  389. }
  390. /**
  391. * 奖励类型
  392. */
  393. export enum RewardType {
  394. /** 红包币 */
  395. redBag = 1,
  396. /** 毛币 */
  397. rmb = 2,
  398. /** 金猪币 */
  399. pigRmb = 3,
  400. }
  401. /**
  402. * 音频路径
  403. */
  404. export enum AUDIO_TYPE {
  405. /**主界面背景音乐*/
  406. bgm = 'bgm',
  407. /**打开存钱罐界面播放一次*/
  408. pigBank = 'pigBank',
  409. /**关卡玩法背景音乐*/
  410. missionBg = 'missionBg',
  411. /**红包币领取界面关闭音效*/
  412. rewardClose = 'rewardClose',
  413. /**红包币领取界面开启音效*/
  414. rewardOpen = 'rewardOpen',
  415. /**红包界面打开音效*/
  416. reward = 'reward',
  417. /**提现到账界面打开播放一次*/
  418. receiptNotice = 'receiptNotice',
  419. /**通用按钮点击音效 */
  420. button = 'button',
  421. /**转盘转动音效*/
  422. turnableplay = 'turnableplay',
  423. /**转盘转动音效*/
  424. turnplateDrawEnd = 'turnplateDrawEnd',
  425. /**主页背景音乐 */
  426. music_startBg = "music_startBg",
  427. /**游戏背景音乐 */
  428. music_gameBg = "music_gameBg",
  429. /**按钮点击 */
  430. ef_button_click = "ef_button_click",
  431. /**红包打开 */
  432. ef_redPacket_open = "ef_redPacket_open",
  433. /**红包来了音效 */
  434. ef_redPacket_come = "ef_redPacket_come",
  435. /**消除4个 */
  436. ef_bonus4 = "ef_bonus4",
  437. /**消除5个 */
  438. ef_bonus5 = "ef_bonus5",
  439. /**消除6个 */
  440. ef_bonus6 = "ef_bonus6",
  441. /**消除7个 */
  442. ef_bonus7 = "ef_bonus7",
  443. /**消除8个 */
  444. ef_bonus8 = "ef_bonus8",
  445. /**普通消除音效 */
  446. ef_eliminate = "ef_eliminate",
  447. /**bouns消除音效 */
  448. ef_eliminate_bonus = "ef_eliminate_bonus",
  449. /**胜利音效 */
  450. ef_win = "ef_win",
  451. /**锤子 */
  452. ef_change = "ef_change",
  453. /**刷新 */
  454. ef_refresh = "ef_refresh",
  455. /**飞翔 */
  456. ef_fly = "ef_fly",
  457. /**关闭按钮音效*/
  458. closeButton = "closeButton",
  459. }
  460. /** ECPM */
  461. type ADShowCfg = {
  462. average_ecpm: number,
  463. insert_probability: number,
  464. is_show_banner: number,
  465. is_show_inter: number,
  466. }
  467. type PlayerInfoType = {
  468. /** 自定义不需要校验的数据 */
  469. gameUserData: object,
  470. /** 今日是否有签到 */
  471. isSignInToday: number,
  472. /** 存钱罐存款 */
  473. piggyBank: number,
  474. /** 存钱罐能否提现 */
  475. isWithdrawable: boolean,
  476. /** 存钱罐每日提现次数 */
  477. piggyBankCashTimes: number,
  478. /** 累计存钱罐每日提现次数 */
  479. totalPiggyBankCashTimes: number,
  480. /** 提现进度 */
  481. cashIndex: number,
  482. /** 上次登录时间 */
  483. lastTime: number,
  484. /** 登录天数 */
  485. loginDays: number,
  486. newPlayer: Boolean,
  487. /** 红包币数量 */
  488. redMoney: number,
  489. /** 累计签到次数 客户端理解 上次签到天数 */
  490. signInDay: number,
  491. /** 转盘次数 */
  492. turntableTimes: number,
  493. /** 版本号 */
  494. versioncfg: string,
  495. /** 福袋数据 */
  496. userTuCaoInfo: object,
  497. }
  498. /**事件类型 */
  499. export enum EVENT_TYPE {
  500. BACK_WxAuth = "BACK_WxAuth",
  501. UPDATE_CashNum = "UPDATE_CashNum",
  502. }
  503. /** 数据事件Id */
  504. export enum DataEventId {
  505. /** 点击 */
  506. guide = "guide",
  507. /** 按钮点击 */
  508. button_click = "button_click",
  509. /** 看视频 */
  510. video_init = "video_init",
  511. /** 看视频完成 */
  512. video_end = "video_end",
  513. /** 福袋功能 */
  514. fudaiFunction = "fudaiFunction",
  515. /** 互推功能 */
  516. hutuiFunction = "hutuiFunction",
  517. /** 关卡 */
  518. level = "level",
  519. /** 常规提现-红包币提现 */
  520. commonWithDrawal = "commonWithDrawl",
  521. /** 存钱罐提现 */
  522. jarWithDrawal = "jarWithDrawal",
  523. /** 签到提现 */
  524. signWithDrawal = "signWithDrawal",
  525. }
  526. /** 视频广告类型 */
  527. export enum VideoAdType {
  528. Null = "",
  529. /** 关卡积分红包 */
  530. LevelScoreRedBag = "关卡积分红包",
  531. /** 主界面气泡红包 */
  532. StartQiPaoRedBag = "主界面气泡红包",
  533. /** 关卡气泡红包 */
  534. LevelQiPaoRedBag = "关卡气泡红包",
  535. /** 转盘 */
  536. Turntable = "转盘视频",
  537. /** 福袋视频" */
  538. Fudai = "福袋视频",
  539. /** 签到视频 */
  540. Sign = "签到视频",
  541. //钱包提现新手视频
  542. CashOutNoviceWelfare = "钱包提现新手视频",
  543. //钱包提现加现金视频
  544. CashOutAddCash = "钱包提现加现金视频"
  545. }