DataManager.ts 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  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 MissionName = ["Make %d steaks", "Sell drinks %d cups", "Serve %d customers", "Earn %d stars"];
  158. public MissionComplete: any = [0, 0, 0, 0]; // soldSteakNum,soldDrinkNum,solCustomerNum,getStarNum;
  159. public MissionReceive: any = [0, 0, 0, 0];
  160. /**皮肤设置 */
  161. public SkinDataList: any = [
  162. {
  163. name: 'niao1',
  164. path: 'skin/niao1'
  165. },
  166. ];
  167. /**任务设置 */
  168. public MissionDataList: any = [
  169. {
  170. missonNum: [5,10,20,30,40,50,60],
  171. rewardCoin: [100,200,300,400,500,600,700],
  172. rewardDiamon: [10,20,30,40,50,60,70],
  173. },
  174. {
  175. missonNum: [5,10,15,20,30,40,50],
  176. rewardCoin: [100,200,300,400,500,600,700],
  177. rewardDiamon: [10,20,30,40,50,60,70],
  178. },
  179. {
  180. missonNum: [5,10,20,30,40,50,60,1000],
  181. rewardCoin: [100,200,300,400,500,600,700],
  182. rewardDiamon: [10,20,30,40,50,60,70],
  183. },
  184. {
  185. missonNum: [9,18,27,36,45,54,63,72,81],
  186. rewardCoin: [100,200,300,400,500,600,700],
  187. rewardDiamon: [10,20,30,40,50,60,70],
  188. },
  189. ];
  190. public constructor() {
  191. super();
  192. }
  193. public init() {
  194. console.log("初始化用户数据");
  195. this.initSkinData();
  196. cc.game.on(cc.game.EVENT_SHOW, () => {
  197. this.OnShow();
  198. console.log('进入游戏&&&&&&&&&&&&&&');
  199. });
  200. cc.game.on(cc.game.EVENT_HIDE, () => {
  201. this.OnHide();
  202. console.log('退出游戏&&&&&&&&&&&&&&');
  203. });
  204. this.iniLevelData();
  205. this.initUserCoin();
  206. this.initUserDiamond();
  207. }
  208. private iniLevelData(): void {
  209. let playLevel = App.LocalStorageUtil.getNumber(App.LocalStorageUtil.lst_playLevel);
  210. if (!playLevel) App.LocalStorageUtil.setNumber(App.LocalStorageUtil.lst_playLevel, this.PlayLevel);
  211. else this.PlayLevel = playLevel;
  212. let passProgress = App.LocalStorageUtil.getJsonObj(App.LocalStorageUtil.lst_passProgress);
  213. if (!passProgress) App.LocalStorageUtil.setJsonObj(App.LocalStorageUtil.lst_passProgress, this.PassProgress);
  214. else this.PassProgress = passProgress;
  215. console.log('通关进度:', this.PassProgress);
  216. // let infiniteLevelDate = App.LocalStorageUtil.getJsonObj(App.LocalStorageUtil.lst_InfiniteLevelDate);
  217. // if (!infiniteLevelDate) App.LocalStorageUtil.setJsonObj(App.LocalStorageUtil.lst_InfiniteLevelDate, this.InfiniteLevelDate);
  218. // else this.InfiniteLevelDate = infiniteLevelDate;
  219. // console.log('30关后随机关卡存储:', this.InfiniteLevelDate);
  220. // 食物等级
  221. let fLevel = App.LocalStorageUtil.getJsonObj(App.LocalStorageUtil.list_foodLevel);
  222. if (!fLevel) App.LocalStorageUtil.setJsonObj(App.LocalStorageUtil.list_foodLevel, this.foodLevel);
  223. else this.foodLevel = fLevel;
  224. // 厨具等级
  225. let kChenLevel = App.LocalStorageUtil.getJsonObj(App.LocalStorageUtil.list_kitchenLevel);
  226. if (!kChenLevel) App.LocalStorageUtil.setJsonObj(App.LocalStorageUtil.list_kitchenLevel, this.kinchenLevel);
  227. else this.kinchenLevel = kChenLevel;
  228. // 任务完成进度
  229. let missionComplete = App.LocalStorageUtil.getJsonObj(App.LocalStorageUtil.list_missionComplete);
  230. if (!missionComplete) App.LocalStorageUtil.setJsonObj(App.LocalStorageUtil.list_missionComplete, this.MissionComplete);
  231. else this.MissionComplete = missionComplete;
  232. console.log('aaa--------missionComplete-----------', missionComplete);
  233. // 任务奖励领取进度
  234. let missionReceive = App.LocalStorageUtil.getJsonObj(App.LocalStorageUtil.list_missionReceive);
  235. if (!missionReceive) App.LocalStorageUtil.setJsonObj(App.LocalStorageUtil.list_missionReceive, this.MissionReceive);
  236. else this.MissionReceive = missionReceive;
  237. console.log('aaa--------missionReceive-----------', missionReceive);
  238. let guidei = App.LocalStorageUtil.getNumber(App.LocalStorageUtil.str_guideStep);
  239. if (!guidei) App.LocalStorageUtil.setNumber(App.LocalStorageUtil.str_guideStep, this.guideStep);
  240. else this.guideStep = Number(guidei);
  241. }
  242. private initUserCoin(){
  243. let coin = App.LocalStorageUtil.getNumber(App.LocalStorageUtil.lst_Coin);
  244. if (!coin) App.LocalStorageUtil.setNumber(App.LocalStorageUtil.lst_Coin, this.UserCoin);
  245. else this.UserCoin = Number(coin);
  246. }
  247. private initUserDiamond(){
  248. let diamond = App.LocalStorageUtil.getNumber(App.LocalStorageUtil.lst_UserDiamond);
  249. if (!diamond) App.LocalStorageUtil.setNumber(App.LocalStorageUtil.lst_UserDiamond, this.UserDiamond);
  250. else this.UserDiamond = Number(diamond);
  251. }
  252. public SaveMessage(): void {
  253. App.LocalStorageUtil.setNumber(App.LocalStorageUtil.lst_Tili, TimeControl.instance.currentTili);
  254. }
  255. public UpdateTili(num: number = 1, cb: Function = null): void {
  256. let shengyuTili = TimeControl.instance.currentTili + num;
  257. if (shengyuTili < 0) {
  258. if (cb) cb(false);
  259. return;
  260. }
  261. if (cb) cb(true);
  262. TimeControl.instance.currentTili = shengyuTili;
  263. // console.log('^^^^^^^^^^^', TimeControl.instance.currentTili, shengyuTili)
  264. App.DataManager.SaveMessage();
  265. this.TimeCountJudge();
  266. App.Facade.getModel(hallModel).updateTiliNumber();
  267. }
  268. /**
  269. * 加载关卡预设
  270. * @param levelName 关卡预设名
  271. * @param cb 加载完关卡后回调
  272. */
  273. public LoadLevelPrefab(levelName: string, cb: Function): void {
  274. if (this.PropPrefabs.hasOwnProperty(levelName)) {
  275. cb && cb(this.PropPrefabs[levelName]);
  276. } else {
  277. cc.assetManager.loadBundle("gameScene", (err, bundle) => {
  278. bundle.load('prefabs/levelPrefab/' + levelName, cc.Prefab, (err, assets) => {
  279. this.PropPrefabs[levelName] = assets;
  280. cb && cb(assets);
  281. });
  282. });
  283. }
  284. }
  285. public LoadAllPropPrefab(cb: Function): void {
  286. cc.assetManager.loadBundle("gameScene", (err, bundle) => {
  287. bundle.loadDir('prefabs/levelPrefab', cc.Prefab, (err, assets) => {
  288. for (var i = 0; i < assets.length; i++) {
  289. var sf = assets[i];
  290. this.PropPrefabs[sf.name] = sf;
  291. if (i == assets.length - 1) {
  292. cb && cb();
  293. }
  294. }
  295. });
  296. });
  297. }
  298. public TimeCountJudge(): void {
  299. if (TimeControl.instance.currentTili < TimeControl.instance.tiliMax) {
  300. TimeControl.instance.CountTili();
  301. } else {
  302. if (App.DataManager.TimeFlag)
  303. TimeControl.instance.StopCount();
  304. }
  305. }
  306. public TimeChange(time: number): string {
  307. // var h = Math.floor(time / 3600) < 10 ? '0' + Math.floor(time / 3600) : Math.floor(time / 3600);
  308. var min = Math.floor((time / 60 % 60)) < 10 ? '0' + Math.floor((time / 60 % 60)) : Math.floor((time / 60 % 60));
  309. var sec = Math.floor((time % 60)) < 10 ? '0' + Math.floor((time % 60)) : Math.floor((time % 60));
  310. //return result = h + ":" + m + ":" + s;
  311. var returnValue = min + ":" + sec;
  312. return returnValue;
  313. }
  314. private initSkinData() {
  315. let getSkins = App.LocalStorageUtil.getJsonObj(App.LocalStorageUtil.lst_getSkin);
  316. if (!getSkins) App.LocalStorageUtil.setJsonObj(App.LocalStorageUtil.lst_getSkin, this.GetSkins);
  317. else this.GetSkins = getSkins;
  318. let dressOnSkin = App.LocalStorageUtil.getString(App.LocalStorageUtil.lst_dressOnSkin);
  319. if (!dressOnSkin) App.LocalStorageUtil.setString(App.LocalStorageUtil.lst_dressOnSkin, this.DressingSkin);
  320. else this.DressingSkin = dressOnSkin;
  321. if (this.DressingSkin == "niao0") {
  322. this.DressingSkin = 'niao1';
  323. if (this.GetSkins.indexOf('niao1') == -1) this.GetSkins.push('niao1');
  324. }
  325. }
  326. private OnShow() {
  327. if (App.DataManager.TimeFlag) {
  328. TimeControl.instance.OfflineTime();
  329. }
  330. }
  331. private OnHide() {
  332. if (App.DataManager.TimeFlag) {
  333. var currentTime = Date.parse(new Date().toString());
  334. App.LocalStorageUtil.setNumber(App.LocalStorageUtil.lst_CountTime, currentTime);
  335. App.LocalStorageUtil.setNumber(App.LocalStorageUtil.lst_CountSecond, TimeControl.instance.currentTimeCount);
  336. }
  337. }
  338. // /** 获取免费视频次数 */
  339. // public getFreeWatchTimes(): number {
  340. // console.log("free watch times");
  341. // let now = new Date().getDay();
  342. // let json = App.LocalStorageUtil.getJsonObj(App.LocalStorageUtil.lst_free_watch_times);
  343. // if (json) {
  344. // let preDay = json["day"];
  345. // if (now == preDay) {
  346. // return json["times"];
  347. // }
  348. // }
  349. // App.LocalStorageUtil.setJsonObj(App.LocalStorageUtil.lst_free_watch_times,
  350. // { "day": now, "times": this.FREE_WATCH_TIMES });
  351. // return this.FREE_WATCH_TIMES;
  352. // }
  353. // /** 设置免费视频次数 */
  354. // public subWatchTimes() {
  355. // let now = new Date().getDay();
  356. // let json = App.LocalStorageUtil.getJsonObj(App.LocalStorageUtil.lst_free_watch_times);
  357. // if (json) {
  358. // let preDay = json["day"];
  359. // let times = json["times"] - 1;
  360. // if (now == preDay) {
  361. // App.LocalStorageUtil.setJsonObj(App.LocalStorageUtil.lst_free_watch_times,
  362. // { "day": now, "times": times < 0 ? 0 : times });
  363. // } else {
  364. // App.LocalStorageUtil.setJsonObj(App.LocalStorageUtil.lst_free_watch_times,
  365. // { "day": now, "times": this.FREE_WATCH_TIMES });
  366. // }
  367. // }
  368. // }
  369. // /** 获取已签到天数 */
  370. // public getDailyDay(): any {
  371. // console.log("getDailyDay");
  372. // let json = App.LocalStorageUtil.getJsonObj(App.LocalStorageUtil.lst_daily_signin);
  373. // if (json) {
  374. // if (this.isTodaySignIn()) {
  375. // //今天已经签过到
  376. // return json["day"];
  377. // } else {
  378. // //昨天签到的
  379. // if (json["day"] >= 7) //已经过去一周, 刷新次数
  380. // return 0;
  381. // }
  382. // }
  383. // else {
  384. // return 0;
  385. // }
  386. // }
  387. // /** 今天是否签到 */
  388. // public isTodaySignIn(): boolean {
  389. // let signin = App.LocalStorageUtil.getJsonObj(App.LocalStorageUtil.lst_daily_signin);
  390. // if (signin) {
  391. // let now = DateUtil.getYearMonthDay();
  392. // if (signin["date"] == now)
  393. // return true;
  394. // else
  395. // return false;
  396. // }
  397. // return false;
  398. // }
  399. // /** 设置签到数据 */
  400. // public setDailySignInData() {
  401. // let now = DateUtil.getYearMonthDay();
  402. // console.log(now);
  403. // let day = this.getDailyDay() + 1;
  404. // App.LocalStorageUtil.setJsonObj(App.LocalStorageUtil.lst_daily_signin,
  405. // { "day": day, "date": now });
  406. // let reward = App.ConfigMgr.getFuLiDayReward(day);
  407. // let data = { "1": reward };
  408. // }
  409. }