战力:获取显示数据

This commit is contained in:
luying
2022-03-30 14:22:46 +08:00
parent ef731fc979
commit 9adbd08d3c
33 changed files with 205 additions and 1689 deletions

View File

@@ -1,8 +1,6 @@
import { HERO_CE_RATIO, getAtrrNameById, ABI_TYPE_MAIN } from '../../consts';
import { CeAttrDataRole } from '../../db/Role';
import { CeAttrData } from '../../db/Hero';
import { getAtrrNameById, ABI_TYPE_MAIN } from '../../consts';
import { gameData } from '../../pubUtils/data';
import { decodeArrayListStr, reduceCe } from '../../pubUtils/util';
import { decodeArrayListStr } from '../../pubUtils/util';
import { ATTRIBUTE } from '../../pubUtils/dicParam';
export class AttributeCal {
@@ -14,34 +12,12 @@ export class AttributeCal {
this.lv = lv;
}
public setByDbData(roleAttrs: CeAttrDataRole[], heroAttrs: CeAttrData[]) {
for(let { id, fixUp: roleFix, ratioUp: roleRatio } of roleAttrs) {
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);
this.attrs.set(id, value);
} else {
let value = this.calAttrValue(roleFix, roleRatio, 0, 0, 0, 0);
this.attrs.set(id, value);
}
}
for(let { id, base: heroBase, fixUp: heroFix, ratioUp: heroRatio, equipUp: heroEquip } of heroAttrs) {
let roleAttr = roleAttrs.find(roleAttr => roleAttr.id == id);
if(!roleAttr) {
let value = this.calAttrValue(0, 0, heroBase, heroFix, heroRatio, heroEquip);
this.attrs.set(id, value);
}
}
}
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 * HERO_CE_RATIO * HERO_CE_RATIO));
this.attrs.set(id, Math.floor(val * ratio));
} else {
this.attrs.set(id, Math.floor(val * HERO_CE_RATIO * HERO_CE_RATIO));
this.attrs.set(id, Math.floor(val));
}
}
}
@@ -49,58 +25,42 @@ export class AttributeCal {
public setByMap( attributes: Map<number, number>, ratio: number = 1 ) {
for(let [id, val] of attributes) {
if(ABI_TYPE_MAIN.includes(id)) {
this.attrs.set(id, Math.floor(val * ratio * HERO_CE_RATIO * HERO_CE_RATIO));
this.attrs.set(id, Math.floor(val * ratio));
} else {
this.attrs.set(id, Math.floor(val * HERO_CE_RATIO * HERO_CE_RATIO));
this.attrs.set(id, Math.floor(val));
}
}
}
private calAttrValue(roleFix: number = 0, roleRatio: number = 0, heroBase: number = 0, heroFix: number = 0, heroRatio: number = 0, heroEquip: number = 0) {
return (heroFix + heroEquip + roleFix) * HERO_CE_RATIO + heroBase * ( HERO_CE_RATIO + heroRatio + roleRatio );
}
// 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 getReduceAttrMap() {
private getAttrMap() {
let newMap = new Map<number, number>();
for(let [id, val] of this.attrs) {
newMap.set(id, reduceCe(val));
newMap.set(id, val);
}
return newMap
}
public getReduceAttributes() {
public getAttributes() {
let attrs = new Attribute();
attrs.setByMap(this.getReduceAttrMap());
attrs.setByMap(this.getAttrMap());
return attrs;
}
public getReduceAttributesToArr() {
public getAttributesToArr() {
let arr: {id: number, val: number}[] = [];
for(let [id, val] of this.getReduceAttrMap()) {
for(let [id, val] of this.getAttrMap()) {
arr.push({ id, val });
}
return arr;
}
public getReduceAttributesToString() {
let arr = this.getReduceAttributesToArr();
public getAttributesToString() {
let arr = this.getAttributesToArr();
return arr.map(cur => `${cur.id}&${cur.val}`).join('|');
}
public getReduceMainAttributes() {
let attribute = this.getReduceAttributes();
public getMainAttributes() {
let attribute = this.getAttributes();
return attribute.getMainAttr();
}
@@ -126,12 +86,8 @@ export class AttributeCal {
return Math.floor(ce);
}
public calSubAttrCeAndReduce() {
return Math.floor(this.calCe(3) / HERO_CE_RATIO / HERO_CE_RATIO);
}
public calCelAndReduce() {
return Math.floor(this.calCe() / HERO_CE_RATIO / HERO_CE_RATIO);
public calSubAttrCe() {
return Math.floor(this.calCe(3));
}
}

View File

@@ -1,7 +1,6 @@
import { Connect, EPlace, HeroSkin, HeroType, HeroUpdate, Talent } from '../../db/Hero';
import { gameData } from '../../pubUtils/data';
import { reduceCe } from '../../pubUtils/util';
export interface CreateHeroParam extends HeroUpdate {
hid: number;
count: number;
@@ -73,11 +72,7 @@ export class HeroParam {
this.hName = hero.hName;
this.exp = hero.exp;
this.lv = hero.lv;
if(hero.isReducedCe) {
this.ce = hero.ce;
} else {
this.ce = reduceCe(hero.ce);
}
this.ce = hero.ce;
this.star = hero.star;
this.starStage = hero.starStage;
this.colorStar = hero.colorStar;