pvp保存阵容

This commit is contained in:
mamengke01
2021-01-07 20:36:30 +08:00
parent 5bfac1723c
commit 2470f7582f
8 changed files with 119 additions and 36 deletions
+45 -11
View File
@@ -10,21 +10,22 @@ import { getRandomIndexByLen, genCode, getRandomByLen } from '../pubUtils/util';
import { oppPlayersInter } from '../pubUtils/interface';
import { gameData, getPLvByScore } from "../pubUtils/data";
import { PVP } from '../pubUtils/dicParam';
const _ = require('underscore');
export async function initPvpInfo(role: RoleType) {
let heroes: Array<Heroes> = [];
//初始化最强5人阵容
for (let i = 0; i < role.topFive.length; i++) {
let item = role.topFive[i];
if (item.hid) {
heroes.push({
actorId: item.hid,
hero: item.hero,
ce: item.ce,
dataId: PVP_HERO_POS.START + i,
order: i + 1,
});
}
for (let i = PVP_HERO_POS.START; i <= PVP_HERO_POS.END; i++) {
let index = i - PVP_HERO_POS.START;
let item = role.topFive[index];
heroes.push({
actorId: item?.hid||0,
hero: item?.hero||null,
ce: item?.ce||0,
dataId: i,
order: index + 1,
});
}
//初始化对手人阵容
let oppPlayers: Array<OppPlayers> = await refreshEnemies(role, 0, 1);
@@ -170,4 +171,37 @@ export function getLvByScore(heroScores: HeroScores[]) {
score += heroScores[i].score;
}
return getPLvByScore(score);
}
export async function defaultHeroes ( role:RoleType) {
let { heroes } = await PvpDefenseModel.findByRoleId(role.roleId);
heroes.sort(function(a, b) {
return a.ce + a.dataId - b.ce + b.dataId;
});
role.topFive.sort(function(a, b) {
return a.ce - b.ce;
});
let defCe = 0;
for (let i = 1; i < role.topFive.length; i++) {
let item = role.topFive[i];
if (!_.findWhere(heroes, {actorId: item.hid})) {
for (let j = 0; j < heroes.length; j++) {
let hero = heroes[j];
if (heroes.length >= 5 && !hero.actorId) {
continue;
}
let index = _.findIndex(role.topFive,{hid: hero.actorId});
if (index == -1) {
hero.actorId = item.hid;
hero.hero = item.hero||'';
hero.ce = item.ce||0;
} else {
heroes[index].ce = item.ce||0;
}
}
}
defCe += item.ce;
}
let { heroes: resHeroes} = await PvpDefenseModel.updateInfo(role.roleId, {defCe, heroes});
return { resHeroes};
}