✨ feat(gvg): 激战期内存以及玩家移动、挑战操作
This commit is contained in:
+33
-13
@@ -1,17 +1,31 @@
|
||||
import BaseModel from "./BaseModel";
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
|
||||
@index({ configId: 1, cityId: 1 })
|
||||
class Player {
|
||||
@prop({ required: true })
|
||||
leagueCode: string;
|
||||
@prop({ required: true })
|
||||
roleId: string;
|
||||
}
|
||||
|
||||
|
||||
@index({ configId: 1, cityId: 1, groupId: 1, serverType: 1 })
|
||||
// GVGCity 类,继承自 BaseModel
|
||||
export default class GVGCity extends BaseModel {
|
||||
@prop({ required: true, default: 1 })
|
||||
configId: number; // config唯一id
|
||||
|
||||
@prop({ required: true, default: 1 })
|
||||
groupId: number; // 战区
|
||||
|
||||
@prop({ required: true, default: 1 })
|
||||
serverType: number; // 1-单服 2-跨服
|
||||
|
||||
@prop({ required: true })
|
||||
cityId: number; // 城池id
|
||||
|
||||
@prop({ required: true, default: [] })
|
||||
leagueCodes: string[]; // 联军
|
||||
@prop({ required: true, default: [], type: Player, _id: false })
|
||||
players: Player[]; // 联军
|
||||
|
||||
@prop({ required: false })
|
||||
guardLeague: string; // 占领的联军
|
||||
@@ -19,29 +33,35 @@ export default class GVGCity extends BaseModel {
|
||||
@prop({ required: false })
|
||||
guardLeagueName: string; // 占领的联军
|
||||
|
||||
@prop({ required: false })
|
||||
guardLeagueIcon: number; // 占领的联军
|
||||
|
||||
@prop({ required: true, default: 0 })
|
||||
userCnt: number; // 城池人数
|
||||
|
||||
@prop({ required: true, default: 0 })
|
||||
teamCnt: number; // 城池队伍数
|
||||
|
||||
// 创建城市
|
||||
public static async createCity(configId: number, cityId: 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});
|
||||
const city: GVGCityType | null = await GVGCityModel.findOneAndUpdate({ configId, cityId }, { $setOnInsert: update }, { upsert: true, new: true }).lean();
|
||||
const city: GVGCityType = await GVGCityModel.findOneAndUpdate({ configId, cityId, groupId, serverType }, { $setOnInsert: update }, { upsert: true, new: true }).lean();
|
||||
return city;
|
||||
}
|
||||
|
||||
// 通过 cityId 获取城市
|
||||
public static async getCityByCityId(configId: number, cityId: number) {
|
||||
const city: GVGCityType | null = await GVGCityModel.findOne({ configId, cityId }).lean();
|
||||
public static async findByCityId(configId: number, groupId: number, serverType: number, cityId: number) {
|
||||
const city: GVGCityType = await GVGCityModel.findOne({ configId, groupId, serverType, cityId }).lean();
|
||||
return city;
|
||||
}
|
||||
|
||||
// 更新城市字段
|
||||
public static async updateCityUser(configId: number, cityId: number, userInc: number, teamInc: number) {
|
||||
const city: GVGCityType | null = await GVGCityModel.findOneAndUpdate({ configId, cityId}, { $inc: {userCnt: userInc, teamCnt: teamInc} }, { new: true }).lean();
|
||||
// 添加人数
|
||||
public static async increasePlayer(configId: number, groupId: number, serverType: number, cityId: number, roleId: string, leagueCode: string) {
|
||||
const city: GVGCityType = await GVGCityModel.findOneAndUpdate({ configId, groupId, serverType, cityId, userCnt: { $lt: 200 } }, { $inc: { userCnt: 1 }, $push: { players: { roleId, leagueCode } }}, { new: true, upsert: true }).lean();
|
||||
return city;
|
||||
}
|
||||
|
||||
// 减少人数
|
||||
public static async decreasePlayer(configId: number, groupId: number, serverType: number, cityId: number, roleId: string) {
|
||||
const city: GVGCityType = await GVGCityModel.findOneAndUpdate({ configId, groupId, serverType, cityId, 'players.roleId': roleId }, { $inc: { userCnt: -1 }, $pull: { players: { roleId } }}, { new: true, upsert: true }).lean();
|
||||
return city;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user