战力:修复创建武将bug

This commit is contained in:
luying
2022-03-28 17:44:14 +08:00
parent f35af70adc
commit 14b28921af
13 changed files with 379 additions and 393 deletions
+16 -16
View File
@@ -281,22 +281,22 @@ export default class Hero extends BaseModel {
return update
}
public static async createHero(heroInfo: HeroUpdate, lean = true) {
const seqId = await CounterModel.getNewCounter(COUNTER.HID) || -1;
const update = this.getInitInfo(heroInfo.hid, { ...heroInfo, seqId });
const hero: HeroType = await HeroModel.findOneAndUpdate({ roleId: heroInfo.roleId, hid: heroInfo.hid }, update, { upsert: true, new: true }).lean(lean);
return hero;
}
// public static async createHero(heroInfo: HeroUpdate, lean = true) {
// const seqId = await CounterModel.getNewCounter(COUNTER.HID) || -1;
// const update = this.getInitInfo(heroInfo.hid, { ...heroInfo, seqId });
// const hero: HeroType = await HeroModel.findOneAndUpdate({ roleId: heroInfo.roleId, hid: heroInfo.hid }, update, { upsert: true, new: true }).lean(lean);
// return hero;
// }
public static async insertHeroes(roleId: string, roleName: string, serverId: number, heroInfos: HeroUpdate[]) {
let insertInfos: HeroUpdate[] = [];
for(let hero of heroInfos) {
const seqId = await CounterModel.getNewCounter(COUNTER.HID) || -1;
insertInfos.push({ ...hero, seqId, roleId, roleName, serverId })
}
await HeroModel.insertMany(insertInfos);
return <HeroType[]>insertInfos;
}
// public static async insertHeroes(roleId: string, roleName: string, serverId: number, heroInfos: HeroUpdate[]) {
// let insertInfos: HeroUpdate[] = [];
// for(let hero of heroInfos) {
// const seqId = await CounterModel.getNewCounter(COUNTER.HID) || -1;
// insertInfos.push({ ...hero, seqId, roleId, roleName, serverId })
// }
// await HeroModel.insertMany(insertInfos);
// return <HeroType[]>insertInfos;
// }
public static async sumHeroCe(roleId: string) {
let ce: Array<{ ce: number }> = await HeroModel.aggregate([
@@ -323,7 +323,7 @@ export default class Hero extends BaseModel {
public static async updateHeroInfo(roleId: string, hid: number, heroUpdate: HeroUpdate, select?: string, getters = false) {
delete heroUpdate._id;
let result: HeroType = await HeroModel.findOneAndUpdate({ roleId, hid }, { $set: heroUpdate }, { new: true }).select(select).lean({ getters });
let result: HeroType = await HeroModel.findOneAndUpdate({ roleId, hid }, { $set: heroUpdate }, { new: true, upsert: true }).select(select).lean({ getters });
return result;
}
+4 -4
View File
@@ -5,7 +5,7 @@ import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoos
export class AttrCell {
@prop({ required: true })
attrId: number; // 属性id
@prop({ required: true })
@prop({ required: true, type: Number })
values: number[]; // 战力公式中的全局加成的数据,查表后的结果
}
@@ -35,7 +35,7 @@ export class EquipAttr {
}
// 百家学宫加成
class SchoolAttr {
export class SchoolAttr {
@prop({ required: true })
hid: number; // 武将id
@prop({ required: true })
@@ -76,13 +76,13 @@ export default class RoleCe extends BaseModel {
equipAttrs: EquipAttr[]
@prop({ required: true, type: SchoolAttr, _id: false })
schoolAttr: SchoolAttr[];
schoolAttrs: SchoolAttr[];
@prop({ required: true, type: ScrollAttr, _id: false })
scrollAttrs: ScrollAttr[];
public static async findByRoleId(roleId: string) {
let result: RoleCeType = await RoleCeModel.findOneAndUpdate({ roleId }).lean();
let result: RoleCeType = await RoleCeModel.findOne({ roleId }).lean();
return result;
}
-1
View File
@@ -4,7 +4,6 @@
import { HERO_SYSTEM_TYPE, ABI_TYPE, HERO_CE_RATIO, LINEUP_NUM, TALENT_RELATION_TYPE } from '../consts';
import { cal, calculatetopLineup, deepCopy, getAllAttrStage, reduceCe } from './util';
import { HeroModel, HeroType, HeroUpdate, CeAttrData, EPlace, Stone, Talent } from '../db/Hero';
import { RoleModel, RoleType, RoleUpdate, CeAttrDataRole } from '../db/Role';
import { AttributeCal } from '../domain/roleField/attribute';
+45 -45
View File
@@ -788,50 +788,50 @@ export function addToMap<T>(map: Map<T, number>, id: T, value: number) {
}
}
/**
* 计算最强阵容战力
* @param role
* @param hid
* @param ce
* @param heroId
*/
export async function calculatetopLineup(role: RoleType, hid?: number, ce?: number, heroId?: string) {
let topLineup = role?.topLineup || new Array();
if(!hid) { // 直接重新排
let heroes = await HeroModel.getTopHero(role.roleId, LINEUP_NUM);
topLineup = heroes.map(cur => { return { hid: cur.hid, ce: cur.ce, hero: cur._id } });
} else {
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, LINEUP_NUM);
topLineup = heroes.map(cur => { return { hid: cur.hid, ce: cur.ce, hero: cur._id } });
} else {
if (index == -1) { // 不在最强列表
if (topLineup.length < LINEUP_NUM) { // 不满6人
topLineup.push({ hid, ce, hero: heroId });
} else if (topLineup.length == LINEUP_NUM) {
if (ce > topLineup[topLineup.length - 1].ce) { // 跻身最强6人
topLineup.pop();
topLineup.push({ hid, ce, hero: heroId });
}
} else {
topLineup.splice(LINEUP_NUM, topLineup.length - LINEUP_NUM);
}
} else { // 原来就是最强6人
if (ce < topLineup[topLineup.length - 1].ce) { // 滑出最强
let heroes = await HeroModel.getTopHero(role.roleId, LINEUP_NUM);
topLineup = heroes.map(cur => { return { hid: cur.hid, ce: cur.ce, hero: cur._id } });
} else {
topLineup[index].ce = ce;
}
}
}
}
// /**
// * 计算最强阵容战力
// * @param role
// * @param hid
// * @param ce
// * @param heroId
// */
// export async function calculatetopLineup(role: RoleType, hid?: number, ce?: number, heroId?: string) {
// let topLineup = role?.topLineup || new Array();
// if(!hid) { // 直接重新排
// let heroes = await HeroModel.getTopHero(role.roleId, LINEUP_NUM);
// topLineup = heroes.map(cur => { return { hid: cur.hid, ce: cur.ce, hero: cur._id } });
// } else {
// 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, LINEUP_NUM);
// topLineup = heroes.map(cur => { return { hid: cur.hid, ce: cur.ce, hero: cur._id } });
// } else {
// if (index == -1) { // 不在最强列表
// if (topLineup.length < LINEUP_NUM) { // 不满6人
// topLineup.push({ hid, ce, hero: heroId });
// } else if (topLineup.length == LINEUP_NUM) {
// if (ce > topLineup[topLineup.length - 1].ce) { // 跻身最强6人
// topLineup.pop();
// topLineup.push({ hid, ce, hero: heroId });
// }
// } else {
// topLineup.splice(LINEUP_NUM, topLineup.length - LINEUP_NUM);
// }
// } else { // 原来就是最强6人
// if (ce < topLineup[topLineup.length - 1].ce) { // 滑出最强
// let heroes = await HeroModel.getTopHero(role.roleId, LINEUP_NUM);
// topLineup = heroes.map(cur => { return { hid: cur.hid, ce: cur.ce, hero: cur._id } });
// } else {
// topLineup[index].ce = ce;
// }
// }
// }
// }
let topLineupCe = topLineup.reduce((pre, cur) => {
return pre + cur.ce
}, 0);
// let topLineupCe = topLineup.reduce((pre, cur) => {
// return pre + cur.ce
// }, 0);
return { topLineup, topLineupCe };
}
// return { topLineup, topLineupCe };
// }