GameData.ts 15 KB

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