import { EventCenter } from '../../common/ui/uiEv/EventCenter'; import gameCfg from '../config/gameCfg'; import { MSG_Event } from '../DefineMsg/LogicMsg'; import { hallproto } from '../netPb/protobundle'; import AccountManager from './data/AccountManager'; import { baseObj, composeObj, objType, valueObj } from './data/baseObject'; import DataManager from './data/DataManager'; import dataManager from './data/DataManager'; import { fileCfgType, IDDef } from './data/excelDefine'; import { propType, PropUnlock, PropLeaveUp, PropCatch, IPSignIn, PropSignIn } from './data/propObject'; import ProxyNetDataMgr from './ProxyNetDataMgr'; /** * 模型层 * 数据代理类 */ //离线收益 export interface offLineData{ addCoin:number, //总增加的金币 parkfee:number, //场馆收费金币 fishfee:number, //钓鱼出售金币 fishNums:number, //钓鱼数量 fishNew:number, //新解锁的鱼数量 offLineTime:number, //离线时间 } //在线钓鱼统计 export interface fishCathOnline{ id:number, type:number, //1标识解锁,2标识出售 numSale:number, //出售数量 coinSale:number,//出售价值 } export default class ProxyClientDataMgr { private static instance: any; public static ins(): ProxyClientDataMgr { this.instance = this.instance || new ProxyClientDataMgr() return this.instance } m_version:string; feeTimmer = 0;//收费计时器 m_bStartFishStatistics = false;//钓鱼统计 fishStatistics:Array = Array()//关闭钓鱼界面,在线期间的统计 //初始化游戏数据 initGameData(){ EventCenter.on(MSG_Event.ReadStartCfg,this.downConfigResOver,this) this.checkVersion() // } //检测版本号 checkVersion() { ProxyNetDataMgr.ins().getDataFromHttp("cfgVersion.json",(data)=>{ console.log("curServerVersion:",this.m_version) let curcfg = cc.sys.localStorage.getItem("cfgVersion") if(!data) { EventCenter.emit(MSG_Event.Net_ERRO,"网络响应超时,没有获取到版本数据") return } let decodeData = JSON.parse(data) if(!curcfg || curcfg!=decodeData.version)//网络获取 { this.m_version = decodeData.version ProxyNetDataMgr.ins().downConfig()//获取配置文件 } else//读取本地文件 { this.m_version = curcfg this.readConfigToObj() } }) } downConfigResOver(cur:number,max:number){ if(cur==max) { console.log("downConfigResOver",cur,max) cc.sys.localStorage.setItem("cfgVersion",this.m_version) EventCenter.targetOff(this) } else console.log("downConfigResOver",cur,max) } // //获取资产 getValueObj(id:number) { let findDt = AccountManager.ins().getGameInfo().findMeans(id) if(findDt.getObjType()==objType.value) return (findDt as valueObj) else return new valueObj() } //获取组合对象 getComposeObj(id:number) { let findDt = AccountManager.ins().getGameInfo().findMeans(id) if(findDt&&findDt.getObjType()==objType.compose) return (findDt as composeObj) else return new composeObj() } //获取签到属性 getSingInProp() { return AccountManager.ins().getGameInfo().getPropByType(propType.signIn) } //读取配置转对象 readConfigToObj(){ let exp = cc.sys.localStorage.getItem("express.txt"); DataManager.ins().readConfigToObj(exp,fileCfgType.ruleFunc) EventCenter.emit(MSG_Event.ReadStartCfg,1,5) let level = cc.sys.localStorage.getItem("level.txt"); DataManager.ins().readConfigToObj(level,fileCfgType.level) EventCenter.emit(MSG_Event.ReadStartCfg,2,5) let obj = cc.sys.localStorage.getItem("obj.txt"); DataManager.ins().readConfigToObj(obj,fileCfgType.obj) EventCenter.emit(MSG_Event.ReadStartCfg,3,5) let sale = cc.sys.localStorage.getItem("sale.txt"); DataManager.ins().readConfigToObj(sale,fileCfgType.sale) EventCenter.emit(MSG_Event.ReadStartCfg,4,5) let unlock = cc.sys.localStorage.getItem("unlock.txt"); DataManager.ins().readConfigToObj(unlock,fileCfgType.unlock) EventCenter.emit(MSG_Event.ReadStartCfg,5,5) } //保存数据 saveGameDataById(id:number){ if(id!=IDDef.COIN)//不是金币 { console.log("saveGameDataById:",id) } let gameInfo = AccountManager.ins().getGameInfo() let saveData = ProxyNetDataMgr.ins().saveGameData if(id==IDDef.SIGNIN)//签到保存 { let sInData = saveData.singInData let objPropSIn = this.getSingInProp() as PropSignIn sInData.weekOnetime = objPropSIn.getWeekOneTime() sInData.singInlist = [] for(let idx=1;idx<=7;++idx){ let sInList = objPropSIn.getSignInfo(idx) if(sInList.eSigin==1||sInList.eSigin==2)//已签到 { let pbSInDt = hallproto.SingInData.singIn.create({weekDay:sInList.weekDay,sInType:sInList.eSigin}) sInData.singInlist.push(pbSInDt) } } } else{//资产类型 let obj = gameInfo.findMeans(id) if(!obj)return let meansDataTemp = hallproto.MeansData.create() meansDataTemp.id = id meansDataTemp.prop = {}//hallproto.MeansProp.create() if(obj.getObjType()==objType.value)//数量 meansDataTemp.prop.num = (obj as valueObj).getCount() let unlockProp = obj.getPropByType(propType.unlock) let levelProp = obj.getPropByType(propType.level) let catchProp = obj.getPropByType(propType.catch) if(unlockProp)//解锁 { meansDataTemp.prop.unlockfee = (unlockProp as PropUnlock).getFee() meansDataTemp.prop.bUnlock = (unlockProp as PropUnlock).getUnLock() } if(levelProp)//升级 meansDataTemp.prop.level = (levelProp as PropLeaveUp).getLevel() if(catchProp)//可捕获对象 meansDataTemp.prop.catchFishes = (catchProp as PropCatch).getAble() let isIn = false; for(let idx=0;idx6*60)//6分钟 { let gameInfo = AccountManager.ins().getGameInfo() //场馆收益 let delayJieduan = [] let cfgOffLinePark = gameCfg.offLineParkTime let tempSecend = delaySecond for(let idx=0;idx=(mins*60)?mins*60:tempSecend //分钟 delayJieduan.push(jdTime) tempSecend -= jdTime } let allAddCoin = 0 for(let idx=0;idxgameCfg.offLineFishTime[2])offLineMinuts=gameCfg.offLineFishTime[2] //最大时间 let CountTimes = Math.floor(offLineMinuts/gameCfg.offLineFishTime[3])//6分钟一次计算 if(CountTimes>0)//间隔时间 { let resultCatch = gameInfo.doCatchFish(CountTimes,gameCfg.offLineFishTime[0],gameCfg.offLineFishTime[1]) //新捕获的鱼 for(let idx=0;idx0) { let coinObj = gameInfo.getMember(IDDef.COIN) if(coinObj) (coinObj as valueObj).changeCount(offlineDt.addCoin) } ProxyClientDataMgr.ins().saveGameDataById(IDDef.COIN)//金币变化保存 EventCenter.emit(MSG_Event.OffLineRevenue,offlineDt) } cc.sys.localStorage.setItem("lastSaveParkFee",String(curSecend)) } //启动场馆收费 startParkFee(){ var secMin = gameCfg.parkFeeTime[0], secMax = gameCfg.parkFeeTime[1]; let randTm = Math.floor(Math.random() * (secMax - secMin + 1) + secMin); //Generate Random number between 15 - 30 function delayTimeOver() { let gameInfo = AccountManager.ins().getGameInfo() let secendCoin = randTm*gameInfo.admissionFee() let coinObj = gameInfo.getMember(IDDef.COIN) if(coinObj) (coinObj as valueObj).changeCount(secendCoin) console.log("=========getParkFee:"+secendCoin+" 当前金币:"+(coinObj as valueObj).getCount()) EventCenter.emit(MSG_Event.ParkFeeCoin,secendCoin) ProxyClientDataMgr.ins().saveGameDataById(IDDef.COIN)//金币变化保存 let curSecend = Math.floor(new Date().getTime()/(1*1000)) cc.sys.localStorage.setItem("lastSaveParkFee",String(curSecend)) randTm = Math.floor(Math.random() * (secMax - secMin + 1) + secMin); //Generate Random number between 15 - 30 setTimeout(delayTimeOver, randTm * 1000); } setTimeout(delayTimeOver, randTm * 1000); } //出海捕鱼 goFishing(){ let self = this; setInterval(function(){ //在线 一分钟一条鱼 let gameInfo = AccountManager.ins().getGameInfo() let resultCatch = gameInfo.doCatchFish(1,50,50)//在线按50的比例捕获 let catchedData:fishCathOnline={ type : 0, numSale : 0, id : 0, coinSale: 0, } if(resultCatch.mapCatched.size==1)//钓到一条 { let desp = "=========goFishing," for (let [idkey, num] of resultCatch.mapCatched) { catchedData.id = idkey; catchedData.numSale = num; let fishName = DataManager.ins().getObjCfgById(idkey)._name desp += "["+String(idkey)+"]"+fishName+" num:"+String(num)+"条 " } console.log(desp) if(resultCatch.vecNewCatched.length>0)//解锁新鱼 { catchedData.type = 1; desp = "钓到新解锁鱼:" for(let idx=0;idx0) { let coinObj = gameInfo.getMember(IDDef.COIN) if(coinObj) (coinObj as valueObj).changeCount(resultCatch.allFee) console.log("出售钓得的鱼获得金币:"+resultCatch.allFee+" 当前金币:"+(coinObj as valueObj).getCount()) ProxyClientDataMgr.ins().saveGameDataById(IDDef.COIN)//金币变化保存 } EventCenter.emit(MSG_Event.FishSaleCoin,catchedData) //新捕获的鱼 for(let idx=0;idx() return this.fishStatistics; } //解锁物品 doUnlockItem(id:number){ let gameInfo = AccountManager.ins().getGameInfo() let coinSecond = gameInfo.admissionFee()//每秒收益 let [resp,bSave] = gameInfo.doUnlockObj(id,coinSecond) if(resp==true) { if(bSave) ProxyClientDataMgr.ins().saveGameDataById(id)// //子对象默认解锁 let data = gameInfo.findMeans(id) if(data.getObjType()==objType.compose)//有成员 { let members = (data as composeObj).getMemberMap() for(let [mId,mVl] of members){ let unlockCfg = DataManager.ins().getUnlockCfgById(mId) if(!unlockCfg)//没有解锁条件,可默认解锁 { this.doUnlockItem(mId); } } } } } //升级物品 doGroupUpItem(id:number){ let gameInfo = AccountManager.ins().getGameInfo() if(gameInfo.doLevelUpObj(id)==true) ProxyClientDataMgr.ins().saveGameDataById(id)// } //获取解锁描述 getUnlockDesp(id:number){ let gameInfo = AccountManager.ins().getGameInfo() return gameInfo.getUnLockDesp(id)// } //获取等级buff描述 getBuffDesp(id:number,lv?:number){ let gameInfo = AccountManager.ins().getGameInfo() return gameInfo.getBuffDesp(id,lv)// } //获取升级描述 getGroupUpDesp(id:number){ let gameInfo = AccountManager.ins().getGameInfo() return gameInfo.getUpLevelDesp(id)// } //是否可解锁 isUnLockAble(id:number){ let gameInfo = AccountManager.ins().getGameInfo() return gameInfo.isUnlockObjAble(id)// } //是否可升级 isGroupUpAble(id:number){ let gameInfo = AccountManager.ins().getGameInfo() return gameInfo.isUpLevelObjAble(id)// } //当日是否可签到 isTodaySignInAble(){ let saveData = ProxyNetDataMgr.ins().saveGameData let signWeekDay = saveData.singInData.weekOnetime //签到的周一时间 let curDate = new Date();//当日时间 let dt0DianTm = new Date(curDate.getFullYear(),curDate.getMonth(),curDate.getDate()) let curWeekDay = (dt0DianTm.getDay()-1+7)%7+1//当前星期x let dwWeekOneTm = new Date() dwWeekOneTm.setTime(dt0DianTm.getTime()-(curWeekDay-1)*24*3600*1000)//星期一的毫秒数 if(dwWeekOneTm.getTime() === (+signWeekDay))//同一周数据 { for(let idx=0;idx0) { let coinObj = gameInfo.getMember(IDDef.COIN) if(coinObj) (coinObj as valueObj).changeCount(allAddCoin) console.log("签到星期"+wDay+"获得金币:"+allAddCoin+" 当前金币:"+(coinObj as valueObj).getCount()) ProxyClientDataMgr.ins().saveGameDataById(IDDef.COIN)//金币变化保存 EventCenter.emit(MSG_Event.OperChangeCoin,allAddCoin) } ProxyClientDataMgr.ins().saveGameDataById(IDDef.SIGNIN)//签到保存 EventCenter.emit(MSG_Event.Net_DoSignInResp,{coin:allAddCoin,weekDay:wDay}) } } }