GameData.ts 16 KB

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