战斗:远征&pvp,属性字段修改

This commit is contained in:
luying
2021-07-30 16:33:14 +08:00
parent a48706fb8d
commit 6ab6a381e2
9 changed files with 144 additions and 176 deletions

View File

@@ -1,6 +1,6 @@
import { prop } from '@typegoose/typegoose';
import { HERO_CE_RATIO, getAtrrNameById, CE_CONST, HERO_SUB_ATTR_RATIO, ABI_TYPE_MAIN } from '../../consts';
import { reduceCe } from '../../pubUtils/util';
import { decodeArrayListStr, reduceCe } from '../../pubUtils/util';
// hero表内属性基础格式
export class CeAttrData {
@@ -34,107 +34,48 @@ export class CeAttrDataRole {
}
}
// 主属性
export class MainAttrNumber {
hp: number = 0;
atk: number = 0;
def: number = 0;
mdef: number = 0;
constructor(attr: Attribute) {
if(attr.hp) this.hp = attr.hp;
if(attr.atk) this.atk = attr.atk;
if(attr.def) this.def = attr.def;
if(attr.mdef) this.mdef = attr.mdef;
}
}
export class Attribute {
@prop({ required: false })
hp: number = 0;
@prop({ required: false })
atk: number = 0;
@prop({ required: false })
def: number = 0;
@prop({ required: false })
mdef: number = 0;
@prop({ required: false })
speed: number = 0;
@prop({ required: false })
hit: number = 0;
@prop({ required: false })
cri: number = 0;
@prop({ required: false })
flee: number = 0;
@prop({ required: false })
antCri: number = 0;
@prop({ required: false })
damageIncrease: number = 0;
@prop({ required: false })
damageDecrease: number = 0;
@prop({ required: false })
defIngnore: number = 0;
@prop({ required: false })
bloodSuck: number = 0;
@prop({ required: false })
ap: number = 0;
@prop({ required: false })
damageCri: number = 0;
@prop({ required: false })
pDamageInc: number = 0;
@prop({ required: false })
mDamageInc: number = 0;
@prop({ required: false })
pDamageDec: number = 0;
@prop({ required: false })
mDemageDec: number = 0;
@prop({ required: false })
strikeBack: number = 0;
@prop({ required: false })
export class AttributeCal {
attrs: Map<number, number> = new Map<number, number>();
ce?: number = 0;
setByDbData(roleAttrs: CeAttrDataRole[], heroAttrs: CeAttrData[]) {
public setByDbData(roleAttrs: CeAttrDataRole[], heroAttrs: CeAttrData[]) {
for(let { id, fixUp: roleFix, ratioUp: roleRatio } of roleAttrs) {
let attrName = getAtrrNameById(id);
let heroAttr = heroAttrs.find(heroAttr => heroAttr.id == id);
if(heroAttr) {
let { fixUp: heroFix, base: heroBase, ratioUp: heroRatio, equipUp: heroEquip } = heroAttr;
let value = this.calAttrValue(roleFix, roleRatio, heroBase, heroFix, heroRatio, heroEquip);
if(attrName in this) this[attrName] = value;
this.attrs.set(id, value);
} else {
let value = this.calAttrValue(roleFix, roleRatio, 0, 0, 0, 0);
if(attrName in this) this[attrName] = value;
this.attrs.set(id, value);
}
}
for(let { id, base: heroBase, fixUp: heroFix, ratioUp: heroRatio, equipUp: heroEquip } of heroAttrs) {
let attrName = getAtrrNameById(id);
let roleAttr = roleAttrs.find(roleAttr => roleAttr.id == id);
if(!roleAttr) {
let value = this.calAttrValue(0, 0, heroBase, heroFix, heroRatio, heroEquip);
if(attrName in this) this[attrName] = value;
this.attrs.set(id, value);
}
}
}
setByWarJson( attributes: {id: number, val: number}[], ratio: number = 1) {
public setByWarJson( attributes: {id: number, val: number}[], ratio: number = 1) {
for(let {id, val} of attributes) {
let attrName = getAtrrNameById(id);
if(ABI_TYPE_MAIN.includes(id)) {
if(attrName in this) this[attrName] = Math.floor(val * ratio * HERO_CE_RATIO * HERO_CE_RATIO);
this.attrs.set(id, Math.floor(val * ratio * HERO_CE_RATIO * HERO_CE_RATIO));
} else {
if(attrName in this) this[attrName] = Math.floor(val * HERO_CE_RATIO * HERO_CE_RATIO);
this.attrs.set(id, Math.floor(val * HERO_CE_RATIO * HERO_CE_RATIO));
}
}
}
setByMap( attributes: Map<number, number>, ratio: number = 1 ) {
public setByMap( attributes: Map<number, number>, ratio: number = 1 ) {
for(let [id, val] of attributes) {
let attrName = getAtrrNameById(id);
if(ABI_TYPE_MAIN.includes(id)) {
if(attrName in this) this[attrName] = Math.floor(val * ratio * HERO_CE_RATIO * HERO_CE_RATIO);
this.attrs.set(id, Math.floor(val * ratio * HERO_CE_RATIO * HERO_CE_RATIO));
} else {
if(attrName in this) this[attrName] = Math.floor(val * HERO_CE_RATIO * HERO_CE_RATIO);
this.attrs.set(id, Math.floor(val * HERO_CE_RATIO * HERO_CE_RATIO));
}
}
}
@@ -143,62 +84,57 @@ export class Attribute {
return (heroFix + heroEquip + roleFix) * HERO_CE_RATIO + heroBase * ( HERO_CE_RATIO + heroRatio + roleRatio );
}
private getRealSubAttr() {
return {
hit: this.hit / HERO_SUB_ATTR_RATIO / HERO_CE_RATIO / HERO_CE_RATIO,
cri: this.cri / HERO_SUB_ATTR_RATIO / HERO_CE_RATIO / HERO_CE_RATIO,
flee: this.flee / HERO_SUB_ATTR_RATIO / HERO_CE_RATIO / HERO_CE_RATIO,
antCri: this.antCri / HERO_SUB_ATTR_RATIO / HERO_CE_RATIO / HERO_CE_RATIO,
damageIncrease: this.damageIncrease / HERO_SUB_ATTR_RATIO / HERO_CE_RATIO / HERO_CE_RATIO,
damageDecrease: this.damageDecrease / HERO_SUB_ATTR_RATIO / HERO_CE_RATIO / HERO_CE_RATIO,
defIngnore: this.defIngnore / HERO_SUB_ATTR_RATIO / HERO_CE_RATIO / HERO_CE_RATIO,
damageCri: this.damageCri / HERO_SUB_ATTR_RATIO / HERO_CE_RATIO / HERO_CE_RATIO,
pDamageInc: this.pDamageInc / HERO_SUB_ATTR_RATIO / HERO_CE_RATIO / HERO_CE_RATIO,
mDamageInc: this.mDamageInc / HERO_SUB_ATTR_RATIO / HERO_CE_RATIO / HERO_CE_RATIO,
pDamageDec: this.pDamageDec / HERO_SUB_ATTR_RATIO / HERO_CE_RATIO / HERO_CE_RATIO,
mDemageDec: this.mDemageDec / HERO_SUB_ATTR_RATIO / HERO_CE_RATIO / HERO_CE_RATIO,
strikeBack: this.strikeBack / HERO_SUB_ATTR_RATIO / HERO_CE_RATIO / HERO_CE_RATIO
private getRealAttrToMap() {
let newMap = new Map<number, number>();
for(let [id, val] of this.attrs) {
if(ABI_TYPE_MAIN.includes(id)) { // 主属性
newMap.set(id, val / HERO_CE_RATIO / HERO_CE_RATIO);
} else {
newMap.set(id, val / HERO_SUB_ATTR_RATIO / HERO_CE_RATIO / HERO_CE_RATIO);
}
}
return newMap;
}
private getRealMainAttr() {
return {
hp: this.hp / HERO_CE_RATIO / HERO_CE_RATIO,
atk: this.atk / HERO_CE_RATIO / HERO_CE_RATIO,
def: this.def / HERO_CE_RATIO / HERO_CE_RATIO,
mdef: this.mdef / HERO_CE_RATIO / HERO_CE_RATIO
private getReduceAttrMap() {
let newMap = new Map<number, number>();
for(let [id, val] of this.attrs) {
newMap.set(id, reduceCe(val));
}
return newMap
}
public getReduceAttributes() {
let newAttr = new Attribute();
newAttr.hp = reduceCe(this.hp);
newAttr.atk = reduceCe(this.atk);
newAttr.def = reduceCe(this.def);
newAttr.mdef = reduceCe(this.mdef);
newAttr.speed = reduceCe(this.speed);
newAttr.hit = reduceCe(this.hit);
newAttr.cri = reduceCe(this.cri);
newAttr.flee = reduceCe(this.flee);
newAttr.antCri = reduceCe(this.antCri);
newAttr.damageIncrease = reduceCe(this.damageIncrease);
newAttr.damageDecrease = reduceCe(this.damageDecrease);
newAttr.defIngnore = reduceCe(this.defIngnore);
newAttr.bloodSuck = reduceCe(this.bloodSuck);
newAttr.ap = reduceCe(this.ap);
newAttr.damageCri = reduceCe(this.damageCri);
newAttr.pDamageInc = reduceCe(this.pDamageInc);
newAttr.mDamageInc = reduceCe(this.mDamageInc);
newAttr.pDamageDec = reduceCe(this.pDamageDec);
newAttr.mDemageDec = reduceCe(this.mDemageDec);
newAttr.strikeBack = reduceCe(this.strikeBack);
return newAttr;
let attrs = new Attribute();
attrs.setByMap(this.getReduceAttrMap());
return attrs;
}
public getReduceAttributesToArr() {
let arr: {id: number, val: number}[] = [];
for(let [id, val] of this.getReduceAttrMap()) {
arr.push({ id, val });
}
return arr;
}
public getReduceAttributesToString() {
let arr = this.getReduceAttributesToArr();
return arr.map(cur => `${cur.id}&${cur.val}`).join('|');
}
public getReduceMainAttributes() {
let attribute = this.getReduceAttributes();
return attribute.getMainAttr();
}
// 战力计算
public calCe() {
let { hp, atk, def, mdef } = this.getRealMainAttr();
let { cri, flee, damageIncrease, damageDecrease, damageCri } = this.getRealSubAttr();
let attrMap = this.getRealAttrToMap();
let attrs = new Attribute();
attrs.setByMap(attrMap);
let { hp, atk, def, mdef, cri, flee, damageIncrease, damageDecrease, damageCri } = attrs;
let putHit = CE_CONST.PUT_HIT / HERO_SUB_ATTR_RATIO;
let putAntCri = CE_CONST.PUT_ANT_CRI / HERO_SUB_ATTR_RATIO;
@@ -222,11 +158,66 @@ export class Attribute {
// 计算未装备的装备的简易战力公式
public calEquipCe() {
let { hp, atk, def, mdef } = this.getRealMainAttr();
let attrMap = this.getRealAttrToMap();
let attrs = new Attribute();
attrs.setByMap(attrMap);
let { hp, atk, def, mdef } = attrs;
return hp * 1 + atk * 3 + def * 2 + mdef * 2;
}
public calCelAndReduce() {
return Math.floor(this.calCe() / HERO_CE_RATIO / HERO_CE_RATIO);
}
}
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<number, number> ) {
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
}
}
}