后台:添加武将,装备,道具

This commit is contained in:
luying
2021-01-28 12:01:26 +08:00
parent 72a089b179
commit b880962f02
12 changed files with 428 additions and 58 deletions
+23 -16
View File
@@ -20,6 +20,7 @@ import { PvpDefenseModel } from '../db/PvpDefense';
const HERO_CE_RATIO = 100;
import { findIndex } from 'underscore';
import { GuildModel } from '../db/Guild';
//战力计算TODO
export function calPlayerCe(globalCeAttr: CeAttrRole, hero: HeroType, type: number, args: Array<number> = []) {
let heroCe = 0;
@@ -123,31 +124,37 @@ export async function calPlayerCeAndSave(roleId: string, heros: Array<HeroType>,
return { pushHeros, role, topFiveCe }
}
async function calculateTopFive(role: RoleType, hid: number, ce: number, heroId: string) {
export 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, hero: heroId });
} else if (topFive.length == 5) {
if (ce > topFive[topFive.length - 1].ce) { // 跻身最强5人
topFive.pop();
if(index != -1 && !heroId) {
let heroes = await HeroModel.getTopHero(role.roleId, 5);
topFive = heroes.map(cur => { return { hid: cur.hid, ce: cur.ce, hero: cur._id } });
} else {
if (index == -1) { // 不在最强列表
if (topFive.length < 5) { // 不满5人
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, hero: heroId });
}
} 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, hero: cur._id } });
} else {
topFive[index].ce = 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, hero: cur._id } });
} else {
topFive[index].ce = ce;
}
}
let topFiveCe = topFive.reduce((pre, cur) => {
return pre + cur.ce
}, 0);