import { Singleton } from "../Utils/Singleton"; import { ETaskID } from "../Const/EnumDefine"; import { App } from "../../Manager/App"; import { DateUtil } from "../Utils/DateUtil"; import NotificationManager from "../../../lightMVC/core/manager/NotificationManager"; import TimeControl from "../../TimeControl"; import hallModel from "../../model/hallModel"; /** * 数据管理器 */ export class DataManager extends Singleton { // /** 免费视频总次数 */ // public FREE_WATCH_TIMES: number = 10; /**已有皮肤数组 */ public GetSkins: any = ['niao1']; /**当前穿戴皮肤 */ public DressingSkin: string = 'niao1'; /**用户金币*/ public UserCoin: number = 0; public UserDiamond: number = 0; /**通关进度 2表示通过了第一关,当前关卡为2, 3表示通过了第2关,当前关卡为3, */ public PassProgress: any = { "1": 1 }; /**30关后随机关卡存储 保证只随机一次 */ public InfiniteLevelDate: any = {}; /**玩家已经玩到的关卡*/ public PlayLevel: number = 1; /**点击关卡号进入的关卡*/ public CurrentIntoLevel: number = 1; /**关卡数据*/ public Configs: any = []; /**看视频得体力数*/ public VideoAddTili: number = 10; /**看视频得金币数*/ public VideoAddCoin: number = 500; /**总关卡数*/ public LevelCount: number = 15; /**重玩标志 */ public resetFlag: boolean = false; /**重玩关卡*/ public resetLevel: number = 0; /**重玩关卡*/ public resetLevelBgIndex: number = 0; public guideStep = 0; // 关卡钻石数量 public diamondNum = [ [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], ]; // 钥匙的位置 public keyPos = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]; public foodLevel: any = [0, 0, 0, 0, 0, 0]; public kinchenLevel: any = [0, 0, 0]; public maxFoodLevel = 2; public maxKitchenLevel = 2; //升级食物需要的金币 public upgradeFoodCoin = [ [500, 1000], [630, 1200], [550, 860], [520, 800], [500, 600], [870, 1000], ]; // 食物升级之后售价 public foodSoldCoin = [ [5, 8, 11], [6, 9, 12], [3, 5, 10], [4, 6, 10], [1, 2, 3], [3, 4, 5], ] // 升级厨具需要的金币 public upgradeKitchenCoin = [ [500, 1000], [500, 1000], [1000, 1500], ]; // 餐具数量 public kitchenNum = [ [2, 3, 4], [2, 3, 4], [1, 2, 3], ] public dirnkMachinTime = [4, 3, 2]; // 食物搭配种类 public levelFoodKind = [ 3, 3, 4, 4, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, ]; public personCount = [ [6, 9, 12], [7, 10, 13], [8, 11, 14], [9, 12, 15], [10, 13, 16], [11, 14, 17], [12, 15, 18], [13, 16, 19], [14, 17, 20], [15, 18, 21], [16, 19, 22], [17, 20, 23], [18, 21, 24], [19, 22, 25], [20, 23, 26], ]; public RandomLevelList = [ { startLevel: 11, endLevel: 15 }, { startLevel: 16, endLevel: 20 }, { startLevel: 21, endLevel: 25 }, { startLevel: 26, endLevel: 30 } ]; public particleColorList: any = { 'niao1': { startColor: new cc.Color(12, 166, 249, 255), endColor: new cc.Color(5, 223, 255, 255) }, } // 道具数量 public PropNum: any = [0, 0, 0, 0, 0]; public propPrice: any = [1800, 1500, 1700, 1250, 2300]; /**变小道具持续时间*/ public SmallTime: number = 5; /**已加载预设组*/ public PropPrefabs: any = []; /**倒计时标志*/ public TimeFlag: boolean = false; /**获得新皮肤标志 */ public GetNewSkinFlag: boolean = false; public NewSkinName: string = ""; // public MissionName = ["制作%d个牛排", "卖出饮料%d杯", "招待%d个顾客", "获得%d颗星星"]; public MissionName = ["Make %d steaks", "Sell drinks %d cups", "Serve %d customers", "Earn %d stars"]; public MissionComplete: any = [0, 0, 0, 0]; // soldSteakNum,soldDrinkNum,solCustomerNum,getStarNum; public MissionReceive: any = [0, 0, 0, 0]; /**皮肤设置 */ public SkinDataList: any = [ { name: 'niao1', path: 'skin/niao1' }, ]; /**任务设置 */ public MissionDataList: any = [ { missonNum: [5,10,20,30,40,50,60], rewardCoin: [100,200,300,400,500,600,700], rewardDiamon: [10,20,30,40,50,60,70], }, { missonNum: [5,10,15,20,30,40,50], rewardCoin: [100,200,300,400,500,600,700], rewardDiamon: [10,20,30,40,50,60,70], }, { missonNum: [5,10,20,30,40,50,60,1000], rewardCoin: [100,200,300,400,500,600,700], rewardDiamon: [10,20,30,40,50,60,70], }, { missonNum: [9,18,27,36,45,54,63,72,81], rewardCoin: [100,200,300,400,500,600,700], rewardDiamon: [10,20,30,40,50,60,70], }, ]; public constructor() { super(); } public init() { console.log("初始化用户数据"); this.initSkinData(); cc.game.on(cc.game.EVENT_SHOW, () => { this.OnShow(); console.log('进入游戏&&&&&&&&&&&&&&'); }); cc.game.on(cc.game.EVENT_HIDE, () => { this.OnHide(); console.log('退出游戏&&&&&&&&&&&&&&'); }); this.iniLevelData(); this.initUserCoin(); this.initUserDiamond(); } private iniLevelData(): void { let playLevel = App.LocalStorageUtil.getNumber(App.LocalStorageUtil.lst_playLevel); if (!playLevel) App.LocalStorageUtil.setNumber(App.LocalStorageUtil.lst_playLevel, this.PlayLevel); else this.PlayLevel = playLevel; let passProgress = App.LocalStorageUtil.getJsonObj(App.LocalStorageUtil.lst_passProgress); if (!passProgress) App.LocalStorageUtil.setJsonObj(App.LocalStorageUtil.lst_passProgress, this.PassProgress); else this.PassProgress = passProgress; console.log('通关进度:', this.PassProgress); // let infiniteLevelDate = App.LocalStorageUtil.getJsonObj(App.LocalStorageUtil.lst_InfiniteLevelDate); // if (!infiniteLevelDate) App.LocalStorageUtil.setJsonObj(App.LocalStorageUtil.lst_InfiniteLevelDate, this.InfiniteLevelDate); // else this.InfiniteLevelDate = infiniteLevelDate; // console.log('30关后随机关卡存储:', this.InfiniteLevelDate); // 食物等级 let fLevel = App.LocalStorageUtil.getJsonObj(App.LocalStorageUtil.list_foodLevel); if (!fLevel) App.LocalStorageUtil.setJsonObj(App.LocalStorageUtil.list_foodLevel, this.foodLevel); else this.foodLevel = fLevel; // 厨具等级 let kChenLevel = App.LocalStorageUtil.getJsonObj(App.LocalStorageUtil.list_kitchenLevel); if (!kChenLevel) App.LocalStorageUtil.setJsonObj(App.LocalStorageUtil.list_kitchenLevel, this.kinchenLevel); else this.kinchenLevel = kChenLevel; // 任务完成进度 let missionComplete = App.LocalStorageUtil.getJsonObj(App.LocalStorageUtil.list_missionComplete); if (!missionComplete) App.LocalStorageUtil.setJsonObj(App.LocalStorageUtil.list_missionComplete, this.MissionComplete); else this.MissionComplete = missionComplete; console.log('aaa--------missionComplete-----------', missionComplete); // 任务奖励领取进度 let missionReceive = App.LocalStorageUtil.getJsonObj(App.LocalStorageUtil.list_missionReceive); if (!missionReceive) App.LocalStorageUtil.setJsonObj(App.LocalStorageUtil.list_missionReceive, this.MissionReceive); else this.MissionReceive = missionReceive; console.log('aaa--------missionReceive-----------', missionReceive); let guidei = App.LocalStorageUtil.getNumber(App.LocalStorageUtil.str_guideStep); if (!guidei) App.LocalStorageUtil.setNumber(App.LocalStorageUtil.str_guideStep, this.guideStep); else this.guideStep = Number(guidei); } private initUserCoin(){ let coin = App.LocalStorageUtil.getNumber(App.LocalStorageUtil.lst_Coin); if (!coin) App.LocalStorageUtil.setNumber(App.LocalStorageUtil.lst_Coin, this.UserCoin); else this.UserCoin = Number(coin); } private initUserDiamond(){ let diamond = App.LocalStorageUtil.getNumber(App.LocalStorageUtil.lst_UserDiamond); if (!diamond) App.LocalStorageUtil.setNumber(App.LocalStorageUtil.lst_UserDiamond, this.UserDiamond); else this.UserDiamond = Number(diamond); } public SaveMessage(): void { App.LocalStorageUtil.setNumber(App.LocalStorageUtil.lst_Tili, TimeControl.instance.currentTili); } public UpdateTili(num: number = 1, cb: Function = null): void { let shengyuTili = TimeControl.instance.currentTili + num; if (shengyuTili < 0) { if (cb) cb(false); return; } if (cb) cb(true); TimeControl.instance.currentTili = shengyuTili; // console.log('^^^^^^^^^^^', TimeControl.instance.currentTili, shengyuTili) App.DataManager.SaveMessage(); this.TimeCountJudge(); App.Facade.getModel(hallModel).updateTiliNumber(); } /** * 加载关卡预设 * @param levelName 关卡预设名 * @param cb 加载完关卡后回调 */ public LoadLevelPrefab(levelName: string, cb: Function): void { if (this.PropPrefabs.hasOwnProperty(levelName)) { cb && cb(this.PropPrefabs[levelName]); } else { cc.assetManager.loadBundle("gameScene", (err, bundle) => { bundle.load('prefabs/levelPrefab/' + levelName, cc.Prefab, (err, assets) => { this.PropPrefabs[levelName] = assets; cb && cb(assets); }); }); } } public LoadAllPropPrefab(cb: Function): void { cc.assetManager.loadBundle("gameScene", (err, bundle) => { bundle.loadDir('prefabs/levelPrefab', cc.Prefab, (err, assets) => { for (var i = 0; i < assets.length; i++) { var sf = assets[i]; this.PropPrefabs[sf.name] = sf; if (i == assets.length - 1) { cb && cb(); } } }); }); } public TimeCountJudge(): void { if (TimeControl.instance.currentTili < TimeControl.instance.tiliMax) { TimeControl.instance.CountTili(); } else { if (App.DataManager.TimeFlag) TimeControl.instance.StopCount(); } } public TimeChange(time: number): string { // var h = Math.floor(time / 3600) < 10 ? '0' + Math.floor(time / 3600) : Math.floor(time / 3600); var min = Math.floor((time / 60 % 60)) < 10 ? '0' + Math.floor((time / 60 % 60)) : Math.floor((time / 60 % 60)); var sec = Math.floor((time % 60)) < 10 ? '0' + Math.floor((time % 60)) : Math.floor((time % 60)); //return result = h + ":" + m + ":" + s; var returnValue = min + ":" + sec; return returnValue; } private initSkinData() { let getSkins = App.LocalStorageUtil.getJsonObj(App.LocalStorageUtil.lst_getSkin); if (!getSkins) App.LocalStorageUtil.setJsonObj(App.LocalStorageUtil.lst_getSkin, this.GetSkins); else this.GetSkins = getSkins; let dressOnSkin = App.LocalStorageUtil.getString(App.LocalStorageUtil.lst_dressOnSkin); if (!dressOnSkin) App.LocalStorageUtil.setString(App.LocalStorageUtil.lst_dressOnSkin, this.DressingSkin); else this.DressingSkin = dressOnSkin; if (this.DressingSkin == "niao0") { this.DressingSkin = 'niao1'; if (this.GetSkins.indexOf('niao1') == -1) this.GetSkins.push('niao1'); } } private OnShow() { if (App.DataManager.TimeFlag) { TimeControl.instance.OfflineTime(); } } private OnHide() { if (App.DataManager.TimeFlag) { var currentTime = Date.parse(new Date().toString()); App.LocalStorageUtil.setNumber(App.LocalStorageUtil.lst_CountTime, currentTime); App.LocalStorageUtil.setNumber(App.LocalStorageUtil.lst_CountSecond, TimeControl.instance.currentTimeCount); } } // /** 获取免费视频次数 */ // public getFreeWatchTimes(): number { // console.log("free watch times"); // let now = new Date().getDay(); // let json = App.LocalStorageUtil.getJsonObj(App.LocalStorageUtil.lst_free_watch_times); // if (json) { // let preDay = json["day"]; // if (now == preDay) { // return json["times"]; // } // } // App.LocalStorageUtil.setJsonObj(App.LocalStorageUtil.lst_free_watch_times, // { "day": now, "times": this.FREE_WATCH_TIMES }); // return this.FREE_WATCH_TIMES; // } // /** 设置免费视频次数 */ // public subWatchTimes() { // let now = new Date().getDay(); // let json = App.LocalStorageUtil.getJsonObj(App.LocalStorageUtil.lst_free_watch_times); // if (json) { // let preDay = json["day"]; // let times = json["times"] - 1; // if (now == preDay) { // App.LocalStorageUtil.setJsonObj(App.LocalStorageUtil.lst_free_watch_times, // { "day": now, "times": times < 0 ? 0 : times }); // } else { // App.LocalStorageUtil.setJsonObj(App.LocalStorageUtil.lst_free_watch_times, // { "day": now, "times": this.FREE_WATCH_TIMES }); // } // } // } // /** 获取已签到天数 */ // public getDailyDay(): any { // console.log("getDailyDay"); // let json = App.LocalStorageUtil.getJsonObj(App.LocalStorageUtil.lst_daily_signin); // if (json) { // if (this.isTodaySignIn()) { // //今天已经签过到 // return json["day"]; // } else { // //昨天签到的 // if (json["day"] >= 7) //已经过去一周, 刷新次数 // return 0; // } // } // else { // return 0; // } // } // /** 今天是否签到 */ // public isTodaySignIn(): boolean { // let signin = App.LocalStorageUtil.getJsonObj(App.LocalStorageUtil.lst_daily_signin); // if (signin) { // let now = DateUtil.getYearMonthDay(); // if (signin["date"] == now) // return true; // else // return false; // } // return false; // } // /** 设置签到数据 */ // public setDailySignInData() { // let now = DateUtil.getYearMonthDay(); // console.log(now); // let day = this.getDailyDay() + 1; // App.LocalStorageUtil.setJsonObj(App.LocalStorageUtil.lst_daily_signin, // { "day": day, "date": now }); // let reward = App.ConfigMgr.getFuLiDayReward(day); // let data = { "1": reward }; // } }