✨ feat(gvgBattle): getCity返回正确的结构
This commit is contained in:
@@ -9,7 +9,7 @@ import { DEBUG_MAGIC_WORD, GVG_PERIOD, STATUS } from "../../../consts";
|
||||
import { LineupHero } from "../../../domain/roleField/hero";
|
||||
import { resResult, genCode } from "../../../pubUtils/util";
|
||||
import { GVGLeagueModel } from '../../../db/GVGLeague';
|
||||
import { checkGVGPeriod, getGroupIdOfServer, getGVGPeriodData, getGVGServerType } from '../../../services/gvg/gvgService';
|
||||
import { checkGVGPeriod, getGroupIdOfServer, getGVGConfig, getGVGPeriodData, getGVGServerType } from '../../../services/gvg/gvgService';
|
||||
import { checkMoveStatus, getBirthAreaOfCity, initRobots } from '../../../services/gvg/gvgBattleService';
|
||||
import { getGVGBattleData } from '../../../services/gvg/gvgBattleMemory';
|
||||
import { nowSeconds } from '../../../pubUtils/timeUtil';
|
||||
@@ -56,14 +56,26 @@ export class GVGBattleHandler {
|
||||
|
||||
// 获取城池信息
|
||||
async getCity(msg: { cityId: number }, session: BackendSession) {
|
||||
|
||||
const guildCode = session.get('guildCode');
|
||||
const { cityId } = msg;
|
||||
let { configId } = getGVGPeriodData();
|
||||
|
||||
let myLeague = await GVGLeagueModel.findLeagueByGuild(guildCode);
|
||||
if(!myLeague) return resResult(STATUS.GVG_LEAGUE_NOT_EXIST);
|
||||
|
||||
const city = await GVGCityModel.findOne({ configId, cityId }).lean();
|
||||
const { guardLeague: leagueCode, guardLeagueName: name, guardLeagueIcon: icon } = city;
|
||||
const { battleTime: startTime, scheduleTime } = getGVGConfig();
|
||||
const cityTeamCnt = await GVGTeamModel.getTeamCntByCity(cityId);
|
||||
const leagueTeamCnt = await GVGTeamModel.getTeamCntByCity(cityId, myLeague.leagueCode);
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
cityId,
|
||||
guardLeague: city.guardLeague
|
||||
guardLeague: { leagueCode, name, icon },
|
||||
startTime,
|
||||
endTime: scheduleTime, // ! endTime 修正
|
||||
ourTeamCnt: leagueTeamCnt,
|
||||
oppTeamCnt: cityTeamCnt - leagueTeamCnt, // ! 总数是否直接存储在城池中,或有其它更好的方案
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import { DicGVGAreaPoint } from "../pubUtils/dictionary/DicGVGAreaPoint";
|
||||
|
||||
@index({ roleId: 1, teamId: 1 })
|
||||
@index({ teamCode: 1 })
|
||||
@index({ cityId: 1, leagueId: 1 })
|
||||
export default class GVGTeam extends BaseModel {
|
||||
|
||||
@prop({ required: true })
|
||||
@@ -106,11 +107,21 @@ export default class GVGTeam extends BaseModel {
|
||||
}
|
||||
|
||||
// 查找角色队伍数
|
||||
public static async getTeamCnt(roleId: string) {
|
||||
public static async getTeamCntByRole(roleId: string) {
|
||||
const teams: GVGTeamType[] = await GVGTeamModel.find({ roleId }).select('teamCode').lean();
|
||||
return teams.length;
|
||||
}
|
||||
|
||||
// 通过城池ID获取队伍数
|
||||
public static async getTeamCntByCity(cityId: number, leagueCode?: string) {
|
||||
const query = { cityId };
|
||||
if (leagueCode) {
|
||||
query['leagueCode'] = leagueCode;
|
||||
}
|
||||
const teams: GVGTeamType[] = await GVGTeamModel.find(query).select('').lean();
|
||||
return teams.length;
|
||||
}
|
||||
|
||||
// 玩家切换城池更新队伍信息
|
||||
public static async enterCity(roleId: string, cityId: number, areaId: number, groupId: number, serverType: number) {
|
||||
const res = await GVGTeamModel.updateMany({ roleId }, { cityId, areaId, pointId: 0, groupId, serverType }).lean();
|
||||
|
||||
Reference in New Issue
Block a user