GameData.ts 17 KB

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