全局修改:topFive字段

This commit is contained in:
luying
2021-02-24 13:23:55 +08:00
parent 47c3c093f2
commit 56efab8cb7
17 changed files with 224 additions and 224 deletions

View File

@@ -323,9 +323,9 @@ export function getFuncsSwitch(id:number) {
export function getPLvByScore(score: number) {
let lv = 0;
for(let {teamLv, topFiveMin, topFiveMax} of gameData.pvpTeamLevel) {
if(score >= topFiveMin) lv = teamLv;
if(score < topFiveMax) break;
for(let {teamLv, topLineupMin, topLineupMax} of gameData.pvpTeamLevel) {
if(score >= topLineupMin) lv = teamLv;
if(score < topLineupMax) break;
}
return lv;
}

View File

@@ -8,9 +8,9 @@ export interface DicPvpTeamLevel {
// 队伍等级
readonly teamLv: number;
// 最高五人军功和下限
readonly topFiveMin: number;
readonly topLineupMin: number;
// 最高五人军功和上限
readonly topFiveMax: number;
readonly topLineupMax: number;
}
const str = readJsonFile(FILENAME.DIC_PVP_TEAM_LEVEL);

View File

@@ -108,7 +108,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, hero._id); // 计算更新最强五人战力
await calculatetopLineup(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({
@@ -118,49 +118,49 @@ export async function calPlayerCeAndSave(roleId: string, heros: Array<HeroType>,
});
}
role.ce += incPlayerCe;
let { topFive, topFiveCe } = role;
await RoleModel.updateRoleInfo(roleId, { globalCeAttr: role.globalCeAttr, ce: role.ce, topFive, topFiveCe });
let { topLineup, topLineupCe } = role;
await RoleModel.updateRoleInfo(roleId, { globalCeAttr: role.globalCeAttr, ce: role.ce, topLineup, topLineupCe });
await GuildModel.updateCe(roleId, incPlayerCe);
return { pushHeros, role, topFiveCe }
return { pushHeros, role, topLineupCe }
}
export async function calculateTopFive(role: RoleType, hid: number, ce: number, heroId: string) {
let topFive = role?.topFive || new Array();
export async function calculatetopLineup(role: RoleType, hid: number, ce: number, heroId: string) {
let topLineup = role?.topLineup || new Array();
topFive.sort((a, b) => { return b.ce - a.ce }); // 0-6最大-最小
let index = topFive.findIndex(cur => cur.hid == hid);
topLineup.sort((a, b) => { return b.ce - a.ce }); // 0-6最大-最小
let index = topLineup.findIndex(cur => cur.hid == hid);
if(index != -1 && !heroId) {
let heroes = await HeroModel.getTopHero(role.roleId, 6);
topFive = heroes.map(cur => { return { hid: cur.hid, ce: cur.ce, hero: cur._id } });
topLineup = heroes.map(cur => { return { hid: cur.hid, ce: cur.ce, hero: cur._id } });
} else {
if (index == -1) { // 不在最强列表
if (topFive.length < 6) { // 不满6人
topFive.push({ hid, ce, hero: heroId });
} else if (topFive.length == 6) {
if (ce > topFive[topFive.length - 1].ce) { // 跻身最强6人
topFive.pop();
topFive.push({ hid, ce, hero: heroId });
if (topLineup.length < 6) { // 不满6人
topLineup.push({ hid, ce, hero: heroId });
} else if (topLineup.length == 6) {
if (ce > topLineup[topLineup.length - 1].ce) { // 跻身最强6人
topLineup.pop();
topLineup.push({ hid, ce, hero: heroId });
}
} else {
topFive.splice(6, topFive.length - 6);
topLineup.splice(6, topLineup.length - 6);
}
} else { // 原来就是最强6人
if (ce < topFive[topFive.length - 1].ce) { // 滑出最强
if (ce < topLineup[topLineup.length - 1].ce) { // 滑出最强
let heroes = await HeroModel.getTopHero(role.roleId, 6);
topFive = heroes.map(cur => { return { hid: cur.hid, ce: cur.ce, hero: cur._id } });
topLineup = heroes.map(cur => { return { hid: cur.hid, ce: cur.ce, hero: cur._id } });
} else {
topFive[index].ce = ce;
topLineup[index].ce = ce;
}
}
}
let topFiveCe = topFive.reduce((pre, cur) => {
let topLineupCe = topLineup.reduce((pre, cur) => {
return pre + cur.ce
}, 0);
role.topFive = topFive;
role.topFiveCe = topFiveCe;
role.topLineup = topLineup;
role.topLineupCe = topLineupCe;
return role;
}
@@ -706,7 +706,7 @@ export async function reCalAllHeroCe(roleId: string, type: number, args: Array<n
await HeroModel.updateHeroInfo(roleId, hero.hid, { ce: hero.ce });
}
role = await RoleModel.updateRoleInfo(roleId, { globalCeAttr: role.globalCeAttr, ce: role.ce });
return { pushHeros, ce: role.ce, topFiveCe: role.topFiveCe }
return { pushHeros, ce: role.ce, topLineupCe: role.topLineupCe }
}
function calHeroAddSkin(args: Array<number>, ceAttr: CeAttrRole) {