添加最强五人战力

This commit is contained in:
luying
2020-12-29 16:49:08 +08:00
parent 74c6f19994
commit 315816ea59
11 changed files with 78 additions and 558 deletions

View File

@@ -16,6 +16,7 @@ import { DicRandomEffectPool } from './dictionary/DicRandomEffectPool';
import { getGoodById } from './gamedata';
import { SchoolModel } from '../db/School';
import { getTeraphAttr } from '../consts/constModules/abilityConst'
import { PvpDefenseModel } from '../db/PvpDefense';
const HERO_CE_RATIO = 100;
const _ = require('underscore');
//战力计算TODO
@@ -84,9 +85,10 @@ export function calPlayerCe(globalCeAttr: CeAttrRole, hero: HeroType, type: numb
}
}
let attrNumber = (hero.ceAttr[attrName].fixUp + (hero.ceAttr[attrName].equipUp || 0) + globalAttrData.fixUp) * HERO_CE_RATIO + hero.ceAttr[attrName].base * (HERO_CE_RATIO + hero.ceAttr[attrName].ratioUp + globalAttrData.ratioUp);
console.log(hero.hid, attrNumber, attrName, getAttrCeRatio(attrName))
heroCe += attrNumber * getAttrCeRatio(attrName);
}
let incCe = (heroCe - hero.ce) > 0?heroCe:0;
let incCe = heroCe - hero.ce;
hero.ce = heroCe > 0?heroCe:1;
if (hero.historyCe < hero.ce) hero.historyCe = hero.ce;
return incCe;
@@ -102,9 +104,12 @@ export async function calPlayerCeAndSave(roleId: string, heros: Array<HeroType>,
await reCalRoleAttr(heros, role.globalCeAttr, type, args);
for (let hero of heros) {
let incHeroCe = calPlayerCe(role.globalCeAttr, hero, type, args);
incPlayerCe += incHeroCe;
hero.ce += incHeroCe;
// hero.ce += incHeroCe;
await calculateTopFive(role, hero.hid, hero.ce); // 计算更新最强五人战力
await HeroModel.updateHeroInfo(roleId, hero.hid, hero);
await PvpDefenseModel.updateCe(roleId, hero.hid, hero.ce); // 更新pvp防守阵最强五人战力
pushHeros.push({
hid: hero.hid,
ce: reduceCe(hero.ce),
@@ -112,8 +117,44 @@ export async function calPlayerCeAndSave(roleId: string, heros: Array<HeroType>,
});
}
role.ce += incPlayerCe;
await RoleModel.updateRoleInfo(roleId, { globalCeAttr: role.globalCeAttr, ce: role.ce });
return { pushHeros, role }
let { topFive, topFiveCe } = role;
await RoleModel.updateRoleInfo(roleId, { globalCeAttr: role.globalCeAttr, ce: role.ce, topFive, topFiveCe });
return { pushHeros, role, topFiveCe }
}
async function calculateTopFive(role: RoleType, hid: number, ce: number) {
let topFive = role?.topFive||new Array();
topFive.sort((a, b) => {return b.ce - a.ce}); // 0-5最大-最小
let index = topFive.findIndex(cur => cur.hid == hid);
if(index == -1) { // 不在最强列表
if(topFive.length < 5) { // 不满5人
topFive.push({hid, ce});
} else if(topFive.length == 5){
if(ce > topFive[topFive.length - 1].ce) { // 跻身最强5人
topFive.pop();
topFive.push({hid, ce});
}
} else {
topFive.splice(5, topFive.length - 5);
}
} else { // 原来就是最强5人
if(ce < topFive[topFive.length - 1].ce) { // 滑出最强
let heroes = await HeroModel.getTopHero(role.roleId, 5);
topFive = heroes.map(cur => {return {hid: cur.hid, ce: cur.ce}});
} else {
topFive[index].ce = ce;
}
}
let topFiveCe = topFive.reduce((pre, cur) => {
return pre + cur.ce
}, 0);
role.topFive = topFive;
role.topFiveCe = topFiveCe;
return role;
}
// 初始战力
@@ -229,6 +270,7 @@ export function calHeroStarIncAttr(hero: HeroType, type: number, hid: number, ar
if (!!dicStar && !!dicStar.ceAttr) {
starUp = dicStar.ceAttr.get(stage);
}
let newBase = (heroAttr + hero.lv * (heroUpAttr + starUp)) * HERO_CE_RATIO;
let field = getAtrrNameById(targetAttrId);
let ceAttrData: CeAttrData = ceAttr[field] || new CeAttrData(); // 存表中的属性下的basefixupratioup
@@ -674,8 +716,8 @@ export async function reCalAllHeroCe(roleId: string, type: number, args: Array<n
pushHeros.push({ hid: hero.hid, ce: reduceCe(hero.ce), incHeroCe: reduceCe(incHeroCe) });
await HeroModel.updateHeroInfo(roleId, hero.hid, { ce: hero.ce });
}
await RoleModel.updateRoleInfo(roleId, { globalCeAttr: role.globalCeAttr, ce: role.ce });
return { pushHeros, ce: role.ce }
role = await RoleModel.updateRoleInfo(roleId, { globalCeAttr: role.globalCeAttr, ce: role.ce });
return { pushHeros, ce: role.ce, topFiveCe: role.topFiveCe }
}
function calHeroAddSkin(args: Array<number>, ceAttr: CeAttrRole) {