Files
ZYZ/shared/db/GVGBattleRec.ts
2023-04-18 11:35:34 +08:00

129 lines
4.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// GVGBattleRec 数据库表,挑战记录信息
import BaseModel from "./BaseModel";
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
import { genCode } from "../pubUtils/util";
import { GVGTeamType } from "./GVGTeam";
import { GVGHeroInfo } from "../domain/dbGeneral";
import { nowSeconds } from "../pubUtils/timeUtil";
class TeamInfo {
@prop({ required: true })
roleId: string; // 玩家id
@prop({ required: true })
roleName: string; // 玩家id
@prop({ required: true })
teamCode: string; // 玩家队伍唯一标识
@prop({ required: true })
index: number; // 队伍id1-3玩家的第几个队伍
@prop({ required: true })
leagueCode: string; // 联军
@prop({ required: true })
guildCode: string; // 军团
@prop({ required: false })
areaId: number;
@prop({ required: false })
cityId: number;
@prop({ required: false })
pointId: number;
@prop({ required: true })
head: number; // 头像
@prop({ required: true })
spine: number; // 形象
@prop({ required: true })
frame: number; // 相框
@prop({ required: true, default: 0 })
durability: number; // 耐久
@prop({ required: true, type: () => GVGHeroInfo, _id: false })
lineup: GVGHeroInfo[]
@prop({ required: true, default: 0 })
isRobot: boolean; // 是否是机器人
@prop({ required: true, default: 0 })
isCatapult: boolean; // 是否是投石车
@prop({ required: true, default: 0 })
originPointId: number;
@prop({ required: true, default: 0 })
curTeamBreak: boolean;
}
@index({ battleCode: 1 })
export default class GVGBattleRec extends BaseModel {
@prop({ required: true })
battleCode: string; // 战斗记录
@prop({ required: true })
configId: number; // 赛季
@prop({ required: true })
groupKey: string; // 1-单服 2-跨服
@prop({ required: true })
warId: number; // 关卡id
@prop({ required: true, type: TeamInfo, _id: false })
attackTeam: TeamInfo; // 挑战队伍
@prop({ required: true, type: TeamInfo, _id: false })
defenseTeam: TeamInfo; // 防守队伍
@prop({ required: true, type: TeamInfo, _id: false })
attackTeamAfter: TeamInfo; // 挑战队伍
@prop({ required: true, type: TeamInfo, _id: false })
defenseTeamAfter: TeamInfo; // 防守队伍
@prop({ required: true })
isSuccess: boolean;
@prop({ required: true })
battleEndTime: number;
@prop({ required: true, default: false })
hasRpl: boolean; // 是否存在对应录像
@prop({ required: true, default: false })
remoteUrl: string; // 录像地址
public static async createRec(configId: number, groupKey: string, warId: number, attackTeam: GVGTeamType, defenseTeam: GVGTeamType) {
const battleCode = genCode(8);
const result: GVGBattleRecType = await GVGBattleRecModel.findOneAndUpdate({ battleCode }, { $set: { configId, groupKey, warId, attackTeam, defenseTeam, isSuccess: false } }, { new: true, upsert: true }).lean();
return result;
}
public static async findByBattleCode(battleCode: string) {
const result: GVGBattleRecType = await GVGBattleRecModel.findOne({ battleCode }).lean();
return result;
}
public static async battleEnd(battleCode: string, isSuccess: boolean, attackTeam: GVGTeamType, defenseTeam: GVGTeamType) {
const result: GVGBattleRecType = await GVGBattleRecModel.findOneAndUpdate({ battleCode }, { $set: { isSuccess, battleEndTime: nowSeconds(), attackTeamAfter: attackTeam, defenseTeamAfter: defenseTeam } }, { new: true }).lean();
return result;
}
public static async updateRplStatus(battleCode: string, hasRpl: boolean, remoteUrl: string) {
let result = await GVGBattleRecModel.findOneAndUpdate({ battleCode }, { hasRpl, remoteUrl }, { new: true }).lean();
return result;
}
}
export const GVGBattleRecModel = getModelForClass(GVGBattleRec);
export interface GVGBattleRecType extends Pick<DocumentType<GVGBattleRec>, keyof GVGBattleRec> {};
export type GVGBattleRecUpdate = Partial<GVGBattleRecType>; // 将所有字段变成可选项