🐞 fix(gvg): 修复战区问题,不跨服服务器应单列
This commit is contained in:
+16
-19
@@ -11,17 +11,14 @@ class Player {
|
||||
teamCnt: number;
|
||||
}
|
||||
|
||||
@index({ configId: 1, cityId: 1, groupId: 1, serverType: 1 })
|
||||
@index({ configId: 1, cityId: 1, groupKey: 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 })
|
||||
groupKey: string; // 战区
|
||||
|
||||
@prop({ required: true })
|
||||
cityId: number; // 城池id
|
||||
@@ -45,20 +42,20 @@ export default class GVGCity extends BaseModel {
|
||||
userCnt: number; // 城池人数
|
||||
|
||||
// 通过 cityId 获取城市
|
||||
public static async findByCityId(configId: number, groupId: number, serverType: number, cityId: number) {
|
||||
const city: GVGCityType = await GVGCityModel.findOne({ configId, groupId, serverType, cityId }).lean();
|
||||
public static async findByCityId(configId: number, groupKey: string, cityId: number) {
|
||||
const city: GVGCityType = await GVGCityModel.findOne({ configId, groupKey, cityId }).lean();
|
||||
return city;
|
||||
}
|
||||
|
||||
// 添加人数
|
||||
public static async increasePlayer(configId: number, groupId: number, serverType: number, cityId: number, roleId: string, leagueCode: string, teamCnt: number) {
|
||||
const city: GVGCityType = await GVGCityModel.findOneAndUpdate({ configId, groupId, serverType, cityId, userCnt: { $lt: 200 } }, { $inc: { userCnt: 1 }, $push: { players: { roleId, leagueCode, teamCnt } }}, { new: true, upsert: true }).lean();
|
||||
public static async increasePlayer(configId: number, groupKey: string, cityId: number, roleId: string, leagueCode: string, teamCnt: number) {
|
||||
const city: GVGCityType = await GVGCityModel.findOneAndUpdate({ configId, groupKey, cityId, userCnt: { $lt: 200 } }, { $inc: { userCnt: 1 }, $push: { players: { roleId, leagueCode, teamCnt } }}, { 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();
|
||||
public static async decreasePlayer(configId: number, groupKey: string, cityId: number, roleId: string) {
|
||||
const city: GVGCityType = await GVGCityModel.findOneAndUpdate({ configId, groupKey, cityId, 'players.roleId': roleId }, { $inc: { userCnt: -1 }, $pull: { players: { roleId } }}, { new: true, upsert: true }).lean();
|
||||
return city;
|
||||
}
|
||||
|
||||
@@ -74,9 +71,9 @@ export default class GVGCity extends BaseModel {
|
||||
}
|
||||
|
||||
// 查询联军驻守情况
|
||||
public static async findGuardCity(configId: number, groupId: number, serverType: number, select = '') {
|
||||
let cities: GVGCityType[] = await GVGCityModel.find({ configId: configId + 1, groupId, serverType, hasGuard: true }).select(select).lean();
|
||||
if(cities.length == 0) cities = await GVGCityModel.find({ configId, groupId, serverType, hasGuard: true }).select(select).lean();
|
||||
public static async findGuardCity(configId: number, groupKey: string, select = '') {
|
||||
let cities: GVGCityType[] = await GVGCityModel.find({ configId: configId + 1, groupKey, hasGuard: true }).select(select).lean();
|
||||
if(cities.length == 0) cities = await GVGCityModel.find({ configId, groupKey, hasGuard: true }).select(select).lean();
|
||||
return cities
|
||||
}
|
||||
|
||||
@@ -87,15 +84,15 @@ export default class GVGCity extends BaseModel {
|
||||
}
|
||||
|
||||
// 占领城池
|
||||
public static async guardCity(configId: number, groupId: number, serverType: number, cityId: number, league: LeagueRankInfo) {
|
||||
const city: GVGCityType = await GVGCityModel.findOneAndUpdate({ configId: configId + 1, cityId, groupId, serverType }, { $set: {
|
||||
public static async guardCity(configId: number, groupKey: string, cityId: number, league: LeagueRankInfo) {
|
||||
const city: GVGCityType = await GVGCityModel.findOneAndUpdate({ configId: configId + 1, cityId, groupKey }, { $set: {
|
||||
hasGuard: true, guardLeague: league.code, guardLeagueName: league.name, guardLeagueIcon: league.icon
|
||||
} }, { upsert: true, new: true }).lean();
|
||||
return city;
|
||||
}
|
||||
|
||||
public static async findByConfig(configId: number, groupId: number, serverType: number) {
|
||||
const cities: GVGCityType[] = await GVGCityModel.find({ configId, groupId, serverType, hasGuard: true }).lean();
|
||||
public static async findByConfig(configId: number, groupKey: string) {
|
||||
const cities: GVGCityType[] = await GVGCityModel.find({ configId, groupKey, hasGuard: true }).lean();
|
||||
return cities
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user