0b76f39b-b4de-4538-acd2-aef17716b729.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. "use strict";
  2. cc._RF.push(module, '0b76fObtN5FOKzSrvF3Frcp', 'DataMgr');
  3. // scripts/Framework/DataMgr.ts
  4. "use strict";
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. var weapon_1 = require("../Game/weapon");
  7. var Constant_1 = require("./Constant");
  8. /**
  9. * 数据管理类
  10. */
  11. var DataMgr = /** @class */ (function () {
  12. function DataMgr() {
  13. this._dataPool = {};
  14. }
  15. Object.defineProperty(DataMgr, "inst", {
  16. get: function () {
  17. if (!DataMgr._inst) {
  18. DataMgr._inst = new DataMgr();
  19. }
  20. return DataMgr._inst;
  21. },
  22. enumerable: false,
  23. configurable: true
  24. });
  25. DataMgr.prototype.init = function () {
  26. // cc.sys.localStorage.clear();
  27. if (cc.sys.localStorage.getItem(Constant_1.default.ST_GameData)) {
  28. this._dataPool = JSON.parse(cc.sys.localStorage.getItem(Constant_1.default.ST_GameData));
  29. }
  30. else {
  31. // 初始金币
  32. this._dataPool[Constant_1.default.ST_CoinCount] = "1000";
  33. // 初始钻石
  34. this._dataPool[Constant_1.default.ST_DiamondCount] = "0";
  35. //初始化皮肤
  36. this._dataPool[Constant_1.default.ST_CurSkinId] = "0";
  37. //初始化武器
  38. this._dataPool[Constant_1.default.ST_CurMeleeId] = "13";
  39. this._dataPool[Constant_1.default.ST_CurRangeId] = "0";
  40. //初始签到信息
  41. this._dataPool[Constant_1.default.ST_LastDailyBonusIndex] = "-1";
  42. this._dataPool[Constant_1.default.ST_LastDailyBonusTime] = "0";
  43. //初始化关卡信息
  44. this._initLevelData();
  45. // 初始化皮肤数据
  46. this._initSkinData();
  47. //初始化枪械数据
  48. this._initGunData();
  49. this._save();
  50. }
  51. };
  52. /**
  53. * 初始化关卡信息
  54. */
  55. DataMgr.prototype._initLevelData = function () {
  56. "";
  57. var levelItemObj = {};
  58. // 简单
  59. var levelitem = new Constant_1.Levelitem("{\"Id\":\"" + 1001 + "\",\"State\":\"" + 1 + "\",\"Grade\":\"0\"}");
  60. levelItemObj["1001"] = levelitem;
  61. for (var i = 1002; i <= 1000 + Constant_1.default.CT_TotalLevelCount; i++) {
  62. var levelitem_1 = new Constant_1.Levelitem("{\"Id\":\"" + i + "\",\"State\":\"" + 0 + "\",\"Grade\":\"0\"}");
  63. levelItemObj[i.toString()] = levelitem_1;
  64. }
  65. // 困难
  66. for (var i = 2001; i <= 2000 + Constant_1.default.CT_TotalLevelCount; i++) {
  67. var levelitem_2 = new Constant_1.Levelitem("{\"Id\":\"" + i + "\",\"State\":\"" + 0 + "\",\"Grade\":\"0\"}");
  68. levelItemObj[i.toString()] = levelitem_2;
  69. }
  70. // 英雄
  71. for (var i = 3001; i <= 3000 + Constant_1.default.CT_TotalLevelCount; i++) {
  72. var levelitem_3 = new Constant_1.Levelitem("{\"Id\":\"" + i + "\",\"State\":\"" + 0 + "\",\"Grade\":\"0\"}");
  73. levelItemObj[i.toString()] = levelitem_3;
  74. }
  75. this._dataPool[Constant_1.default.ST_LevelItem] = JSON.stringify(levelItemObj);
  76. };
  77. DataMgr.prototype._initSkinData = function () {
  78. // 皮肤数据读表
  79. var price = [0, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000];
  80. var skinInfoArr = [];
  81. var skinInfo = new Constant_1.SkinInfo("{\"Id\":\"" + 0 + "\",\"State\":\"2\",\"Price\":\"" + price[0] + "\",\"Level\":\"0\",\"VideoCount\":\"0\"}");
  82. skinInfoArr.push(skinInfo);
  83. for (var i = 1; i < price.length; i++) {
  84. var skinInfo_1 = new Constant_1.SkinInfo("{\"Id\":\"" + i + "\",\"State\":\"0\",\"Price\":\"" + price[i] + "\",\"Level\":\"0\",\"VideoCount\":\"0\"}");
  85. skinInfoArr.push(skinInfo_1);
  86. }
  87. this._dataPool[Constant_1.default.ST_SkinInfo] = JSON.stringify(skinInfoArr);
  88. };
  89. DataMgr.prototype._initGunData = function () {
  90. // 武器数据读表
  91. var price = [
  92. 0, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000,
  93. 1000, 1000, 1000, 0, 1000, 1000, 1000, 1000, 1000, 1000,
  94. 1000, 1000, 1000, 1000, 1000
  95. ];
  96. var gunInfoArr = [];
  97. for (var i = 0; i < price.length; i++) {
  98. var gunInfo = null;
  99. if (i == 0 || i == 13) {
  100. gunInfo = new Constant_1.GunInfo("{\"Id\":\"" + i + "\",\"State\":\"2\",\"Price\":\"" + price[i] + "\",\"Level\":\"0\",\"VideoCount\":\"0\"}");
  101. }
  102. else {
  103. gunInfo = new Constant_1.GunInfo("{\"Id\":\"" + i + "\",\"State\":\"0\",\"Price\":\"" + price[i] + "\",\"Level\":\"0\",\"VideoCount\":\"0\"}");
  104. }
  105. gunInfoArr.push(gunInfo);
  106. }
  107. this._dataPool[Constant_1.default.ST_GunInfo] = JSON.stringify(gunInfoArr);
  108. };
  109. Object.defineProperty(DataMgr.prototype, "AudioOn", {
  110. //////////////////////////////////////////////////// 当前使用
  111. /** 声音开关 */
  112. get: function () {
  113. return this.getItem(Constant_1.default.ST_AudioOn, "1") == "1";
  114. },
  115. set: function (value) {
  116. this.setItem(Constant_1.default.ST_AudioOn, value ? "1" : "0");
  117. },
  118. enumerable: false,
  119. configurable: true
  120. });
  121. Object.defineProperty(DataMgr.prototype, "ShakeOn", {
  122. /** 震动开关 */
  123. get: function () {
  124. return this.getItem(Constant_1.default.ST_ShakeOn, "1") == "1";
  125. },
  126. set: function (value) {
  127. this.setItem(Constant_1.default.ST_ShakeOn, value ? "1" : "0");
  128. },
  129. enumerable: false,
  130. configurable: true
  131. });
  132. Object.defineProperty(DataMgr.prototype, "CoinCount", {
  133. /** 金币数据 */
  134. get: function () {
  135. return parseInt(this.getItem(Constant_1.default.ST_CoinCount, "0"));
  136. },
  137. set: function (value) {
  138. this.setItem(Constant_1.default.ST_CoinCount, value + "");
  139. cc.game.emit(Constant_1.default.E_GAME_LOGIC, { type: Constant_1.default.E_COIN_CHANGE });
  140. },
  141. enumerable: false,
  142. configurable: true
  143. });
  144. Object.defineProperty(DataMgr.prototype, "DiamondCount", {
  145. /** 取钻石数据 */
  146. get: function () {
  147. return parseInt(this.getItem(Constant_1.default.ST_DiamondCount, "0"));
  148. },
  149. set: function (value) {
  150. this.setItem(Constant_1.default.ST_DiamondCount, value + "");
  151. cc.game.emit(Constant_1.default.E_GAME_LOGIC, { type: Constant_1.default.E_Diamond_CHANGE });
  152. },
  153. enumerable: false,
  154. configurable: true
  155. });
  156. Object.defineProperty(DataMgr.prototype, "TotoalCount_6", {
  157. /** 总局数_割草模式 */
  158. get: function () {
  159. return parseInt(this.getItem(Constant_1.default.ST_TotoalCount + "6", "1"));
  160. },
  161. set: function (value) {
  162. this.setItem(Constant_1.default.ST_TotoalCount + "6", value + "");
  163. },
  164. enumerable: false,
  165. configurable: true
  166. });
  167. Object.defineProperty(DataMgr.prototype, "LastDailyBonusIndex", {
  168. /** 最后奖励的天数 */
  169. get: function () {
  170. return parseInt(this.getItem(Constant_1.default.ST_LastDailyBonusIndex, "-1"));
  171. },
  172. set: function (value) {
  173. this.setItem(Constant_1.default.ST_LastDailyBonusIndex, value + "");
  174. },
  175. enumerable: false,
  176. configurable: true
  177. });
  178. Object.defineProperty(DataMgr.prototype, "LastDailyBonusTime", {
  179. /** 最后一次签到的时间 */
  180. get: function () {
  181. return this.getItem(Constant_1.default.ST_LastDailyBonusTime, "0");
  182. },
  183. set: function (value) {
  184. this.setItem(Constant_1.default.ST_LastDailyBonusTime, value + "");
  185. },
  186. enumerable: false,
  187. configurable: true
  188. });
  189. Object.defineProperty(DataMgr.prototype, "LastLoadDate", {
  190. /** 加载游戏日期 */
  191. get: function () {
  192. return this.getItem(Constant_1.default.ST_LastLoadDate, "");
  193. },
  194. set: function (v) {
  195. this.setItem(Constant_1.default.ST_LastLoadDate, v);
  196. },
  197. enumerable: false,
  198. configurable: true
  199. });
  200. Object.defineProperty(DataMgr.prototype, "OnlineToday", {
  201. /** 今日在线时间 */
  202. get: function () {
  203. return parseInt(this.getItem(Constant_1.default.ST_OnlineToday, "0"));
  204. },
  205. set: function (v) {
  206. this.setItem(Constant_1.default.ST_OnlineToday, v + "");
  207. },
  208. enumerable: false,
  209. configurable: true
  210. });
  211. Object.defineProperty(DataMgr.prototype, "receiveToday", {
  212. /** 今日在线奖励领取数量 */
  213. get: function () {
  214. return JSON.parse(this.getItem(Constant_1.default.ST_ReceiveToday, "[0, 0, 0, 0, 0]"));
  215. },
  216. set: function (v) {
  217. this.setItem(Constant_1.default.ST_ReceiveToday, JSON.stringify(v));
  218. },
  219. enumerable: false,
  220. configurable: true
  221. });
  222. Object.defineProperty(DataMgr.prototype, "CurSkinId", {
  223. /**
  224. * 当前皮肤ID
  225. */
  226. get: function () {
  227. return parseInt(this.getItem(Constant_1.default.ST_CurSkinId, "0"));
  228. },
  229. /**
  230. * 设置当前皮肤ID
  231. */
  232. set: function (value) {
  233. if (value == this.CurSkinId) {
  234. return;
  235. }
  236. var preId = this.CurSkinId;
  237. var skinInfo = this.getSkinInfo(preId);
  238. if (skinInfo) {
  239. skinInfo.State = 1;
  240. this.setSkinInfo(preId, skinInfo);
  241. }
  242. var curSkinInfo = this.getSkinInfo(value);
  243. if (curSkinInfo) {
  244. curSkinInfo.State = 2;
  245. this.setSkinInfo(value, curSkinInfo);
  246. }
  247. this.setItem(Constant_1.default.ST_CurSkinId, value + "");
  248. },
  249. enumerable: false,
  250. configurable: true
  251. });
  252. /**
  253. * 获取皮肤信息
  254. * @param id 皮肤ID
  255. */
  256. DataMgr.prototype.getSkinInfo = function (id) {
  257. var skinInfos = this.getItem(Constant_1.default.ST_SkinInfo, "");
  258. if (skinInfos) {
  259. var skinInfoArr = JSON.parse(skinInfos);
  260. if (id >= 0 && id < skinInfoArr.length) {
  261. return skinInfoArr[id];
  262. }
  263. }
  264. return null;
  265. };
  266. /**
  267. * 保存皮肤信息
  268. * @param id 皮肤ID
  269. * @param info 皮肤信息
  270. */
  271. DataMgr.prototype.setSkinInfo = function (id, info) {
  272. var skinInfos = this.getItem(Constant_1.default.ST_SkinInfo, "");
  273. if (skinInfos) {
  274. var skinInfoArr = JSON.parse(skinInfos);
  275. if (id >= 0 && id < skinInfoArr.length) {
  276. skinInfoArr[id] = info;
  277. this.setItem(Constant_1.default.ST_SkinInfo, JSON.stringify(skinInfoArr));
  278. }
  279. }
  280. };
  281. /**
  282. * 随机获取3个未解锁的皮肤id
  283. */
  284. DataMgr.prototype.getRandomLockSkin = function () {
  285. var ids = [];
  286. var skinInfos = this.getItem(Constant_1.default.ST_SkinInfo, "");
  287. if (skinInfos) {
  288. var skinInfoArr = JSON.parse(skinInfos);
  289. for (var i = 0; i < skinInfoArr.length; i++) {
  290. if (skinInfoArr[i].State == 0) {
  291. ids.push(skinInfoArr[i].Id);
  292. }
  293. }
  294. }
  295. return ids;
  296. };
  297. /**
  298. * 获取武器信息
  299. * @param id 武器ID
  300. */
  301. DataMgr.prototype.getGunInfo = function (id) {
  302. var gunInfos = this.getItem(Constant_1.default.ST_GunInfo, "");
  303. if (gunInfos) {
  304. var gunInfoArr = JSON.parse(gunInfos);
  305. if (id >= 0 && id < gunInfoArr.length) {
  306. return gunInfoArr[id];
  307. }
  308. }
  309. return null;
  310. };
  311. /**
  312. * 保存武器信息
  313. * @param id 皮肤ID
  314. * @param info 皮肤信息
  315. */
  316. DataMgr.prototype.setGunInfo = function (id, info) {
  317. var gunInfos = this.getItem(Constant_1.default.ST_GunInfo, "");
  318. if (gunInfos) {
  319. var gunInfoArr = JSON.parse(gunInfos);
  320. if (id >= 0 && id < gunInfoArr.length) {
  321. gunInfoArr[id] = info;
  322. this.setItem(Constant_1.default.ST_GunInfo, JSON.stringify(gunInfoArr));
  323. }
  324. }
  325. };
  326. Object.defineProperty(DataMgr.prototype, "CurMelee", {
  327. /**
  328. * 当前近战武器
  329. */
  330. get: function () {
  331. return parseInt(this.getItem(Constant_1.default.ST_CurMeleeId, "13"));
  332. },
  333. set: function (id) {
  334. if (id == this.CurMelee || !weapon_1.default.meleeWaapon.includes(id + 1)) {
  335. return;
  336. }
  337. var preId = this.CurMelee;
  338. var gunInfo = this.getGunInfo(preId);
  339. if (gunInfo) {
  340. gunInfo.State = 1;
  341. this.setGunInfo(preId, gunInfo);
  342. }
  343. var curGunInfo = this.getGunInfo(id);
  344. if (curGunInfo) {
  345. curGunInfo.State = 2;
  346. this.setGunInfo(id, curGunInfo);
  347. }
  348. this.setItem(Constant_1.default.ST_CurMeleeId, id + "");
  349. },
  350. enumerable: false,
  351. configurable: true
  352. });
  353. Object.defineProperty(DataMgr.prototype, "CurRange", {
  354. /**
  355. * 当前远程武器
  356. */
  357. get: function () {
  358. return parseInt(this.getItem(Constant_1.default.ST_CurRangeId, "0"));
  359. },
  360. set: function (id) {
  361. if (id == this.CurRange || !weapon_1.default.rangeWeapon.includes(id + 1)) {
  362. return;
  363. }
  364. var preId = this.CurRange;
  365. var gunInfo = this.getGunInfo(preId);
  366. if (gunInfo) {
  367. gunInfo.State = 1;
  368. this.setGunInfo(preId, gunInfo);
  369. }
  370. var curGunInfo = this.getGunInfo(id);
  371. if (curGunInfo) {
  372. curGunInfo.State = 2;
  373. this.setGunInfo(id, curGunInfo);
  374. }
  375. this.setItem(Constant_1.default.ST_CurRangeId, id + "");
  376. },
  377. enumerable: false,
  378. configurable: true
  379. });
  380. Object.defineProperty(DataMgr.prototype, "curWeapon", {
  381. get: function () {
  382. return this.CurRange;
  383. },
  384. set: function (id) {
  385. if (weapon_1.default.meleeWaapon.includes(id + 1)) {
  386. this.CurMelee = id;
  387. }
  388. else if (weapon_1.default.rangeWeapon.includes(id + 1)) {
  389. this.CurRange = id;
  390. }
  391. },
  392. enumerable: false,
  393. configurable: true
  394. });
  395. Object.defineProperty(DataMgr.prototype, "guide_skill", {
  396. /** 技能指引 */
  397. get: function () {
  398. return this.getItem(Constant_1.default.ST_Guide_Skill, true);
  399. },
  400. /** 技能指引 */
  401. set: function (value) {
  402. this.setItem(Constant_1.default.ST_Guide_Skill, value);
  403. cc.game.emit(Constant_1.default.E_ShareOrVideo);
  404. },
  405. enumerable: false,
  406. configurable: true
  407. });
  408. Object.defineProperty(DataMgr.prototype, "best_time", {
  409. ///////////////// 历史最佳 //////////////////////
  410. // 游戏时间
  411. get: function () {
  412. return parseInt(this.getItem("best_time", "0"));
  413. },
  414. set: function (v) {
  415. if (v > this.best_time) {
  416. this.setItem("best_time", v + "");
  417. }
  418. },
  419. enumerable: false,
  420. configurable: true
  421. });
  422. Object.defineProperty(DataMgr.prototype, "best_kill", {
  423. // 击杀数
  424. get: function () {
  425. return parseInt(this.getItem("best_kill", "0"));
  426. },
  427. set: function (v) {
  428. if (v > this.best_kill) {
  429. this.setItem("best_kill", v + "");
  430. }
  431. },
  432. enumerable: false,
  433. configurable: true
  434. });
  435. Object.defineProperty(DataMgr.prototype, "best_level", {
  436. // 等级
  437. get: function () {
  438. return parseInt(this.getItem("best_level", "0"));
  439. },
  440. set: function (v) {
  441. if (v > this.best_level) {
  442. this.setItem("best_level", v + "");
  443. }
  444. },
  445. enumerable: false,
  446. configurable: true
  447. });
  448. Object.defineProperty(DataMgr.prototype, "best_coin", {
  449. // 金币
  450. get: function () {
  451. return parseInt(this.getItem("best_coin", "0"));
  452. },
  453. set: function (v) {
  454. if (v > this.best_coin) {
  455. this.setItem("best_coin", v + "");
  456. }
  457. },
  458. enumerable: false,
  459. configurable: true
  460. });
  461. Object.defineProperty(DataMgr.prototype, "shareNum", {
  462. // 分享次数
  463. get: function () {
  464. return this.getItem(Constant_1.default.ST_ShareNum, 0);
  465. },
  466. set: function (v) {
  467. this.setItem(Constant_1.default.ST_ShareNum, v);
  468. // 发送事件更新图标
  469. cc.game.emit(Constant_1.default.E_ShareOrVideo);
  470. cc.log("今日分享了", v, "次");
  471. },
  472. enumerable: false,
  473. configurable: true
  474. });
  475. ////////////////////////////////////////////////////////////////////////////////
  476. DataMgr.prototype.getItem = function (key, defaultValue) {
  477. if (this._dataPool[key] != undefined && this._dataPool[key] != null) {
  478. return this._dataPool[key];
  479. }
  480. return defaultValue;
  481. };
  482. DataMgr.prototype.setItem = function (key, value) {
  483. this._dataPool[key] = value;
  484. this._save();
  485. };
  486. DataMgr.prototype._save = function () {
  487. cc.sys.localStorage.setItem(Constant_1.default.ST_GameData, JSON.stringify(this._dataPool));
  488. };
  489. return DataMgr;
  490. }());
  491. exports.default = DataMgr;
  492. cc._RF.pop();