import { getAtrrNameById, ABI_TYPE_MAIN } from '../../consts'; import { gameData } from '../../pubUtils/data'; import { decodeArrayListStr } from '../../pubUtils/util'; import { ATTRIBUTE } from '../../pubUtils/dicParam'; export class AttributeCal { attrs: Map = new Map(); ce?: number = 0; lv: number = 1; public setLv(lv: number) { this.lv = lv; } public setByWarJson(attributes: {id: number, val: number}[], ratio: number = 1) { for(let {id, val} of attributes) { if(ABI_TYPE_MAIN.includes(id)) { this.attrs.set(id, Math.floor(val * ratio)); } else { this.attrs.set(id, Math.floor(val)); } } } public setByMap( attributes: Map, ratio: number = 1 ) { for(let [id, val] of attributes) { if(ABI_TYPE_MAIN.includes(id)) { this.attrs.set(id, Math.floor(val * ratio)); } else { this.attrs.set(id, Math.floor(val)); } } } private getAttrMap() { let newMap = new Map(); for(let [id, val] of this.attrs) { newMap.set(id, val); } return newMap } public getAttributes() { let attrs = new Attribute(); attrs.setByMap(this.getAttrMap()); return attrs; } public getAttributesToArr() { let arr: {id: number, val: number}[] = []; for(let [id, val] of this.getAttrMap()) { arr.push({ id, val }); } return arr; } public getAttributesToString() { let arr = this.getAttributesToArr(); return arr.map(cur => `${cur.id}&${cur.val}`).join('|'); } public getMainAttributes() { let attribute = this.getAttributes(); return attribute.getMainAttr(); } // 战力计算 // calType 1-全部 2-只算主属性 3-只算次属性 public calCe(calType: number = 1) { let ce = gameData.ceRatio.reduce((pre, cur) => { let { type, val } = cur; if(ABI_TYPE_MAIN.includes(type)) { if(calType == 3) { return 0 } else { return pre + val * (this.attrs.get(type)|| 0) } } else { if(calType == 2) { return 0 } else { return pre + val * (this.attrs.get(type)|| 0) * this.lv / ATTRIBUTE.ATTRIBUTE_POWER_DIVISOR; } } }, 0); return Math.floor(ce); } public calSubAttrCe() { return Math.floor(this.calCe(3)); } } export class Attribute { hp: number = 0; atk: number = 0; def: number = 0; mdef: number = 0; speed: number = 0; hit: number = 0; cri: number = 0; flee: number = 0; antCri: number = 0; damageIncrease: number = 0; damageDecrease: number = 0; defIngnore: number = 0; bloodSuck: number = 0; ap: number = 0; damageCri: number = 0; physicaldamageInc: number = 0; magicdamageInc: number = 0; physicaldamageDec: number = 0; magicdamageDec: number = 0; treatmentInc: number = 0; treatmentDec: number = 0; acceptTreatmentInc: number = 0; acceptTreatmentDec: number = 0; bloodRebound: number = 0; strikeBack: number = 0; setByMap( attributes: Map ) { for(let [id, val] of attributes) { let attrName = getAtrrNameById(id); if(attrName in this) this[attrName] = val; } } setByStr(str: string) { // id&val|... let arr = decodeArrayListStr(str); for(let [id, val] of arr) { let attrName = getAtrrNameById(parseInt(id)); if(attrName in this) this[attrName] = parseInt(val); } } getMainAttr() { return { hp: this.hp, atk: this.atk, def: this.def, mdef: this.mdef } } }