GameData.ts 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. import Game from "../game/Game";
  2. /**
  3. * @description 游戏核心玩法数据
  4. * @author 邹勇
  5. */
  6. export class GameData {
  7. public dataFinish: boolean = false;
  8. public savePropFinish: boolean = false;
  9. public savePropsFinish: boolean = false;
  10. public getPropsFnish: boolean = false;
  11. public configs: any = {};
  12. /** 功能开启 */
  13. public funOpenData:string[] = [];
  14. public gameData: PlayerInfoType;
  15. public props: Map<number, number>;
  16. public pools = [
  17. { url: "game/prefab/tips", num: 20 },
  18. { url: "game/prefab/coin", num: 20 }
  19. ];
  20. /** 主页样式脚本 */
  21. public gameStyle: Game = null;
  22. /**
  23. * 初始化游戏数据:网络配置信息,用户信息
  24. * @returns
  25. */
  26. public async init() {
  27. this.dataFinish = true;
  28. let data: any = { "versionCode": gData.appData.version };
  29. let response = await mk.http.sendData('getAllConfigInfo', data);
  30. if (response.errcode != 0) {
  31. if (response.errcode == -10003 || response.errcode == -20003) {
  32. //清除缓存
  33. gData.loginData.reload();
  34. }
  35. return;
  36. }
  37. this.initConfigs(response.data);
  38. data = {};
  39. response = await mk.http.sendData('getInfoCrypt', data);
  40. if (response.errcode != 0) {
  41. return;
  42. }
  43. this.gameData = response.data;
  44. if (this.props == null) {
  45. this.props = new Map<number, number>();
  46. }
  47. this.initProps(response.data.gameUserData);
  48. gData.moduleData.forEach(element => {
  49. element.init();
  50. });
  51. this.dataFinish = true;
  52. }
  53. private initConfigs(data){
  54. this.configs = data;
  55. this.funOpenData = this.configs.ServerConfig.Functionswitch.split(",");
  56. }
  57. /**
  58. * 保存单个数据
  59. */
  60. public async setProp(key: GameProp, value: number) {
  61. let data = {
  62. key: key + '',
  63. value: value + ''
  64. };
  65. await mk.http.sendData('savePlayerProp', data);
  66. // this.props.set(key, value);
  67. // this.savePropFinish = true;
  68. }
  69. /**
  70. * 保存多个数据
  71. */
  72. public async setProps(arr: { key: GameProp, value: number }[]) {
  73. let needProp = {};
  74. for (let i = 0; i < arr.length; i++) {
  75. needProp[arr[i].key + ''] = arr[i].value + "";
  76. }
  77. let data = {
  78. needProp: needProp
  79. };
  80. await mk.http.sendData('saveAllPlayerProp', data);
  81. for (let i = 0; i < arr.length; i++) {
  82. this.props.set(arr[i].key, arr[i].value);
  83. }
  84. this.savePropsFinish = true;
  85. }
  86. /** 获取属性 */
  87. public getProp(key: GameProp): number {
  88. if (this.props == null) {
  89. return 0;
  90. }
  91. let value = this.props.get(key);
  92. return value == null ? 0 : value;
  93. }
  94. /**
  95. * 向服务器请求所有属性后更新
  96. */
  97. public async getAllProps() {
  98. let response = await mk.http.sendData('getAllPlayerProp', {});
  99. if (response.errcode != 0) {
  100. return;
  101. }
  102. this.initProps(response.data);
  103. this.getPropsFnish = true;
  104. }
  105. private initProps(data) {
  106. if (data == null) {
  107. return;
  108. }
  109. for (let key in data) {
  110. this.props.set(parseInt(key), JSON.parse(data[key]));
  111. }
  112. }
  113. /**
  114. * 第二天需要重置的数据
  115. */
  116. public resetProps() {
  117. let arr = [];
  118. arr.push({ key: GameProp.sign_can, value: 1 });
  119. this.setProps(arr);
  120. }
  121. }
  122. /**
  123. * 所有模块的非校验数据
  124. */
  125. export enum GameProp {
  126. /** ------------------ 游戏核心数据 --------------------------- */
  127. /** ------------------ 转盘数据 ------------------------------ */
  128. turnable_leftTimes = 20,
  129. /** ------------------ 存钱罐数据 ----------------------------- */
  130. /** ------------------ 签到数据 ----------------------------- */
  131. /** 上次签到进度 */
  132. sign_last_bar = 120,
  133. /** 当前能否签到 */
  134. sign_can = 121,
  135. /** ------------------ 红包提现 ----------------------------- */
  136. /** 提现进度 */
  137. redBag_cash_bar = 220,
  138. }
  139. /**
  140. * 奖励状态
  141. */
  142. export enum RewardState {
  143. /** 已领取 */
  144. none = 1,
  145. /** 未解锁 */
  146. lock = 2,
  147. /** 可领取 */
  148. unlock = 3
  149. }
  150. /**
  151. * 奖励类型
  152. */
  153. export enum RewardType {
  154. /** 红包币 */
  155. redBag = 1,
  156. /** 毛币 */
  157. rmb = 2,
  158. /** 金猪币 */
  159. pigRmb = 3,
  160. }
  161. /**
  162. * 音频路径
  163. */
  164. export enum AUDIO_TYPE {
  165. /**主界面背景音乐*/
  166. bgm = 'bgm',
  167. /**打开存钱罐界面播放一次*/
  168. pigBank = 'pigBank',
  169. /**关卡玩法背景音乐*/
  170. missionBg = 'missionBg',
  171. /**红包币领取界面关闭音效*/
  172. rewardClose = 'rewardClose',
  173. /**红包币领取界面开启音效*/
  174. rewardOpen = 'rewardOpen',
  175. /**红包界面打开音效*/
  176. reward = 'reward',
  177. /**提现到账界面打开播放一次*/
  178. receiptNotice = 'receiptNotice',
  179. /**通用按钮点击音效 */
  180. button = 'button',
  181. /**转盘转动音效*/
  182. turnableplay = 'turnableplay',
  183. /**主页背景音乐 */
  184. music_startBg = "music_startBg",
  185. /**游戏背景音乐 */
  186. music_gameBg = "music_gameBg",
  187. /**按钮点击 */
  188. ef_button_click = "ef_button_click",
  189. /**红包打开 */
  190. ef_redPacket_open = "ef_redPacket_open",
  191. /**红包来了音效 */
  192. ef_redPacket_come = "ef_redPacket_come",
  193. /**消除4个 */
  194. ef_bonus4 = "ef_bonus4",
  195. /**消除5个 */
  196. ef_bonus5 = "ef_bonus5",
  197. /**消除6个 */
  198. ef_bonus6 = "ef_bonus6",
  199. /**消除7个 */
  200. ef_bonus7 = "ef_bonus7",
  201. /**消除8个 */
  202. ef_bonus8 = "ef_bonus8",
  203. /**普通消除音效 */
  204. ef_eliminate = "ef_eliminate",
  205. /**bouns消除音效 */
  206. ef_eliminate_bonus = "ef_eliminate_bonus",
  207. /**胜利音效 */
  208. ef_win = "ef_win",
  209. /**锤子 */
  210. ef_change = "ef_change",
  211. /**刷新 */
  212. ef_refresh = "ef_refresh",
  213. /**飞翔 */
  214. ef_fly = "ef_fly",
  215. }
  216. type PlayerInfoType = {
  217. /** 自定义不需要校验的数据 */
  218. gameUserData: object,
  219. /** 今日是否有签到 */
  220. isSignInToday: boolean,
  221. /** 存钱罐存款 */
  222. piggyBank: number,
  223. /** 存钱罐能否提现 */
  224. isWithdrawable: boolean,
  225. /** 存钱罐每日提现次数 */
  226. piggyBankCashTimes: number,
  227. /** 累计存钱罐每日提现次数 */
  228. totalPiggyBankCashTimes: number,
  229. /** 提现进度 */
  230. cashIndex: number,
  231. /** 上次登录时间 */
  232. lastTime: number,
  233. /** 登录天数 */
  234. loginDays: number,
  235. newPlayer: Boolean,
  236. /** 红包币数量 */
  237. redMoney: number,
  238. /** 累计签到次数 客户端理解 上次签到天数 */
  239. signInDay: number,
  240. /** 转盘次数 */
  241. turntableTimes: number,
  242. /** 版本号 */
  243. versioncfg: string,
  244. /** 福袋数据 */
  245. userTuCaoInfo: object,
  246. }
  247. /**事件类型 */
  248. export enum EVENT_TYPE {
  249. BACK_WxAuth = "BACK_WxAuth",
  250. UPDATE_CashNum = "UPDATE_CashNum",
  251. }