✨ feat(gvg): 定时器

This commit is contained in:
luying
2023-02-17 11:00:25 +08:00
parent 7543baa8cb
commit 605ee869a9
12 changed files with 210 additions and 56 deletions
+10 -8
View File
@@ -1,5 +1,6 @@
import BaseModel from "./BaseModel";
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
import { LeagueRankInfo } from "../domain/rank";
class Player {
@prop({ required: true })
@@ -44,14 +45,6 @@ export default class GVGCity extends BaseModel {
@prop({ required: true, default: 0 })
userCnt: number; // 城池人数
// 创建城市
public static async createCity(configId: number, groupId: number, serverType: number, cityId: number) {
let doc = new GVGCityModel();
let update = Object.assign(doc.toJSON(), { configId, cityId, groupId, serverType});
const city: GVGCityType = await GVGCityModel.findOneAndUpdate({ configId, cityId, groupId, serverType }, { $setOnInsert: update }, { upsert: true, new: true }).lean();
return city;
}
// 通过 cityId 获取城市
public static async findByCityId(configId: number, groupId: number, serverType: number, cityId: number) {
const city: GVGCityType = await GVGCityModel.findOne({ configId, groupId, serverType, cityId }).lean();
@@ -81,6 +74,15 @@ export default class GVGCity extends BaseModel {
const cities: GVGCityType[] = await GVGCityModel.find({ configId, hasGuard: true }).lean();
return cities
}
// 占领城池
public static async guardCity(configId: number, groupId: number, serverType: number, cityId: number, league: LeagueRankInfo) {
console.log('##### guardCity', configId, groupId, serverType, cityId)
const city: GVGCityType = await GVGCityModel.findOneAndUpdate({ configId: configId + 1, cityId, groupId, serverType }, { $set: {
hasGuard: true, guardLeague: league.code, guardLeagueName: league.name, guardLeagueIcon: league.icon
} }, { upsert: true, new: true }).lean();
return city;
}
}