寻宝:roleStatus.heroes格式修改

This commit is contained in:
luying
2021-08-13 20:16:07 +08:00
parent 96042737d3
commit 899fc4aef6
4 changed files with 55 additions and 13 deletions

View File

@@ -2,6 +2,27 @@ import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
import { EXTERIOR } from '../pubUtils/dicParam';
import { ItemReward } from '../domain/dbGeneral';
import { HeroType } from './Hero';
export class ComRoleStatusHero {
@prop({ required: true })
id: number;
@prop({ required: true })
quality: number;
@prop({ required: true })
star: number;
@prop({ required: true })
colorStar: number;
@prop({ required: true })
lv: number;
constructor(hero: HeroType) {
this.id = hero.hid;
this.quality = hero.quality;
this.star = hero.star;
this.colorStar = hero.colorStar;
this.lv = hero.lv;
}
}
export class RoleStatus {
@prop({ required: true })
@@ -19,8 +40,8 @@ export class RoleStatus {
@prop({ required: false, default: '' })
battleCode: string;
// 玩家所用阵容
@prop({ required: false, type: Number, default: [] })
heroes: number[];
@prop({ required: false, type: ComRoleStatusHero, default: [], _id: false })
heroes: ComRoleStatusHero[];
// 阵亡武将
@prop({ required: false, type: Number, default: [] })
killed: number[];
@@ -58,7 +79,7 @@ export class RoleStatus {
@prop({ required: true, default: 0 })
frdRatio: number = 0;
constructor(roleId: string, roleName: string, isCap: boolean, isFrd: boolean, head: number, frame: number, spine: number, topLineupCe: number, lv: number, heroes = [], isRobot = false) {
constructor(roleId: string, roleName: string, isCap: boolean, isFrd: boolean, head: number, frame: number, spine: number, topLineupCe: number, lv: number, heroes: ComRoleStatusHero[] = [], isRobot = false) {
this.roleId = roleId;
this.roleName = roleName;
this.isCap = isCap;
@@ -178,12 +199,12 @@ export default class ComBattleTeam extends BaseModel {
return team;
}
public static async updateHeroes(teamCode: string, roleId: string, heroes: number[], lean = true) {
public static async updateHeroes(teamCode: string, roleId: string, heroes: ComRoleStatusHero[], lean = true) {
const team: ComBattleTeamType = await ComBattleTeamModel.findOneAndUpdate({ teamCode, 'roleStatus.roleId': roleId}, {$set: {'roleStatus.$.heroes': heroes}}, {new: true}).lean(lean);
return team;
}
public static async setupBattleInfo(teamCode: string, roleId: string, heroes: number[], battleCode: string, lean = true) {
public static async setupBattleInfo(teamCode: string, roleId: string, heroes: ComRoleStatusHero[], battleCode: string, lean = true) {
const team: ComBattleTeamType = await ComBattleTeamModel.findOneAndUpdate({ teamCode, 'roleStatus.roleId': roleId}, {$set: {'roleStatus.$.heroes': heroes, 'roleStatus.$.battleCode': battleCode}}, {new: true}).lean(lean);
return team;
}