GameData.ts 17 KB

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