6f4547a8-3dc0-41e3-90dc-e61f7bc48665.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. "use strict";
  2. cc._RF.push(module, '6f454eoPcBB45Dc5h97xIZl', 'DataManager');
  3. // Script/Framework/Manager/DataManager.ts
  4. "use strict";
  5. var __extends = (this && this.__extends) || (function () {
  6. var extendStatics = function (d, b) {
  7. extendStatics = Object.setPrototypeOf ||
  8. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  9. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  10. return extendStatics(d, b);
  11. };
  12. return function (d, b) {
  13. extendStatics(d, b);
  14. function __() { this.constructor = d; }
  15. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  16. };
  17. })();
  18. Object.defineProperty(exports, "__esModule", { value: true });
  19. exports.DataManager = void 0;
  20. var Singleton_1 = require("../Utils/Singleton");
  21. var App_1 = require("../../Manager/App");
  22. var TimeControl_1 = require("../../TimeControl");
  23. var hallModel_1 = require("../../model/hallModel");
  24. /**
  25. * 数据管理器
  26. */
  27. var DataManager = /** @class */ (function (_super) {
  28. __extends(DataManager, _super);
  29. function DataManager() {
  30. var _this = _super.call(this) || this;
  31. // /** 免费视频总次数 */
  32. // public FREE_WATCH_TIMES: number = 10;
  33. /**已有皮肤数组 */
  34. _this.GetSkins = ['niao1'];
  35. /**当前穿戴皮肤 */
  36. _this.DressingSkin = 'niao1';
  37. /**用户金币*/
  38. _this.UserCoin = 0;
  39. _this.UserDiamond = 0;
  40. /**通关进度 2表示通过了第一关,当前关卡为2, 3表示通过了第2关,当前关卡为3, */
  41. _this.PassProgress = { "1": 1 };
  42. /**30关后随机关卡存储 保证只随机一次 */
  43. _this.InfiniteLevelDate = {};
  44. /**玩家已经玩到的关卡*/
  45. _this.PlayLevel = 1;
  46. /**点击关卡号进入的关卡*/
  47. _this.CurrentIntoLevel = 1;
  48. /**关卡数据*/
  49. _this.Configs = [];
  50. /**看视频得体力数*/
  51. _this.VideoAddTili = 10;
  52. /**看视频得金币数*/
  53. _this.VideoAddCoin = 500;
  54. /**总关卡数*/
  55. _this.LevelCount = 15;
  56. /**重玩标志 */
  57. _this.resetFlag = false;
  58. /**重玩关卡*/
  59. _this.resetLevel = 0;
  60. /**重玩关卡*/
  61. _this.resetLevelBgIndex = 0;
  62. _this.guideStep = 0;
  63. // 关卡钻石数量
  64. _this.diamondNum = [
  65. [1, 1, 1],
  66. [1, 1, 1],
  67. [1, 1, 1],
  68. [1, 1, 1],
  69. [1, 1, 1],
  70. [1, 1, 1],
  71. [1, 1, 1],
  72. [1, 1, 1],
  73. [1, 1, 1],
  74. [1, 1, 1],
  75. [1, 1, 1],
  76. [1, 1, 1],
  77. [1, 1, 1],
  78. [1, 1, 1],
  79. [1, 1, 1],
  80. ];
  81. // 钥匙的位置
  82. _this.keyPos = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3];
  83. _this.foodLevel = [0, 0, 0, 0, 0, 0];
  84. _this.kinchenLevel = [0, 0, 0];
  85. _this.maxFoodLevel = 2;
  86. _this.maxKitchenLevel = 2;
  87. //升级食物需要的金币
  88. _this.upgradeFoodCoin = [
  89. [500, 1000],
  90. [630, 1200],
  91. [550, 860],
  92. [520, 800],
  93. [500, 600],
  94. [870, 1000],
  95. ];
  96. // 食物升级之后售价
  97. _this.foodSoldCoin = [
  98. [5, 8, 11],
  99. [6, 9, 12],
  100. [3, 5, 10],
  101. [4, 6, 10],
  102. [1, 2, 3],
  103. [3, 4, 5],
  104. ];
  105. // 升级厨具需要的金币
  106. _this.upgradeKitchenCoin = [
  107. [500, 1000],
  108. [500, 1000],
  109. [1000, 1500],
  110. ];
  111. // 餐具数量
  112. _this.kitchenNum = [
  113. [2, 3, 4],
  114. [2, 3, 4],
  115. [1, 2, 3],
  116. ];
  117. _this.dirnkMachinTime = [4, 3, 2];
  118. // 食物搭配种类
  119. _this.levelFoodKind = [
  120. 3, 3, 4, 4, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  121. ];
  122. _this.personCount = [
  123. [6, 9, 12],
  124. [7, 10, 13],
  125. [8, 11, 14],
  126. [9, 12, 15],
  127. [10, 13, 16],
  128. [11, 14, 17],
  129. [12, 15, 18],
  130. [13, 16, 19],
  131. [14, 17, 20],
  132. [15, 18, 21],
  133. [16, 19, 22],
  134. [17, 20, 23],
  135. [18, 21, 24],
  136. [19, 22, 25],
  137. [20, 23, 26],
  138. ];
  139. _this.RandomLevelList = [
  140. {
  141. startLevel: 11,
  142. endLevel: 15
  143. },
  144. {
  145. startLevel: 16,
  146. endLevel: 20
  147. },
  148. {
  149. startLevel: 21,
  150. endLevel: 25
  151. },
  152. {
  153. startLevel: 26,
  154. endLevel: 30
  155. }
  156. ];
  157. _this.particleColorList = {
  158. 'niao1': {
  159. startColor: new cc.Color(12, 166, 249, 255),
  160. endColor: new cc.Color(5, 223, 255, 255)
  161. },
  162. };
  163. // 道具数量
  164. _this.PropNum = [0, 0, 0, 0, 0];
  165. _this.propPrice = [1800, 1500, 1700, 1250, 2300];
  166. /**变小道具持续时间*/
  167. _this.SmallTime = 5;
  168. /**已加载预设组*/
  169. _this.PropPrefabs = [];
  170. /**倒计时标志*/
  171. _this.TimeFlag = false;
  172. /**获得新皮肤标志 */
  173. _this.GetNewSkinFlag = false;
  174. _this.NewSkinName = "";
  175. // public MissionName = ["制作%d个牛排", "卖出饮料%d杯", "招待%d个顾客", "获得%d颗星星"];
  176. _this.MissionName = ["Make %d steaks", "Sell drinks %d cups", "Serve %d customers", "Earn %d stars"];
  177. _this.MissionComplete = [0, 0, 0, 0]; // soldSteakNum,soldDrinkNum,solCustomerNum,getStarNum;
  178. _this.MissionReceive = [0, 0, 0, 0];
  179. /**皮肤设置 */
  180. _this.SkinDataList = [
  181. {
  182. name: 'niao1',
  183. path: 'skin/niao1'
  184. },
  185. ];
  186. /**任务设置 */
  187. _this.MissionDataList = [
  188. {
  189. missonNum: [5, 10, 20, 30, 40, 50, 60],
  190. rewardCoin: [100, 200, 300, 400, 500, 600, 700],
  191. rewardDiamon: [10, 20, 30, 40, 50, 60, 70],
  192. },
  193. {
  194. missonNum: [5, 10, 15, 20, 30, 40, 50],
  195. rewardCoin: [100, 200, 300, 400, 500, 600, 700],
  196. rewardDiamon: [10, 20, 30, 40, 50, 60, 70],
  197. },
  198. {
  199. missonNum: [5, 10, 20, 30, 40, 50, 60, 1000],
  200. rewardCoin: [100, 200, 300, 400, 500, 600, 700],
  201. rewardDiamon: [10, 20, 30, 40, 50, 60, 70],
  202. },
  203. {
  204. missonNum: [9, 18, 27, 36, 45, 54, 63, 72, 81],
  205. rewardCoin: [100, 200, 300, 400, 500, 600, 700],
  206. rewardDiamon: [10, 20, 30, 40, 50, 60, 70],
  207. },
  208. ];
  209. return _this;
  210. }
  211. DataManager.prototype.init = function () {
  212. var _this = this;
  213. console.log("初始化用户数据");
  214. this.initSkinData();
  215. cc.game.on(cc.game.EVENT_SHOW, function () {
  216. _this.OnShow();
  217. console.log('进入游戏&&&&&&&&&&&&&&');
  218. });
  219. cc.game.on(cc.game.EVENT_HIDE, function () {
  220. _this.OnHide();
  221. console.log('退出游戏&&&&&&&&&&&&&&');
  222. });
  223. this.iniLevelData();
  224. this.initUserCoin();
  225. this.initUserDiamond();
  226. };
  227. DataManager.prototype.iniLevelData = function () {
  228. var playLevel = App_1.App.LocalStorageUtil.getNumber(App_1.App.LocalStorageUtil.lst_playLevel);
  229. if (!playLevel)
  230. App_1.App.LocalStorageUtil.setNumber(App_1.App.LocalStorageUtil.lst_playLevel, this.PlayLevel);
  231. else
  232. this.PlayLevel = playLevel;
  233. var passProgress = App_1.App.LocalStorageUtil.getJsonObj(App_1.App.LocalStorageUtil.lst_passProgress);
  234. if (!passProgress)
  235. App_1.App.LocalStorageUtil.setJsonObj(App_1.App.LocalStorageUtil.lst_passProgress, this.PassProgress);
  236. else
  237. this.PassProgress = passProgress;
  238. console.log('通关进度:', this.PassProgress);
  239. // let infiniteLevelDate = App.LocalStorageUtil.getJsonObj(App.LocalStorageUtil.lst_InfiniteLevelDate);
  240. // if (!infiniteLevelDate) App.LocalStorageUtil.setJsonObj(App.LocalStorageUtil.lst_InfiniteLevelDate, this.InfiniteLevelDate);
  241. // else this.InfiniteLevelDate = infiniteLevelDate;
  242. // console.log('30关后随机关卡存储:', this.InfiniteLevelDate);
  243. // 食物等级
  244. var fLevel = App_1.App.LocalStorageUtil.getJsonObj(App_1.App.LocalStorageUtil.list_foodLevel);
  245. if (!fLevel)
  246. App_1.App.LocalStorageUtil.setJsonObj(App_1.App.LocalStorageUtil.list_foodLevel, this.foodLevel);
  247. else
  248. this.foodLevel = fLevel;
  249. // 厨具等级
  250. var kChenLevel = App_1.App.LocalStorageUtil.getJsonObj(App_1.App.LocalStorageUtil.list_kitchenLevel);
  251. if (!kChenLevel)
  252. App_1.App.LocalStorageUtil.setJsonObj(App_1.App.LocalStorageUtil.list_kitchenLevel, this.kinchenLevel);
  253. else
  254. this.kinchenLevel = kChenLevel;
  255. // 任务完成进度
  256. var missionComplete = App_1.App.LocalStorageUtil.getJsonObj(App_1.App.LocalStorageUtil.list_missionComplete);
  257. if (!missionComplete)
  258. App_1.App.LocalStorageUtil.setJsonObj(App_1.App.LocalStorageUtil.list_missionComplete, this.MissionComplete);
  259. else
  260. this.MissionComplete = missionComplete;
  261. console.log('aaa--------missionComplete-----------', missionComplete);
  262. // 任务奖励领取进度
  263. var missionReceive = App_1.App.LocalStorageUtil.getJsonObj(App_1.App.LocalStorageUtil.list_missionReceive);
  264. if (!missionReceive)
  265. App_1.App.LocalStorageUtil.setJsonObj(App_1.App.LocalStorageUtil.list_missionReceive, this.MissionReceive);
  266. else
  267. this.MissionReceive = missionReceive;
  268. console.log('aaa--------missionReceive-----------', missionReceive);
  269. var guidei = App_1.App.LocalStorageUtil.getNumber(App_1.App.LocalStorageUtil.str_guideStep);
  270. if (!guidei)
  271. App_1.App.LocalStorageUtil.setNumber(App_1.App.LocalStorageUtil.str_guideStep, this.guideStep);
  272. else
  273. this.guideStep = Number(guidei);
  274. };
  275. DataManager.prototype.initUserCoin = function () {
  276. var coin = App_1.App.LocalStorageUtil.getNumber(App_1.App.LocalStorageUtil.lst_Coin);
  277. if (!coin)
  278. App_1.App.LocalStorageUtil.setNumber(App_1.App.LocalStorageUtil.lst_Coin, this.UserCoin);
  279. else
  280. this.UserCoin = Number(coin);
  281. };
  282. DataManager.prototype.initUserDiamond = function () {
  283. var diamond = App_1.App.LocalStorageUtil.getNumber(App_1.App.LocalStorageUtil.lst_UserDiamond);
  284. if (!diamond)
  285. App_1.App.LocalStorageUtil.setNumber(App_1.App.LocalStorageUtil.lst_UserDiamond, this.UserDiamond);
  286. else
  287. this.UserDiamond = Number(diamond);
  288. };
  289. DataManager.prototype.SaveMessage = function () {
  290. App_1.App.LocalStorageUtil.setNumber(App_1.App.LocalStorageUtil.lst_Tili, TimeControl_1.default.instance.currentTili);
  291. };
  292. DataManager.prototype.UpdateTili = function (num, cb) {
  293. if (num === void 0) { num = 1; }
  294. if (cb === void 0) { cb = null; }
  295. var shengyuTili = TimeControl_1.default.instance.currentTili + num;
  296. if (shengyuTili < 0) {
  297. if (cb)
  298. cb(false);
  299. return;
  300. }
  301. if (cb)
  302. cb(true);
  303. TimeControl_1.default.instance.currentTili = shengyuTili;
  304. // console.log('^^^^^^^^^^^', TimeControl.instance.currentTili, shengyuTili)
  305. App_1.App.DataManager.SaveMessage();
  306. this.TimeCountJudge();
  307. App_1.App.Facade.getModel(hallModel_1.default).updateTiliNumber();
  308. };
  309. /**
  310. * 加载关卡预设
  311. * @param levelName 关卡预设名
  312. * @param cb 加载完关卡后回调
  313. */
  314. DataManager.prototype.LoadLevelPrefab = function (levelName, cb) {
  315. var _this = this;
  316. if (this.PropPrefabs.hasOwnProperty(levelName)) {
  317. cb && cb(this.PropPrefabs[levelName]);
  318. }
  319. else {
  320. cc.assetManager.loadBundle("gameScene", function (err, bundle) {
  321. bundle.load('prefabs/levelPrefab/' + levelName, cc.Prefab, function (err, assets) {
  322. _this.PropPrefabs[levelName] = assets;
  323. cb && cb(assets);
  324. });
  325. });
  326. }
  327. };
  328. DataManager.prototype.LoadAllPropPrefab = function (cb) {
  329. var _this = this;
  330. cc.assetManager.loadBundle("gameScene", function (err, bundle) {
  331. bundle.loadDir('prefabs/levelPrefab', cc.Prefab, function (err, assets) {
  332. for (var i = 0; i < assets.length; i++) {
  333. var sf = assets[i];
  334. _this.PropPrefabs[sf.name] = sf;
  335. if (i == assets.length - 1) {
  336. cb && cb();
  337. }
  338. }
  339. });
  340. });
  341. };
  342. DataManager.prototype.TimeCountJudge = function () {
  343. if (TimeControl_1.default.instance.currentTili < TimeControl_1.default.instance.tiliMax) {
  344. TimeControl_1.default.instance.CountTili();
  345. }
  346. else {
  347. if (App_1.App.DataManager.TimeFlag)
  348. TimeControl_1.default.instance.StopCount();
  349. }
  350. };
  351. DataManager.prototype.TimeChange = function (time) {
  352. // var h = Math.floor(time / 3600) < 10 ? '0' + Math.floor(time / 3600) : Math.floor(time / 3600);
  353. var min = Math.floor((time / 60 % 60)) < 10 ? '0' + Math.floor((time / 60 % 60)) : Math.floor((time / 60 % 60));
  354. var sec = Math.floor((time % 60)) < 10 ? '0' + Math.floor((time % 60)) : Math.floor((time % 60));
  355. //return result = h + ":" + m + ":" + s;
  356. var returnValue = min + ":" + sec;
  357. return returnValue;
  358. };
  359. DataManager.prototype.initSkinData = function () {
  360. var getSkins = App_1.App.LocalStorageUtil.getJsonObj(App_1.App.LocalStorageUtil.lst_getSkin);
  361. if (!getSkins)
  362. App_1.App.LocalStorageUtil.setJsonObj(App_1.App.LocalStorageUtil.lst_getSkin, this.GetSkins);
  363. else
  364. this.GetSkins = getSkins;
  365. var dressOnSkin = App_1.App.LocalStorageUtil.getString(App_1.App.LocalStorageUtil.lst_dressOnSkin);
  366. if (!dressOnSkin)
  367. App_1.App.LocalStorageUtil.setString(App_1.App.LocalStorageUtil.lst_dressOnSkin, this.DressingSkin);
  368. else
  369. this.DressingSkin = dressOnSkin;
  370. if (this.DressingSkin == "niao0") {
  371. this.DressingSkin = 'niao1';
  372. if (this.GetSkins.indexOf('niao1') == -1)
  373. this.GetSkins.push('niao1');
  374. }
  375. };
  376. DataManager.prototype.OnShow = function () {
  377. if (App_1.App.DataManager.TimeFlag) {
  378. TimeControl_1.default.instance.OfflineTime();
  379. }
  380. };
  381. DataManager.prototype.OnHide = function () {
  382. if (App_1.App.DataManager.TimeFlag) {
  383. var currentTime = Date.parse(new Date().toString());
  384. App_1.App.LocalStorageUtil.setNumber(App_1.App.LocalStorageUtil.lst_CountTime, currentTime);
  385. App_1.App.LocalStorageUtil.setNumber(App_1.App.LocalStorageUtil.lst_CountSecond, TimeControl_1.default.instance.currentTimeCount);
  386. }
  387. };
  388. return DataManager;
  389. }(Singleton_1.Singleton));
  390. exports.DataManager = DataManager;
  391. cc._RF.pop();