GameData.ts 16 KB

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