feat(gvg): 开始挑战和结束挑战

This commit is contained in:
luying
2023-02-01 21:26:24 +08:00
parent b727249106
commit ddce23d7fd
12 changed files with 34095 additions and 179 deletions

View File

@@ -1,9 +1,8 @@
// 征战中原对手锁
import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
import { OppPlayerInfo } from '../domain/gvgField/gvgDb';
import { OppPlayerInfo, OppPlayerHeroInfo } from '../domain/gvgField/gvgDb';
import { genCode } from '../pubUtils/util';
import { VESTIGE_STATUS } from '../consts';
class LeagueGood {
@prop({ required: true })
@@ -16,12 +15,16 @@ class LeagueGood {
count: number
}
@index({ battleCode: 1 })
@index({ day: 1, groupId: 1, vestigeId: 1, rank: 1 })
export default class GVGVestigeRec extends BaseModel {
@prop({ required: true })
battleCode: string; // 唯一code
@prop({ required: true })
warId: number; // 关卡id
@prop({ required: true })
attackRoleId: string; // 攻方玩家id
@@ -35,7 +38,7 @@ export default class GVGVestigeRec extends BaseModel {
vestigeId: number; // 遗迹id
@prop({ required: true })
status: number; // 1-出兵中 2-挑战中 3-挑战完毕 4-取消
cancel: boolean; // 是否取消
@prop({ required: true })
checkTime: number; // 开始出兵的时间13位时间戳
@@ -58,19 +61,50 @@ export default class GVGVestigeRec extends BaseModel {
@prop({ required: true, default: false })
hasRpl: boolean; // 是否存在对应录像
public static async createRec(configId: number, vestigeId: number, groupId: number, attackInfo: OppPlayerInfo, defenseInfo: OppPlayerInfo, leagueGoods: LeagueGood[]) {
public static async createRec(configId: number, vestigeId: number, groupId: number, warId: number, attackInfo: OppPlayerInfo, defenseInfo: OppPlayerInfo, leagueGoods: LeagueGood[]) {
const battleCode = genCode(10);
const result: GVGVestigeRecType = await GVGVestigeRecModel.findOneAndUpdate({ battleCode }, {
$set: { configId, vestigeId, groupId, attackRoleId: attackInfo.roleId, defenseRoleId: defenseInfo.roleId, status: VESTIGE_STATUS.CHECK, checkTime: Date.now(), attackInfo, defenseInfo, leagueGoods }
$set: { configId, vestigeId, groupId, attackRoleId: attackInfo.roleId, defenseRoleId: defenseInfo.roleId, warId, checkTime: Date.now(), attackInfo, defenseInfo, leagueGoods }
}, { new: true, upsert: true }).lean();
return result;
}
public static async findByBattleCode(battleCode: string, select = '') {
const result: GVGVestigeRecType = await GVGVestigeRecModel.findOne({ battleCode }).select(select).lean();
return result;
}
public static async startBattle(battleCode: string, attackHeroes: OppPlayerHeroInfo[]) {
const result: GVGVestigeRecType = await GVGVestigeRecModel.findOneAndUpdate({ battleCode }, {
$set: { battleTime: Date.now(), 'attackInfo.heroes': attackHeroes }
}, { new: true }).lean();
return result;
}
public static async battleEnd(battleCode: string, isSuccess: boolean, endTime: number, atkNewRank?: number, defNewRank?: number) {
let update: GVGVestigeRecUpdate = { endTime };
if(isSuccess) {
update['attackInfo.isSuccess'] = true;
update['defenseInfo.isSuccess'] = false;
}
if(atkNewRank != undefined && defNewRank != undefined) {
update['attackInfo.newRank'] = atkNewRank;
update['attackInfo.oldRank'] = defNewRank;
update['defenseInfo.newRank'] = defNewRank;
update['defenseInfo.oldRank'] = atkNewRank;
}
const result: GVGVestigeRecType = await GVGVestigeRecModel.findOneAndUpdate({ battleCode }, { $set: update }, { new: true }).lean();
return result;
}
public static async giveup(roleId: string, battleCode: string) {
const result: GVGVestigeRecType = await GVGVestigeRecModel.findOneAndUpdate({ attackRoleId: roleId, battleCode }, { $set: { cancel: true }}, { new: true }).lean();
return result;
}
}
export const GVGVestigeRecModel = getModelForClass(GVGVestigeRec);
export interface GVGVestigeRecType extends Pick<DocumentType<GVGVestigeRec>, keyof GVGVestigeRec> {
id: number;
};
export interface GVGVestigeRecType extends Pick<DocumentType<GVGVestigeRec>, keyof GVGVestigeRec> {};
export type GVGVestigeRecUpdate = Partial<GVGVestigeRecType>; // 将所有字段变成可选项