298 lines
11 KiB
TypeScript
298 lines
11 KiB
TypeScript
import {composeObj,baseObj,objType, propBase, valueObj} from './baseObject'
|
||
import {Propbuff,buffIF,propType, PropUnlock, PropLeaveUp, PropCatch, PropSignIn, IPSignIn} from './propObject'
|
||
import dataManager from './DataManager'
|
||
import gameFun from './gameFun'
|
||
import {excelJson,saleCfg,levelCfg,unlockCfg,objCfg, funcExpression, buffCfg, buffType, IDDef} from './excelDefine'
|
||
import DataManager from './DataManager'
|
||
import gameCfg from '../../config/gameCfg'
|
||
|
||
export interface catchData{
|
||
mapCatched:Map<number,number>,//总共捕获的鱼id,鱼数量
|
||
vecNewCatched:Array<number>,//新捕获
|
||
allFee:number,//出售费用
|
||
}
|
||
|
||
//游戏对象,包含一系列资产
|
||
export default class GameInfo extends composeObj{
|
||
m_gameFun:gameFun = new gameFun()//依赖游戏函数
|
||
//构造
|
||
constructor(gameId:number){
|
||
super(gameId)
|
||
this.addProp(new PropSignIn())
|
||
}
|
||
m_mapMeansList:Map<number,baseObj>=new Map<number,baseObj>()//快捷查询物品列表
|
||
//签到属性
|
||
|
||
//获取资产道具
|
||
findMeans(id:number){
|
||
return this.m_mapMeansList.get(id);
|
||
}
|
||
|
||
//获取单位时间增加的金币门票
|
||
admissionFee(){
|
||
let buffList = this.getPropDeep(propType.buff)
|
||
let coinAddBase = gameCfg.startParkFee
|
||
let addProb = 1
|
||
for(let idx=0;idx<buffList.length;++idx)
|
||
{
|
||
let buffInfo = (buffList[idx] as Propbuff).getBuff()
|
||
if(buffInfo.eType == buffType.base)
|
||
coinAddBase += buffInfo.num
|
||
if(buffInfo.eType == buffType.ratio)
|
||
addProb += buffInfo.num
|
||
}
|
||
let coin = Math.floor(coinAddBase*addProb)
|
||
//四舍五入
|
||
|
||
return coin
|
||
}
|
||
|
||
//获取解锁描述,解锁的条件描述
|
||
getUnLockDesp(id:number){
|
||
let exData = dataManager.ins().getUnlockCfgById(id);
|
||
let mapdesp:Map<number,string> = new Map<number,string>()
|
||
if(exData)
|
||
{
|
||
let arrList = exData._unlockCondition
|
||
for (let idx=0;idx<arrList.length;++idx)
|
||
{
|
||
let tempData = this.m_gameFun.doDespDecode(this,arrList[idx],id)
|
||
if(tempData[1]!="")
|
||
mapdesp.set(tempData[0],tempData[1]);
|
||
}
|
||
}
|
||
return mapdesp;
|
||
}
|
||
//是否可以解锁
|
||
isUnlockObjAble(id:number){
|
||
let exData = dataManager.ins().getUnlockCfgById(id);
|
||
if(exData)
|
||
{
|
||
let arrList = exData._unlockCondition
|
||
let able = true
|
||
for (let idx=0;idx<arrList.length;++idx)
|
||
{
|
||
able = this.m_gameFun.doConditionDecode(this,arrList[idx],id) as boolean;
|
||
if(able==false)
|
||
return false;
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
//解锁操作,score表示解锁的花费
|
||
doUnlockObj(id:number,score:number){
|
||
let bSave = false;
|
||
if(this.isUnlockObjAble(id)==true)
|
||
{
|
||
let data = this.findMeans(id)
|
||
if(data)
|
||
{
|
||
let unlockObj = data.getPropByType(propType.unlock) as PropUnlock
|
||
if(unlockObj)//没有解锁
|
||
{
|
||
if(unlockObj.getUnLock()==true)return [false,false];
|
||
unlockObj.setUnLock(true)
|
||
unlockObj.setFee(score)
|
||
this.doLevelUpObj(id,true)//有升级的话,默认升级1
|
||
bSave = true;
|
||
}
|
||
}
|
||
}
|
||
return [true,bSave];
|
||
}
|
||
//获取升级描述
|
||
getUpLevelDesp(id:number){
|
||
let data = this.findMeans(id)
|
||
let mapDesp:Map<number,string> = new Map<number,string>()
|
||
if(!data)return mapDesp
|
||
let findProp = data.getPropByType(propType.level)
|
||
if(!findProp)return mapDesp
|
||
let lvObj = findProp as PropLeaveUp
|
||
let exData = dataManager.ins().getLevelCfgByIdLv(id,lvObj.getLevel());
|
||
if(exData)
|
||
{
|
||
let arrList = exData._growupCondition
|
||
let able = true
|
||
for (let idx=0;idx<arrList.length;++idx)
|
||
{
|
||
let tempData = this.m_gameFun.doDespDecode(this,arrList[idx],id);
|
||
if(tempData[1]!="")
|
||
mapDesp.set(tempData[0],tempData[1])
|
||
}
|
||
}
|
||
return mapDesp;
|
||
}
|
||
//获取buf描述
|
||
getBuffDesp(id:number,lv?:number){
|
||
let data = this.findMeans(id)
|
||
if(!data)return [0,""]
|
||
let findProp = data.getPropByType(propType.level)
|
||
if(!findProp)return [0,""]
|
||
let lvObj = findProp as PropLeaveUp
|
||
let curLv = lv?lv:lvObj.getLevel()
|
||
let exData = dataManager.ins().getLevelCfgByIdLv(id,curLv-1);
|
||
if(exData)
|
||
{
|
||
let buffData = exData._buff
|
||
let desp = this.m_gameFun.doDespDecode(this,buffData,id);
|
||
return desp
|
||
}
|
||
return [0,""];
|
||
}
|
||
//是否可以升级
|
||
isUpLevelObjAble(id:number){
|
||
let data = this.findMeans(id)
|
||
if(!data)return
|
||
let findProp = data.getPropByType(propType.level)
|
||
if(!findProp)return
|
||
|
||
let lvObj = findProp as PropLeaveUp
|
||
let exData = dataManager.ins().getLevelCfgByIdLv(id,lvObj.getLevel());
|
||
if(exData)
|
||
{
|
||
let arrListCondition = exData._growupCondition
|
||
let able = true
|
||
for (let idx=0;idx<arrListCondition.length;++idx)
|
||
{
|
||
able = this.m_gameFun.doConditionDecode(this,arrListCondition[idx],id) as boolean;
|
||
if(able==false)
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
//升级操作
|
||
doLevelUpObj(id:number,bUnlock?:boolean){
|
||
let data = this.findMeans(id)
|
||
if(!data)return
|
||
let findProp = data.getPropByType(propType.level)
|
||
if(!findProp)return
|
||
|
||
let lvObj = findProp as PropLeaveUp
|
||
let curLv = lvObj.getLevel()
|
||
let buffProp = data.getPropByType(propType.buff) as Propbuff
|
||
|
||
if(curLv==0&&(bUnlock==undefined||bUnlock==false))
|
||
return false;
|
||
if(curLv>0 && (bUnlock==true))
|
||
return false;
|
||
|
||
let exData = dataManager.ins().getLevelCfgByIdLv(id,curLv);
|
||
let bUpAble = this.isUpLevelObjAble(id)
|
||
if(curLv>0) bUpAble = true
|
||
if(exData)
|
||
{
|
||
let arrList = exData._growupResult
|
||
let able = true
|
||
for (let idx=0;idx<arrList.length;++idx)
|
||
this.m_gameFun.doOperDecode(this,arrList[idx],id);
|
||
lvObj.changeLevel(1);
|
||
|
||
//当前buff
|
||
let jsonData = exData._buff
|
||
if(jsonData)
|
||
{
|
||
let idFun = <funcExpression>jsonData._idFun;//解锁条件id
|
||
if(idFun==funcExpression.addBuffCoinNum || idFun==funcExpression.addBuffCoinPer)
|
||
{
|
||
let num = 0
|
||
if (jsonData._param[0] instanceof Object)//excelJson,表达式
|
||
num = this.m_gameFun.doExpressDecode(this,jsonData._param[0],id) as number
|
||
else
|
||
num = jsonData._param[0]
|
||
let bufftp = idFun ==funcExpression.addBuffCoinNum ? buffType.base:buffType.ratio
|
||
if(buffProp)
|
||
buffProp.setBuff(bufftp,num)
|
||
}
|
||
}
|
||
}
|
||
|
||
return true;
|
||
}
|
||
//捕鱼操作,钓鱼对象中找,time表示次数,在线一分钟一次,perOwn:已钓比例,perUnOwn:未钓比例
|
||
doCatchFish(time:number,perOwn:number,perUnOwn:number):catchData{
|
||
let vecAbleFishId = Array<number>()//可钓列表
|
||
let vecCatched = Array<baseObj>()//钓到过
|
||
let vecUnCatched = Array<baseObj>()
|
||
let gofishList = this.findMeans(IDDef.FISHING) as composeObj
|
||
for (let [idkey, valueObj] of gofishList.getMemberMap()) {
|
||
let catchProp = valueObj.getPropByType(propType.catch)
|
||
if(catchProp)
|
||
{
|
||
vecAbleFishId = vecAbleFishId.concat((catchProp as PropCatch).getAble())
|
||
}
|
||
}
|
||
//已钓列表
|
||
for(let idx=0;idx<vecAbleFishId.length;++idx){
|
||
let findObj = this.findMeans(vecAbleFishId[idx])
|
||
if(findObj)
|
||
{
|
||
let fish = findObj as valueObj
|
||
if(fish.getCount()>0)
|
||
vecCatched.push(fish)
|
||
else
|
||
vecUnCatched.push(fish)
|
||
}
|
||
}
|
||
|
||
let allfee = 0
|
||
//perOwn概率捕获已捕获的鱼,perUnOwn概率捕获未捕获的鱼
|
||
let vecNewCatchedId:Array<number>=new Array<number>()
|
||
let mapCatchedId:Map<number,number>=new Map<number,number>()
|
||
function randInt(){
|
||
return Math.round((Math.random()*10000000))
|
||
}
|
||
while(time>0)
|
||
{
|
||
time--;
|
||
if(vecCatched.length==0 && vecUnCatched.length==0)break;//没有可钓鱼
|
||
let cacheIdx = 0
|
||
//没有捕获过鱼,就直接在可捕获中捕获,没有可捕获的,就在已经捕获中捕获。否则按比例捕获
|
||
if(vecCatched.length==0)
|
||
cacheIdx = 1;
|
||
else if(vecUnCatched.length==0)
|
||
cacheIdx = 0;
|
||
else if(randInt()%100<=perOwn)//
|
||
cacheIdx = 0
|
||
else
|
||
cacheIdx = 1
|
||
if(cacheIdx==0)
|
||
{
|
||
let randIdx = randInt()%vecCatched.length;
|
||
let fishId = vecCatched[randIdx].getId()
|
||
let catchedNum = mapCatchedId.get(fishId) || 0
|
||
mapCatchedId.set(fishId,catchedNum+1)
|
||
let arrSale = dataManager.ins().getSaleById(fishId)
|
||
if(arrSale)
|
||
allfee += arrSale._price
|
||
}
|
||
else
|
||
{
|
||
let randIdx = randInt()%vecUnCatched.length;
|
||
let fishId = vecUnCatched[randIdx].getId()
|
||
let findObj = this.findMeans(fishId)
|
||
if(findObj)
|
||
{
|
||
(findObj as valueObj).setCount(1)//钓到过
|
||
vecCatched.push(findObj)
|
||
vecUnCatched.splice(randIdx,1)
|
||
mapCatchedId.set(fishId,1)//新解锁的不能卖
|
||
vecNewCatchedId.push(fishId)
|
||
}
|
||
}
|
||
}
|
||
|
||
return {mapCatched:mapCatchedId,vecNewCatched:vecNewCatchedId,allFee:allfee}
|
||
}
|
||
|
||
//签到
|
||
doSignInByWeekDay(wDay:number){
|
||
let sInProp = this.getPropByType(propType.signIn) as PropSignIn
|
||
if(sInProp.isSignAble(wDay)==true){
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
} |