✨ feat(gvg): 保存阵容、刷新对手、战报
This commit is contained in:
@@ -135,6 +135,13 @@ export default class GVGVestigeRank extends BaseModel {
|
||||
session.endSession()
|
||||
}
|
||||
}
|
||||
|
||||
public static async refreshOpp(roleId: string, vestigeId: number, oppRanks: number[]) {
|
||||
let today = getZeroPoint();
|
||||
let result: GVGVestigeRankType = await GVGVestigeRankModel.findOneAndUpdate({ day: today, vestigeId, roleId }, { $set: { oppRanks }, $inc: { refreshCnt: 1 } }, { new: true, upsert: true }).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const GVGVestigeRankModel = getModelForClass(GVGVestigeRank);
|
||||
|
||||
@@ -3,6 +3,7 @@ import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
import { OppPlayerInfo, OppPlayerHeroInfo } from '../domain/gvgField/gvgDb';
|
||||
import { genCode } from '../pubUtils/util';
|
||||
import { getTimeFunD } from '../pubUtils/timeUtil';
|
||||
|
||||
class LeagueGood {
|
||||
@prop({ required: true })
|
||||
@@ -16,7 +17,7 @@ class LeagueGood {
|
||||
}
|
||||
|
||||
@index({ battleCode: 1 })
|
||||
@index({ day: 1, groupId: 1, vestigeId: 1, rank: 1 })
|
||||
@index({ groupId: 1, vestigeId: 1, rank: 1 })
|
||||
export default class GVGVestigeRec extends BaseModel {
|
||||
|
||||
@prop({ required: true })
|
||||
@@ -74,14 +75,16 @@ export default class GVGVestigeRec extends BaseModel {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async startBattle(battleCode: string, attackHeroes: OppPlayerHeroInfo[]) {
|
||||
public static async startBattle(battleCode: string, attackHeroes: OppPlayerHeroInfo[], ce: number) {
|
||||
const result: GVGVestigeRecType = await GVGVestigeRecModel.findOneAndUpdate({ battleCode }, {
|
||||
$set: { battleTime: Date.now(), 'attackInfo.heroes': attackHeroes }
|
||||
$set: { battleTime: Date.now(), 'attackInfo.heroes': attackHeroes, 'attackInfo.ce': ce }
|
||||
}, { new: true }).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async battleEnd(battleCode: string, isSuccess: boolean, endTime: number, atkNewRank?: number, defNewRank?: number) {
|
||||
console.log('battleEnd', battleCode, isSuccess, endTime, atkNewRank, defNewRank)
|
||||
|
||||
let update: GVGVestigeRecUpdate = { endTime };
|
||||
if(isSuccess) {
|
||||
update['attackInfo.isSuccess'] = true;
|
||||
@@ -99,9 +102,23 @@ export default class GVGVestigeRec extends BaseModel {
|
||||
}
|
||||
|
||||
public static async giveup(roleId: string, battleCode: string) {
|
||||
const result: GVGVestigeRecType = await GVGVestigeRecModel.findOneAndUpdate({ attackRoleId: roleId, battleCode }, { $set: { cancel: true }}, { new: true }).lean();
|
||||
const result: GVGVestigeRecType = await GVGVestigeRecModel.findOneAndUpdate({ attackRoleId: roleId, battleCode }, { $set: { cancel: true, endTime: Date.now() }}, { new: true }).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public static async updateRplStatus(battleCode: string, hasRpl: boolean) {
|
||||
let result: GVGVestigeRecType = await GVGVestigeRecModel.findOneAndUpdate({ battleCode }, { hasRpl }, { new: true }).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async findRec(roleId: string, vestigeId: number) {
|
||||
let recs: GVGVestigeRecType[] = await GVGVestigeRecModel.find({
|
||||
vestigeId, $or: [{attackRoleId: roleId}, { defenseRoleId: roleId }],
|
||||
createdAt: { $gte: <Date>getTimeFunD().getBeforeDayWithHour(3) },
|
||||
}).select({ battleCode: 1, attackRoleId: 1, defenseRoleId: 1, _id: 0, endTime: 1, attackInfo: 1, defenseInfo: 1, hasRpl: 1 }).limit(1000).lean();
|
||||
return recs;
|
||||
}
|
||||
}
|
||||
|
||||
export const GVGVestigeRecModel = getModelForClass(GVGVestigeRec);
|
||||
|
||||
Reference in New Issue
Block a user