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
+5
View File
@@ -247,3 +247,8 @@ export function getSuit(id: number) {
const suitInfo = gameData.suit.get(id);
return suitInfo;
}
export function getFuncsSwitch(id:number) {
const funcInfo = gameData.funcsSwitch.get(id);
return funcInfo;
}
+2 -2
View File
@@ -19,7 +19,7 @@ export interface DicFuncSwitch {
const str = readJsonFile(FILENAME.DIC_FUNC_SWITCH);
let arr = JSON.parse(str);
export const dicFuncSwitch = new Array<DicFuncSwitch>();
export const dicFuncSwitch = new Map<number, DicFuncSwitch>();
arr.forEach(o => {
dicFuncSwitch.push(o);
dicFuncSwitch.set(o.id, o);
});
+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);
+35
View File
@@ -0,0 +1,35 @@
/**
* 体力系统
*/
import { PvpDefenseModel, Heroes, OppPlayers } from '../db/pvpDefense';
import { RoleType } from '../db/Role';
export async function initPvpInfo(role: RoleType) {
let heroes: Array<Heroes> = [];
//初始化最强5人阵容
for (let i = 1; i <= role.topFive.length; i++) {
let item = role.topFive[i - 1];
if (item.hid) {
heroes.push({
actorId: item.hid,
hero: item.hero,
ce: item.ce,
pos: i,
order: i,
});
}
}
//初始化对手人阵容TODO
let oppPlayers: Array<OppPlayers> = [];
let result = await PvpDefenseModel.createPvpDefense({ roleId: role.roleId, roleName: role.roleName, heroes, oppPlayers, defCe: role.topFiveCe });
//加入排行榜 TODO
return result;
}
export async function checkPvp(role: RoleType) {
let result = await PvpDefenseModel.findByRoleId(role.roleId);
if (!!result)
return result;
result = await initPvpInfo(role);
return result;
}