添加最强五人战力
This commit is contained in:
@@ -71,9 +71,8 @@ export default class PvpDefense extends BaseModel {
|
||||
|
||||
}
|
||||
|
||||
public static async updateCe(roleId: string, hid: number, ce: number, oldCe: number, lean = true) {
|
||||
let distance = ce - oldCe;
|
||||
const rec: PvpDefenseType = await PvpDefenseModel.findOneAndUpdate({roleId, 'heroes.actorId': hid}, {$inc: {ce: distance}}).lean(lean);
|
||||
public static async updateCe(roleId: string, hid: number, ce: number, lean = true) {
|
||||
const rec: PvpDefenseType = await PvpDefenseModel.findOneAndUpdate({roleId, 'heroes.actorId': hid}, {$set: { ce }}).lean(lean);
|
||||
return rec
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import { CeAttrRole } from './generalField';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
import User from './User';
|
||||
import { shouldRefresh } from '../pubUtils/util';
|
||||
import { HeroModel } from './Hero';
|
||||
import { initRoleAtrr } from '../pubUtils/playerCe';
|
||||
interface roleUpdate {
|
||||
ce?: number;
|
||||
@@ -16,6 +15,8 @@ interface roleUpdate {
|
||||
globalCeAttr?:CeAttrRole;
|
||||
title?:number;
|
||||
teraphs?: Teraph[];
|
||||
topFive?: TopHero[];
|
||||
topFiveCe?: number;
|
||||
}
|
||||
|
||||
class TopHero {
|
||||
@@ -382,41 +383,6 @@ export default class Role extends BaseModel {
|
||||
return ranks;
|
||||
}
|
||||
|
||||
public static async updateSumCe(roleId: string, hid: number, ce: number, oldCe: number, lean = true) {
|
||||
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
let topFive = role?.topFive||new Array();
|
||||
let distance = ce - oldCe;
|
||||
|
||||
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});
|
||||
} else if(topFive.length == 5){
|
||||
if(ce > topFive[topFive.length - 1].ce) { // 跻身最强5人
|
||||
topFive.pop();
|
||||
topFive.push({hid, ce});
|
||||
}
|
||||
} else {
|
||||
topFive.splice(5, topFive.length - 5);
|
||||
}
|
||||
} else { // 原来就是最强5人
|
||||
if(ce < topFive[topFive.length - 1].ce) { // 滑出最强
|
||||
let heroes = await HeroModel.getTopHero(roleId, 5);
|
||||
topFive = heroes.map(cur => {return {hid: cur.hid, ce: cur.ce}});
|
||||
} else {
|
||||
topFive[index].ce = ce;
|
||||
}
|
||||
}
|
||||
|
||||
let topFiveCe = topFive.reduce((pre, cur) => {
|
||||
return pre + cur.ce
|
||||
}, 0);
|
||||
role = await RoleModel.findOneAndUpdate({roleId}, { topFive, topFiveCe, $inc: {ce: distance} }).lean(lean);
|
||||
return role;
|
||||
}
|
||||
|
||||
// 保存秘境首通队伍
|
||||
public static async saveDungeonHero(roleId: string, battleId: number, heroes: Array<number>, isSuccess: boolean) {
|
||||
if(isSuccess) {
|
||||
@@ -438,7 +404,7 @@ export default class Role extends BaseModel {
|
||||
|
||||
public static async updateRoleInfo(roleId: string, roleUpdate:roleUpdate, lean = true) {
|
||||
delete roleUpdate._id;
|
||||
let result: RoleType = await RoleModel.findOneAndUpdate({roleId}, {$set:roleUpdate}).lean(lean);
|
||||
let result: RoleType = await RoleModel.findOneAndUpdate({roleId}, {$set:roleUpdate}, {new: true}).lean(lean);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user