GameData.ts 16 KB

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