pvp创建获取

This commit is contained in:
mamengke01
2021-01-06 16:06:31 +08:00
parent d2f76c9198
commit a785a4733a
17 changed files with 189 additions and 71 deletions
+4 -4
View File
@@ -106,7 +106,7 @@ export async function calPlayerCeAndSave(roleId: string, heros: Array<HeroType>,
let incHeroCe = calPlayerCe(role.globalCeAttr, hero, type, args);
incPlayerCe += incHeroCe;
await calculateTopFive(role, hero.hid, hero.ce); // 计算更新最强五人战力
await calculateTopFive(role, hero.hid, hero.ce, hero._id); // 计算更新最强五人战力
await HeroModel.updateHeroInfo(roleId, hero.hid, hero);
await PvpDefenseModel.updateCe(roleId, hero.hid, hero.ce); // 更新pvp防守阵最强五人战力
pushHeros.push({
@@ -121,18 +121,18 @@ export async function calPlayerCeAndSave(roleId: string, heros: Array<HeroType>,
return { pushHeros, role, topFiveCe }
}
async function calculateTopFive(role: RoleType, hid: number, ce: number) {
async function calculateTopFive(role: RoleType, hid: number, ce: number, heroId: string) {
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 });
topFive.push({ hid, ce, hero: heroId });
} else if (topFive.length == 5) {
if (ce > topFive[topFive.length - 1].ce) { // 跻身最强5人
topFive.pop();
topFive.push({ hid, ce });
topFive.push({ hid, ce, hero: heroId });
}
} else {
topFive.splice(5, topFive.length - 5);