DataManager.ts 16 KB

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