GameData.ts 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. import FunBtns from "../game/FunBtns";
  2. import Game from "../game/Game";
  3. import { StorageKey } from "./StorageData";
  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. public configs: any = {};
  14. public adShowConfig: ADShowCfg;
  15. /** 功能开启 依次是 0 互推 1 转盘 2 裂变 3 存钱罐 4 福袋 5 签到 6 常规提现 7 气泡红包组 8 福利礼包*/
  16. public funOpenData: string[] = [];
  17. public gameData: PlayerProp = null;
  18. /** 标志位:刷新主界面货币 */
  19. public init_coin: boolean = false;
  20. public updatePiggyBankValue: boolean = false;
  21. /** 标志位:刷新主界面头像 */
  22. public init_head: boolean = false;
  23. /** 标志位:刷新主界面红点 */
  24. public init_red_point: boolean = true;
  25. public props: Map<number, number> = new Map<number, number>();
  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. //初始化topon
  51. mk.ad.init();
  52. data = {};
  53. response = await mk.http.sendData('getInfoCrypt', data);
  54. if (response.errcode != 0) {
  55. return;
  56. }
  57. mk.console.logSingle("getInfoCrypt", response.data);
  58. this.initPlayerProp(response.data)
  59. this.initProps(response.data.gameUserData);
  60. gData.guideData.init();
  61. gData.guideWeakData.init();
  62. gData.moduleData.forEach(element => {
  63. element.init();
  64. });
  65. data = {};
  66. response = await mk.http.sendData('user/adShowConfig', data);
  67. if (response.errcode != 0) {
  68. return;
  69. }
  70. this.adShowConfig = response.data;
  71. mk.console.logSingle("user/adShowConfig", response.data);
  72. gData.adData.setFullInterShowStr();
  73. this.dataFinish = true;
  74. }
  75. private initConfigs(data) {
  76. this.configs = data;
  77. this.funOpenData = this.configs.ServerConfig.Functionswitch.split(",");
  78. gData.safeDepositBoxData.richBankConfig = this.configs.RichBankTaskCfg;
  79. gData.loginData.popIdentifySwitch = this.configs.ServerConfig.popIdentifySwitch == '1';
  80. gData.guideToWxData.guideToWxSwith = this.configs.ServerConfig.guideToWxSwith == '1';
  81. gData.guideToWxData.money = this.configs.ServerConfig.addfriendmoney;
  82. gData.guideToWxData.setGhId();
  83. }
  84. /**
  85. * 初始化玩家数据
  86. */
  87. private initPlayerProp(res_data) {
  88. this.gameData = new PlayerProp();
  89. this.gameData.cashIndex = res_data.cashIndex;
  90. this.gameData.gameUserData = res_data.gameUserData;
  91. this.gameData.isSignInToday = res_data.isSignInToday;
  92. this.gameData.isWithdrawable = res_data.isWithdrawable;
  93. this.gameData.lastTime = res_data.lastTime;
  94. this.gameData.loginDays = res_data.loginDays;
  95. this.gameData.newPlayer = res_data.newPlayer;
  96. this.gameData.initPiggyBank(res_data.piggyBank);
  97. this.gameData.piggyBankCashTimes = res_data.piggyBankCashTimes;
  98. this.gameData.redMoney = res_data.redMoney == null ? 0 : res_data.redMoney;
  99. this.gameData.signInDay = res_data.signInDay;
  100. this.gameData.totalPiggyBankCashTimes = res_data.totalPiggyBankCashTimes;
  101. this.gameData.turntableTimes = res_data.turntableTimes;
  102. this.gameData.userTuCaoInfo = res_data.userTuCaoInfo;
  103. this.gameData.versioncfg = res_data.versioncfg;
  104. this.gameData.isFirstRedMoney = res_data.isFirstRedMoney;
  105. if (res_data.groupCode) {
  106. this.gameData.groupCode = res_data.groupCode;
  107. }
  108. console.log('ABTest ', res_data.groupCode);
  109. gData.adData.watchNumToday = res_data.dayVideoTimesForRedMoney == null ? 0 : res_data.dayVideoTimesForRedMoney;
  110. mk.data.setTAUserID(gData.loginData.uin);
  111. if (gData.loginData.isFirstIn) {
  112. gData.loginData.isFirstIn = false;
  113. mk.data.setTAEventRegister();
  114. mk.data.sendDataEvent('ABTest', `触发${this.gameData.groupCode}方案`);
  115. //星云uid
  116. mk.data.setTAEventUserStr(0, 'xy_uid', gData.loginData.uin);
  117. //注册时版本号
  118. mk.data.setTAEventUserStr(0, 'regtime_app_id', gData.appData.appVersion);
  119. //引导开关开启阶段注册的用户才保留此功能
  120. if (gData.guideToWxData.guideToWxSwith) {
  121. console.log('BBB aaa ');
  122. mk.storage.setStorage('canShowGuideToWx', '1');
  123. }
  124. }
  125. //当前版本号
  126. mk.data.setTAEventUserStr(0, 'now_app_id', gData.appData.appVersion);
  127. //渠道号
  128. mk.data.setTAEventUserStr(0, 'channel_id', gData.appData.umengChannel);
  129. gData.safeDepositBoxData.richBankCashAmount = res_data.richBankCashAmount;
  130. gData.safeDepositBoxData.currentRichBankCashTaskIndex = res_data.currentRichBankCashTaskIndex;
  131. gData.safeDepositBoxData.addRichBankFinishIndex = res_data.addRichBankFinishIndex;
  132. if (gData.safeDepositBoxData.currentRichBankCashTaskIndex > 0) {
  133. gData.safeDepositBoxData.addRichBankFinishIndex = gData.safeDepositBoxData.currentRichBankCashTaskIndex;
  134. }
  135. }
  136. /**
  137. * 保存单个数据
  138. */
  139. public async setProp(key: GameProp, value: number) {
  140. let data = {
  141. key: key + '',
  142. value: value + ''
  143. };
  144. this.props.set(key, value);
  145. await mk.http.sendData('savePlayerProp', data);
  146. this.savePropFinish = true;
  147. }
  148. /**
  149. * 保存多个数据
  150. */
  151. public async setProps(arr: { key: GameProp, value: number }[]) {
  152. let needProp = {};
  153. for (let i = 0; i < arr.length; i++) {
  154. needProp[arr[i].key + ''] = arr[i].value + "";
  155. }
  156. let data = {
  157. needProp: needProp
  158. };
  159. for (let i = 0; i < arr.length; i++) {
  160. this.props.set(arr[i].key, arr[i].value);
  161. }
  162. await mk.http.sendData('saveAllPlayerProp', data);
  163. this.savePropsFinish = true;
  164. }
  165. /** 获取属性 */
  166. public getProp(key: GameProp): number {
  167. if (this.props == null) {
  168. return 0;
  169. }
  170. let value = this.props.get(key);
  171. return value == null ? 0 : value;
  172. }
  173. /**
  174. * 向服务器请求所有属性后更新
  175. */
  176. public async getAllProps() {
  177. let response = await mk.http.sendData('getAllPlayerProp', {});
  178. if (response.errcode != 0) {
  179. return;
  180. }
  181. this.initProps(response.data);
  182. this.getPropsFnish = true;
  183. }
  184. private initProps(data) {
  185. if (data == null) {
  186. return;
  187. }
  188. for (let key in data) {
  189. this.props.set(parseInt(key), JSON.parse(data[key]));
  190. }
  191. }
  192. /**
  193. * 第二天需要重置的数据
  194. */
  195. public resetProps() {
  196. let arr = [];
  197. arr.push({ key: GameProp.sign_can, value: 1 });
  198. arr.push({ key: GameProp.isAutoOpenPanel, value: 1 });
  199. arr.push({ key: GameProp.isOpenBankOnCloseCash, value: 0 });
  200. this.setProps(arr);
  201. }
  202. /** 是否是新用户 */
  203. public isNewPlayer(): boolean {
  204. let v = this.getProp(GameProp.newPlayer);
  205. return v == 0;
  206. }
  207. }
  208. /**
  209. * 所有模块的非校验数据
  210. */
  211. export enum GameProp {
  212. /** -------------------- 通用玩家数据 ------------------------- */
  213. /** 是否新手 0新手 1老手 */
  214. newPlayer = 1,
  215. /** 当前新手引导步骤 */
  216. guideID = 2,
  217. /** 需要自动弹界面 每次登录都弹 除首次 表示今日是否要自动开 1自动开 2不自动开 其他不处理*/
  218. isAutoOpenPanel = 3,
  219. /** 关闭常规提现时需要自动开存钱罐 每天一次 表示今日有没有开过 */
  220. isOpenBankOnCloseCash = 4,
  221. //看视频次数
  222. videoTimes = 5,
  223. //提现次数
  224. cashTimes = 6,
  225. //引导到微信
  226. guideToWx = 7,
  227. /** ------------------ 游戏核心数据 --------------------------- */
  228. /** 关卡数 */
  229. levelNum = 10,
  230. /** 锤子道具数目 */
  231. hammerPropNum = 1001,
  232. /** 重设道具数目 */
  233. resetPropNum = 1002,
  234. /** 变色道具数目 */
  235. changePropNum = 1003,
  236. /** 当前总分 */
  237. curTotalScore = 11,
  238. /** ------------------ 转盘数据 ------------------------------ */
  239. turnable_leftTimes = 20,
  240. /** ------------------ 存钱罐数据 ----------------------------- */
  241. /** ------------------ 签到数据 ----------------------------- */
  242. /** 上次签到进度 */
  243. sign_last_bar = 120,
  244. /** 当前能否签到 */
  245. sign_can = 121,
  246. /** ------------------ 红包提现 ----------------------------- */
  247. /** 提现进度 */
  248. redBag_cash_bar = 220,
  249. }
  250. /**
  251. * 玩家数据
  252. */
  253. class PlayerProp {
  254. /** 自定义不需要校验的数据 */
  255. gameUserData = 0;
  256. _isSignInToday = 0;
  257. /**
  258. * 今日是否有签到
  259. * - 0 未签到,表示可以签到
  260. * - 1 有签到,表示不可签到
  261. */
  262. set isSignInToday(value: number) {
  263. this._isSignInToday = value;
  264. gData.sign.init_data = true;
  265. gData.gameData.init_red_point = true;
  266. }
  267. get isSignInToday(): number {
  268. return this._isSignInToday;
  269. }
  270. private _piggyBank: number = 0;
  271. /** 存钱罐存款 */
  272. set piggyBank(value: number) {
  273. if (this._piggyBank === value) return;
  274. if (gData.gameData.gameData.isWithdrawable && value > 0) return;// 存钱罐可提现状态,不能增加存钱罐金额
  275. this._piggyBank = value;
  276. gData.gameData.init_coin = true;
  277. gData.pigbank.init_data = true;
  278. gData.gameData.init_red_point = true;
  279. }
  280. get piggyBank(): number {
  281. return this._piggyBank;
  282. }
  283. /** 初始化 */
  284. initPiggyBank(v) {
  285. this._piggyBank = v;
  286. }
  287. _isWithdrawable = 0;
  288. /**
  289. * 存钱罐能否提现
  290. * - 0 不能提现
  291. * - 1 能提现
  292. */
  293. set isWithdrawable(value: number) {
  294. if (this._isWithdrawable != value) {
  295. this._isWithdrawable = value;
  296. gData.pigbank.init_data = true;
  297. gData.gameData.init_red_point = true;
  298. }
  299. }
  300. get isWithdrawable(): number {
  301. return this._isWithdrawable;
  302. }
  303. /** 存钱罐每日提现次数 */
  304. piggyBankCashTimes = 0;
  305. /** 累计存钱罐每日提现次数 */
  306. totalPiggyBankCashTimes = 0;
  307. /** 提现进度 */
  308. cashIndex = 0;
  309. /** 上次登录时间 */
  310. lastTime = 0;
  311. /** 登录天数 */
  312. loginDays = 0;
  313. newPlayer = 0;
  314. private _redMoney: number = 0;
  315. /** 红包币数量 */
  316. set redMoney(value: number) {
  317. this._redMoney = value;
  318. gData.gameData.init_coin = true;
  319. gData.gameData.init_red_point = true;
  320. //当前红包币
  321. mk.data.setTAEventUser(0, 'red_money_num', this._redMoney);
  322. }
  323. get redMoney(): number {
  324. return this._redMoney;
  325. }
  326. _signInDay = 0;
  327. /** 累计签到次数 客户端理解 上次签到天数 */
  328. set signInDay(value: number) {
  329. if (this._signInDay === value) return;
  330. this._signInDay = value;
  331. gData.sign.init_data = true;
  332. }
  333. get signInDay(): number {
  334. return this._signInDay;
  335. }
  336. /** 转盘次数 */
  337. turntableTimes = 0;
  338. /** 版本号 */
  339. versioncfg = 0;
  340. /** 福袋数据 */
  341. userTuCaoInfo = 0;
  342. /** 关卡数 */
  343. levelNum = 0;
  344. /** 锤子道具数目 */
  345. hammerPropNum = 0;
  346. /** 重设道具数目 */
  347. resetPropNum = 0;
  348. /** 变色道具数目 */
  349. changePropNum = 0;
  350. /** 能免费领红包 1 表示是新人第一次产出红包币,不用看视频*/
  351. isFirstRedMoney = 0;
  352. /** ABTest分组id */
  353. groupCode = 0;
  354. }
  355. /**
  356. * 奖励状态
  357. */
  358. export enum RewardState {
  359. /** 已领取 */
  360. none = 1,
  361. /** 未解锁 */
  362. lock = 2,
  363. /** 可领取 */
  364. unlock = 3
  365. }
  366. /**
  367. * 奖励类型
  368. */
  369. export enum RewardType {
  370. /** 红包币 */
  371. redBag = 1,
  372. /** 毛币 */
  373. rmb = 2,
  374. /** 金猪币 */
  375. pigRmb = 3,
  376. }
  377. /**
  378. * 音频路径
  379. */
  380. export enum AUDIO_TYPE {
  381. /**主界面背景音乐*/
  382. bgm = 'bgm',
  383. /**打开存钱罐界面播放一次*/
  384. pigBank = 'pigBank',
  385. /**关卡玩法背景音乐*/
  386. missionBg = 'missionBg',
  387. /**红包币领取界面关闭音效*/
  388. rewardClose = 'rewardClose',
  389. /**红包币领取界面开启音效*/
  390. rewardOpen = 'rewardOpen',
  391. /**红包界面打开音效*/
  392. reward = 'reward',
  393. /**提现到账界面打开播放一次*/
  394. receiptNotice = 'receiptNotice',
  395. /**通用按钮点击音效 */
  396. button = 'button',
  397. /**转盘转动音效*/
  398. turnableplay = 'turnableplay',
  399. /**转盘转动音效*/
  400. turnplateDrawEnd = 'turnplateDrawEnd',
  401. /**主页背景音乐 */
  402. music_startBg = "music_startBg",
  403. /**游戏背景音乐 */
  404. music_gameBg = "music_gameBg",
  405. /**按钮点击 */
  406. ef_button_click = "ef_button_click",
  407. /**红包打开 */
  408. ef_redPacket_open = "ef_redPacket_open",
  409. /**红包来了音效 */
  410. ef_redPacket_come = "ef_redPacket_come",
  411. /**消除4个 */
  412. ef_bonus4 = "ef_bonus4",
  413. /**消除5个 */
  414. ef_bonus5 = "ef_bonus5",
  415. /**消除6个 */
  416. ef_bonus6 = "ef_bonus6",
  417. /**消除7个 */
  418. ef_bonus7 = "ef_bonus7",
  419. /**消除8个 */
  420. ef_bonus8 = "ef_bonus8",
  421. /**普通消除音效 */
  422. ef_eliminate = "ef_eliminate",
  423. /**bouns消除音效 */
  424. ef_eliminate_bonus = "ef_eliminate_bonus",
  425. /**胜利音效 */
  426. ef_win = "ef_win",
  427. /**锤子 */
  428. ef_change = "ef_change",
  429. /**刷新 */
  430. ef_refresh = "ef_refresh",
  431. /**飞翔 */
  432. ef_fly = "ef_fly",
  433. /**存入银行成功*/
  434. saveSuccess = 'saveSuccess',
  435. }
  436. /** ECPM */
  437. type ADShowCfg = {
  438. average_ecpm: number,
  439. insert_probability: number,
  440. is_show_banner: number,
  441. is_show_inter: number,
  442. }
  443. /**事件类型 */
  444. export enum EVENT_TYPE {
  445. BACK_WxAuth = "BACK_WxAuth",
  446. UPDATE_CashNum = "UPDATE_CashNum",
  447. }
  448. /** 数据事件Id */
  449. export enum DataEventId {
  450. /** 点击 */
  451. guide = "guide",
  452. /** 点击跳过 */
  453. guideSkip = "guideSkip",
  454. /** 按钮点击 */
  455. button_click = "button_click",
  456. /** 看视频 */
  457. video_init = "video_init",
  458. /** 看视频完成 */
  459. video_end = "video_end",
  460. /** 福袋功能 */
  461. fudaiFunction = "fudaiFunction",
  462. /** 互推功能 */
  463. hutuiFunction = "hutuiFunction",
  464. /** 关卡 */
  465. level = "level",
  466. /** 常规提现-红包币提现 */
  467. commonWithDrawal = "commonWithDrawl",
  468. /** 存钱罐提现 */
  469. jarWithDrawal = "jarWithDrawal",
  470. /** 签到提现 */
  471. signWithDrawal = "signWithDrawal",
  472. /** 激励视频ecpm */
  473. ad_videoEcpm = 'ad_video',
  474. /** 开屏ecpm */
  475. ad_openEcpm = 'ad_open',
  476. /** 引导到微信 (加我送钱) */
  477. guideToWx = 'guideToWx',
  478. /** 广告点击 */
  479. ad_click = 'ad_click',
  480. }
  481. /** 视频广告类型 */
  482. export enum VideoAdType {
  483. Null = "",
  484. /** 关卡积分红包 */
  485. LevelScoreRedBag = "关卡消除红包",
  486. /** 主界面气泡红包 */
  487. StartQiPaoRedBag = "主界面气泡红包",
  488. /** 关卡气泡红包 */
  489. LevelQiPaoRedBag = "关卡气泡红包",
  490. /** 转盘 */
  491. Turntable = "转盘视频",
  492. /** 福袋视频" */
  493. Fudai = "福袋视频",
  494. /** 签到视频 */
  495. Sign = "签到视频"
  496. }