Merge branch 'feature/ce'
This commit is contained in:
@@ -4,7 +4,7 @@ import { DungeonFirstType } from '../../db/DungeonFirst';
|
||||
class DungeonUserInfo extends RankParam {
|
||||
roleId: string;
|
||||
constructor(roleId: string, userInfo: RankParam) {
|
||||
super(userInfo, false);
|
||||
super(userInfo);
|
||||
this.roleId = roleId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { EXTERIOR } from "../pubUtils/dicParam";
|
||||
import { WoodenHorse } from "./battleField/guildActivity";
|
||||
import { RoleUpdate, RoleType } from "../db/Role";
|
||||
import { reduceCe } from "../pubUtils/util";
|
||||
import { GuildUpdateParam } from "../db/Guild";
|
||||
import { HeroUpdate, } from "../db/Hero";
|
||||
import { getSeconds } from "../pubUtils/timeUtil";
|
||||
@@ -38,7 +37,7 @@ export class RankParam {
|
||||
@prop({ required: true })
|
||||
updatedAt?: number = 0;
|
||||
|
||||
constructor(role: RoleUpdate|RankParam, fromDb: boolean) {
|
||||
constructor(role: RoleUpdate|RankParam) {
|
||||
if(role.roleName) this.roleName = role.roleName;
|
||||
if(role.lv) this.lv = role.lv;
|
||||
if(role.head) this.head = role.head;
|
||||
@@ -46,13 +45,7 @@ export class RankParam {
|
||||
if(role.spine) this.spine = role.spine;
|
||||
if(role.title) this.title = role.title;
|
||||
if(role.guildName) this.guildName = role.guildName||"";
|
||||
if(role.ce) {
|
||||
if(fromDb && !(<RoleUpdate>role).isReducedCe) {
|
||||
this.ce = reduceCe(role.ce);
|
||||
} else {
|
||||
this.ce = role.ce;
|
||||
}
|
||||
}
|
||||
if(role.ce) this.ce = role.ce;
|
||||
if(role.updatedAt) {
|
||||
if(typeof role.updatedAt == 'number') {
|
||||
this.updatedAt = role.updatedAt;
|
||||
@@ -178,27 +171,14 @@ export class GuildRankParam {
|
||||
@prop({ required: true })
|
||||
guildCe: number;
|
||||
|
||||
constructor(guild: GuildUpdateParam, fromDb: boolean) {
|
||||
constructor(guild: GuildUpdateParam) {
|
||||
this.icon = guild.icon;
|
||||
this.name = guild.name;
|
||||
this.lv = guild.lv;
|
||||
let leader = <RoleType>guild.leader;
|
||||
let _leader = new GuildLeader(leader);
|
||||
this.leader = _leader;
|
||||
// console.log('*****', guild.isReducedCe, guild.guildCe, reduceCe(guild.guildCe))
|
||||
if(guild.isReducedCe) {
|
||||
this.guildCe = guild.guildCe;
|
||||
} else {
|
||||
this.guildCe = reduceCe(guild.guildCe);
|
||||
}
|
||||
|
||||
if(fromDb && !(<GuildUpdateParam>guild).isReducedCe) {
|
||||
this.guildCe = reduceCe(guild.guildCe);
|
||||
} else {
|
||||
this.guildCe = guild.guildCe;
|
||||
}
|
||||
|
||||
|
||||
this.guildCe = guild.guildCe;
|
||||
this.memberCnt = guild.memberCnt;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,249 +0,0 @@
|
||||
import { ABI_STAGE, ABI_STAGE_TO_TYPE, ABI_TYPE, ABI_TYPE_MAIN, HERO_CE_RATIO, HERO_SYSTEM_TYPE, SEID_TYPE } from "../../consts";
|
||||
import { HeroModel, HeroUpdate, CeAttrData } from "../../db/Hero";
|
||||
import { CeAttrDataRole, RoleUpdate } from "../../db/Role";
|
||||
import { gameData, getHeroStarByQuality, getHeroWakeByQuality } from "../../pubUtils/data";
|
||||
import { DicRandomEffectPool } from "../../pubUtils/dictionary/DicRandomEffectPool";
|
||||
import { DicSe } from "../../pubUtils/dictionary/DicSe";
|
||||
import { deepCopy } from "../../pubUtils/util";
|
||||
import { AttributeCal } from "./attribute";
|
||||
|
||||
export class CalRoleCe {
|
||||
private roleInfo: RoleUpdate;
|
||||
private roleCeWithAttr: Map<ABI_TYPE, CeAttrDataRole> = new Map();
|
||||
|
||||
constructor(roleInfo?: RoleUpdate) {
|
||||
this.roleInfo = roleInfo;
|
||||
}
|
||||
|
||||
public cal(type: HERO_SYSTEM_TYPE) {
|
||||
switch (type) {
|
||||
case HERO_SYSTEM_TYPE.INIT:
|
||||
this.calTitleAbility();
|
||||
this.calTeraphMainAttr();
|
||||
break;
|
||||
}
|
||||
return this.getRoleAttr();
|
||||
}
|
||||
|
||||
private calTitleAbility() {
|
||||
let { title } = this.roleInfo;
|
||||
|
||||
let dicTitle = gameData.title.get(title)||{ mainAttrValue: new Map(), assiAttrValue: new Map() };
|
||||
|
||||
for (let i = ABI_TYPE.ABI_HP; i < ABI_TYPE.ABI_MAX; i++) {
|
||||
if (dicTitle.mainAttrValue.has(i)) {
|
||||
let fixUp = dicTitle.mainAttrValue.get(i) || 0;
|
||||
this.getSingleAttrObj(i).updateAttr({ inc: { fixUp } });
|
||||
}
|
||||
if (dicTitle.assiAttrValue.has(i)) {
|
||||
let fixUp = dicTitle.assiAttrValue.get(i) || 0;
|
||||
this.getSingleAttrObj(i).updateAttr({ inc: { fixUp } });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private calTeraphMainAttr(id?: number) {
|
||||
let { teraphs = [] } = this.roleInfo;
|
||||
for(let teraph of teraphs) {
|
||||
if(id == undefined || teraph.id == id) {
|
||||
for(let [attrId, val] of teraph.attr) {
|
||||
this.getSingleAttrObj(attrId).updateAttr({ inc: { fixUp: val } });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 获取一个CeAttrData对象,没有就新建
|
||||
public getSingleAttrObj(attrId: ABI_TYPE) {
|
||||
if(!this.roleCeWithAttr.has(attrId)) {
|
||||
let calSingleAttr = new CeAttrDataRole(attrId);
|
||||
this.roleCeWithAttr.set(attrId, calSingleAttr);
|
||||
}
|
||||
return this.roleCeWithAttr.get(attrId);
|
||||
}
|
||||
|
||||
private getRoleAttr() {
|
||||
let attr: CeAttrDataRole[] = [];
|
||||
this.roleCeWithAttr.forEach(value => {
|
||||
if(value.ratioUp > 0 || value.fixUp > 0) {
|
||||
attr.push(value);
|
||||
}
|
||||
});
|
||||
return attr;
|
||||
}
|
||||
}
|
||||
|
||||
export class CalHeroCe {
|
||||
private hid: number;
|
||||
private heroInfo: HeroUpdate;
|
||||
private heroCeWithAttr: Map<ABI_TYPE, CeAttrData> = new Map();
|
||||
|
||||
constructor(hid: number, heroInfo?: HeroUpdate) {
|
||||
this.hid = hid;
|
||||
if(heroInfo) this.heroInfo = heroInfo;
|
||||
}
|
||||
|
||||
public async setHeroInfoByHid(roleId: string) {
|
||||
let hero = await HeroModel.findByHidAndRole(this.hid, roleId);
|
||||
this.heroInfo = hero;
|
||||
}
|
||||
|
||||
// 主要接口
|
||||
public cal(type: HERO_SYSTEM_TYPE) {
|
||||
switch (type) {
|
||||
case HERO_SYSTEM_TYPE.INIT:
|
||||
case HERO_SYSTEM_TYPE.REBIRTH:
|
||||
this.calBaseAbility();
|
||||
this.calSkinSeid();
|
||||
this.calJobAbility();
|
||||
break;
|
||||
}
|
||||
return this.getHeroAttr()
|
||||
}
|
||||
|
||||
// 计算基础属性
|
||||
private calBaseAbility() {
|
||||
let { star, starStage, quality, colorStar, colorStarStage, lv, skinId } = this.heroInfo;
|
||||
const dicHero = gameData.hero.get(skinId);
|
||||
if(!dicHero) {
|
||||
console.error(`not found hero: ${skinId}`);
|
||||
return;
|
||||
}
|
||||
|
||||
for (let stage = ABI_STAGE.START + 1; stage <= ABI_STAGE.END; stage++) {
|
||||
let attrId = ABI_STAGE_TO_TYPE.get(stage);
|
||||
|
||||
const isWake = colorStar > 0; // 是否觉醒,只要激活了觉醒,彩星就会 > 1
|
||||
// console.log('*isUpstar', isUpStar, originStar, star, originColorStar, colorStar)
|
||||
|
||||
const dicStar = isWake ? getHeroWakeByQuality(dicHero.jobClass, dicHero.quality, colorStarStage < stage? colorStar - 1: colorStar) : getHeroStarByQuality(dicHero.jobClass, quality, starStage < stage? star - 1: star); // 星级表
|
||||
|
||||
let heroAttr = dicHero.baseAbilityArr.get(attrId); // 武将表hp等
|
||||
let heroUpAttr = dicHero.baseAbilityUpArr.get(attrId); // 武将表hp_up等
|
||||
let starUp = 0; // 星级成长
|
||||
if (!!dicStar && !!dicStar.ceAttr) {
|
||||
starUp = dicStar.ceAttr.get(stage);
|
||||
}
|
||||
let base = heroAttr + lv * (heroUpAttr + starUp);
|
||||
this.getSingleAttrObj(attrId).updateAttr({ set: { base } });
|
||||
};
|
||||
}
|
||||
|
||||
// 计算职业属性
|
||||
private calJobAbility() {
|
||||
let { job, jobStage } = this.heroInfo;
|
||||
|
||||
const dicJob = gameData.job.get(job);
|
||||
for(let i = 1; i <= dicJob.maxStage; i++) {
|
||||
if(jobStage >= i) {
|
||||
let { id, attr } = dicJob.ceAttr.get(i);
|
||||
this.getSingleAttrObj(id).updateAttr({ inc: { fixUp: attr } });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 计算皮肤属性
|
||||
private calSkinSeid() {
|
||||
let { skinId, star: _star, colorStar: _colorStar } = this.heroInfo;
|
||||
|
||||
let seidList = new Map<number, number>(); // type => seid
|
||||
let dicHero = gameData.hero.get(skinId);
|
||||
let { starSeidArr, colorStarSeidArr } = gameData.heroSkill.get(dicHero.skill);
|
||||
for (let { star, value, type } of starSeidArr) {
|
||||
if (_star >= star) {
|
||||
seidList.set(type, value);
|
||||
}
|
||||
}
|
||||
for (let { star, value, type } of colorStarSeidArr) {
|
||||
if (_colorStar >= star) {
|
||||
seidList.set(type, value);
|
||||
}
|
||||
}
|
||||
let list: number[] = [];
|
||||
for(let [_type, value] of seidList) list.push(value);
|
||||
addSeidEffect.bind(this, list);
|
||||
}
|
||||
|
||||
public getHeroAttr() {
|
||||
let attr: CeAttrData[] = [];
|
||||
this.heroCeWithAttr.forEach(value => {
|
||||
if(value.base > 0 || value.equipUp > 0 || value.fixUp > 0 || value.ratioUp > 0) {
|
||||
attr.push(value);
|
||||
}
|
||||
});
|
||||
return attr;
|
||||
}
|
||||
|
||||
// 获取一个CeAttrData对象,没有就新建
|
||||
public getSingleAttrObj(attrId: ABI_TYPE) {
|
||||
if(!this.heroCeWithAttr.has(attrId)) {
|
||||
let calSingleAttr = new CeAttrData(attrId);
|
||||
this.heroCeWithAttr.set(attrId, calSingleAttr);
|
||||
}
|
||||
return this.heroCeWithAttr.get(attrId);
|
||||
}
|
||||
|
||||
public getCalculatedCe(roleAttr: CeAttrDataRole[]) {
|
||||
let attrCal = new AttributeCal();
|
||||
attrCal.setLv(this.heroInfo.lv);
|
||||
attrCal.setByDbData(roleAttr, this.getHeroAttr());
|
||||
return attrCal.calCe();
|
||||
}
|
||||
}
|
||||
|
||||
// 添加技能增加的被动属性
|
||||
function addSeidEffect(this: CalRoleCe|CalHeroCe, seidList: number[]) {
|
||||
// console.log('******addSeidEffect',this, seidList)
|
||||
|
||||
// console.log('addSeidList', addSeidList.join())
|
||||
// console.log('removeSeidList', removeSeidList.join())
|
||||
let effectList: DicSe[] = []; // any: dic_zyz_se表内容
|
||||
|
||||
for (let ii = 0; ii < seidList.length; ii += 2) {
|
||||
let seid = seidList[ii];
|
||||
let rand = seidList[ii + 1] || 0;
|
||||
let dicSeid: DicSe | DicRandomEffectPool = gameData.se.get(seid);
|
||||
if (!dicSeid) dicSeid = gameData.randomEffectPool.get(seid);
|
||||
if (dicSeid && dicSeid.id > 0) {
|
||||
addSeid(effectList, dicSeid.id, rand, dicSeid.gainValueArr)
|
||||
}
|
||||
}
|
||||
|
||||
// console.log('effectList', JSON.stringify(effectList));
|
||||
for (let { type, gainValueArr: [ability, value] } of effectList) {
|
||||
if (type == SEID_TYPE.TYPE101) { // 加值
|
||||
this.getSingleAttrObj(ability).updateAttr({ inc: { fixUp: value } });
|
||||
} else if (type == SEID_TYPE.TYPE103) { // 主属性加百分比
|
||||
if(ABI_TYPE_MAIN.includes(ability)) {
|
||||
this.getSingleAttrObj(ability).updateAttr({ inc: {ratioUp: value / 1000} });
|
||||
}
|
||||
} else if (type == SEID_TYPE.TYPE104) { // 次级属性加百分比
|
||||
if(!ABI_TYPE_MAIN.includes(ability)) {
|
||||
this.getSingleAttrObj(ability).updateAttr({ inc: { fixUp: value * 100 * HERO_CE_RATIO } });
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 获取dic_zyz_se内容
|
||||
function addSeid(effectList: (DicSe | DicRandomEffectPool)[], seidId: number, rand: number, seidValue: number[] = []) {
|
||||
let curSeid: DicSe | DicRandomEffectPool = gameData.se.get(seidId);
|
||||
if (!curSeid) curSeid = gameData.randomEffectPool.get(seidId);
|
||||
if (!curSeid) { console.log("seidId not found:" + seidId); return; }
|
||||
if (!seidValue) seidValue = curSeid.gainValueArr;
|
||||
|
||||
if (curSeid.type === SEID_TYPE.TYPE999) {
|
||||
for (let i = 0; i < seidValue.length; i++) {
|
||||
addSeid(effectList, seidValue[i], rand);
|
||||
}
|
||||
return;
|
||||
}
|
||||
let seid: DicSe | DicRandomEffectPool = deepCopy(curSeid);
|
||||
if (curSeid.index > 0) {
|
||||
seid.gainValueArr[curSeid.index - 1] = rand;
|
||||
}
|
||||
effectList.push(seid);
|
||||
}
|
||||
@@ -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;
|
||||
@@ -41,7 +40,6 @@ export class HeroParam {
|
||||
exp: number; // 经验值
|
||||
lv: number; // 武将等级
|
||||
ce: number; // 武将战力
|
||||
historyCe: number; // 武将历史最高战力
|
||||
star: number; // 星级
|
||||
starStage: number; // 星级六维阶段
|
||||
colorStar: number; // 觉醒, 彩星
|
||||
@@ -74,13 +72,7 @@ export class HeroParam {
|
||||
this.hName = hero.hName;
|
||||
this.exp = hero.exp;
|
||||
this.lv = hero.lv;
|
||||
if(hero.isReducedCe) {
|
||||
this.ce = hero.ce;
|
||||
this.historyCe = hero.historyCe;
|
||||
} else {
|
||||
this.ce = reduceCe(hero.ce);
|
||||
this.historyCe = reduceCe(hero.historyCe);
|
||||
}
|
||||
this.ce = hero.ce;
|
||||
this.star = hero.star;
|
||||
this.starStage = hero.starStage;
|
||||
this.colorStar = hero.colorStar;
|
||||
|
||||
Reference in New Issue
Block a user