diff --git a/game-server/app/servers/guild/handler/gvgBattleHandler.ts b/game-server/app/servers/guild/handler/gvgBattleHandler.ts index 9ca3abbe3..5c6374536 100644 --- a/game-server/app/servers/guild/handler/gvgBattleHandler.ts +++ b/game-server/app/servers/guild/handler/gvgBattleHandler.ts @@ -4,9 +4,10 @@ import { GVGTeamModel } from '../../../db/GVGTeam'; import { GVGUserDataModel } from '../../../db/GVGUserData'; import { GVGCityModel } from '../../../db/GVGCity'; import { Application, BackendSession, ChannelService, HandlerService } from "pinus"; -import { STATUS } from "../../../consts"; +import { DEBUG_MAGIC_WORD, STATUS } from "../../../consts"; import { LineupHero } from "../../../domain/roleField/hero"; import { resResult, genCode } from "../../../pubUtils/util"; +import { GVGConfigModel } from '../../../db/GVGConfig'; export default function (app: Application) { new HandlerService(app, {}); @@ -26,6 +27,7 @@ export class GVGBattleHandler { // spine: 形象 // lineup: 阵容 async saveTeam(msg: { index: number, head: number, frame: number, spine: number, lineup: [ LineupHero ] }, session: BackendSession) { + const { index, head, frame, spine, lineup } = msg; return resResult(STATUS.SUCCESS, { teams: [ 'teamCode' ] }); } @@ -41,12 +43,20 @@ export class GVGBattleHandler { async enterCity(msg: { cityId: number }, session: BackendSession) { const { cityId } = msg; - let valid = false; - if (!valid) { + + + let city = await GVGCityModel.findOne({ cityId }).lean(); + if (!city) { + return resResult(STATUS.GVG_CITY_NOT_FOUND); + } + + const { teamCnt, userCnt } = city; + // 检测是否满员 + if (userCnt >= 200) { return resResult(STATUS.GVG_BATTLE_CITY_FULL); } - const city = await GVGCityModel.findOne({ cityId }).lean(); + // ! 更新城池人数和队伍数,更新用户城池信息 return resResult(STATUS.SUCCESS, { city }); } @@ -175,4 +185,27 @@ export class GVGBattleHandler { ]); return resResult(STATUS.SUCCESS, { teams }); } + + // debug 接口,创建城市 + async createCity(msg: { cityId: number, magicWord: string }, session: BackendSession) { + const { cityId, magicWord } = msg; + if (magicWord !== DEBUG_MAGIC_WORD) { + return resResult(STATUS.INTERNAL_ERR); + } + + // 检查城市是否存在 + let city = await GVGCityModel.getCityByCityId(cityId); + if (city) { + return resResult(STATUS.SUCCESS, { city }); + } + + // 创建城市 + const config = await GVGConfigModel.findConfig(); + if (!config || !config.configId) { + return resResult(STATUS.INTERNAL_ERR); + } + const { configId } = config; + city = await GVGCityModel.createCity(cityId, configId); + return resResult(STATUS.SUCCESS, { city }); + } } diff --git a/game-server/test/gvgBattle.test.ts b/game-server/test/gvgBattle.test.ts index 0e4ec0697..4f59d80d5 100644 --- a/game-server/test/gvgBattle.test.ts +++ b/game-server/test/gvgBattle.test.ts @@ -1,3 +1,4 @@ +import { DEBUG_MAGIC_WORD } from '../../shared/consts'; import { GVGTeamType } from './../../shared/db/GVGTeam'; import { GVGUserDataType } from './../../shared/db/GVGUserData'; import { LineupHero } from './../../shared/domain/roleField/hero'; @@ -7,7 +8,7 @@ import { PinusWSClient } from 'pinus-robot-plugin'; import { expect } from 'chai'; import { checkSuccessResponse } from './CheckPatten'; -describe.skip('gvg激战期测试', function () { +describe('gvg激战期测试', function () { let pinusClient: PinusWSClient; let roleInfo; @@ -58,13 +59,21 @@ describe.skip('gvg激战期测试', function () { // 测试获取城池信息 it('测试获取城池信息', function (done) { const cityId = 1; - pinusClient.request('guild.gvgBattleHandler.getCity', { - cityId, + // 通过测试接口尝试创建城市 + pinusClient.request('guild.gvgBattleHandler.createCity', { + cityId, magicWord: DEBUG_MAGIC_WORD }, (data) => { checkSuccessResponse(data); - // 检查返回值中的 city + console.log(JSON.stringify(data.data.city, null, 2)); checkCity(data.data.city); - done(); + pinusClient.request('guild.gvgBattleHandler.getCity', { + cityId, + }, (data) => { + checkSuccessResponse(data); + // 检查返回值中的 city + checkCity(data.data.city); + done(); + }); }); }); @@ -90,7 +99,7 @@ describe.skip('gvg激战期测试', function () { }); // 开始移动 - it('开始移动', function (done) { + it.skip('开始移动', function (done) { const cityId = 1; const areaId = 1; const teamCode = ''; @@ -102,7 +111,7 @@ describe.skip('gvg激战期测试', function () { checkSuccessResponse(data); setTimeout(() => { // 停止移动 - it('停止移动', function (done) { + it.skip('停止移动', function (done) { pinusClient.request('guild.gvgBattleHandler.stopMove', {}, (data) => { checkSuccessResponse(data); expect(data.data.areaId).to.be.a('number'); @@ -121,7 +130,7 @@ describe.skip('gvg激战期测试', function () { }); // 队伍入驻积分点 - it('队伍入驻积分点', function (done) { + it.skip('队伍入驻积分点', function (done) { const cityId = 1; const areaId = 1; const pointId = 1; @@ -139,7 +148,7 @@ describe.skip('gvg激战期测试', function () { }); // 队伍离开积分点 - it('队伍离开积分点', function (done) { + it.skip('队伍离开积分点', function (done) { pinusClient.request('guild.gvgBattleHandler.teamLeave', {}, (data) => { checkSuccessResponse(data); done(); @@ -157,7 +166,7 @@ describe.skip('gvg激战期测试', function () { expect(battleCode).to.be.a('string'); setTimeout(() => { // 队伍结束攻击 battleEnd - it('队伍结束攻击', function (done) { + it.skip('队伍结束攻击', function (done) { pinusClient.request('guild.gvgBattleHandler.battleEnd', { battleCode, isSuccess, @@ -174,14 +183,14 @@ describe.skip('gvg激战期测试', function () { } // 队伍开始攻击且获胜 - it('队伍开始攻击且获胜', function (done) { + it.skip('队伍开始攻击且获胜', function (done) { const teamCode = ''; const oppoTeamCode = ''; battle(teamCode, oppoTeamCode, true, done); }); // 队伍开始攻击且失败 - it('队伍开始攻击且失败', function (done) { + it.skip('队伍开始攻击且失败', function (done) { const teamCode = ''; const oppoTeamCode = ''; battle(teamCode, oppoTeamCode, false, done); @@ -200,14 +209,14 @@ describe.skip('gvg激战期测试', function () { // 使用道具 // ! 不同道具添加多个测试用例 - it('使用道具', function (done) { + it.skip('使用道具', function (done) { const itemId = 1; const teamCode = ''; useItem(itemId, teamCode, done); }); // 复活队伍 - it('复活队伍', function (done) { + it.skip('复活队伍', function (done) { const teamCode = ''; pinusClient.request('guild.gvgBattleHandler.reviveTeam', {}, (data) => { checkSuccessResponse(data); @@ -219,7 +228,10 @@ describe.skip('gvg激战期测试', function () { // 获取战报 getRecs // ! 战报具体内容未检查 it('获取战报', function (done) { - pinusClient.request('guild.gvgBattleHandler.getRecs', {}, (data) => { + const type = 1; + pinusClient.request('guild.gvgBattleHandler.getRecs', { + type, + }, (data) => { checkSuccessResponse(data); expect(data.data.recs).to.be.an('array'); done(); @@ -239,7 +251,7 @@ describe.skip('gvg激战期测试', function () { }); // 获取区域上的队伍 getAreaTeams - it('获取区域上的队伍', function (done) { + it.skip('获取区域上的队伍', function (done) { const cityId = 1; const areaIds = [1, 2, 3]; pinusClient.request('guild.gvgBattleHandler.getAreaTeams', { diff --git a/shared/consts/statusCode.ts b/shared/consts/statusCode.ts index 8b4f6925a..b3ce768ea 100644 --- a/shared/consts/statusCode.ts +++ b/shared/consts/statusCode.ts @@ -336,6 +336,7 @@ export const STATUS = { GVG_TASK_HAS_RECEIVED: { code: 21330, simStr: '任务已领取过' }, GVG_BATTLE_CITY_FULL: { code: 21331, simStr: '城市已满员' }, GVG_BATTLE_TEAM_INVALID: { code: 21332, simStr: '无效的队伍' }, + GVG_CITY_NOT_FOUND: { code: 21333, simStr: '城池不存在' }, // GVG征战中原 GVG_VESTIGE_ERR: { code: 21350, simStr: '今日未开放该遗迹' }, diff --git a/shared/db/GVGCity.ts b/shared/db/GVGCity.ts index 8993d2587..0f93dbc81 100644 --- a/shared/db/GVGCity.ts +++ b/shared/db/GVGCity.ts @@ -10,7 +10,7 @@ export default class GVGCity extends BaseModel { @prop({ required: true }) cityId: number; // 城池id - @prop({ required: true }) + @prop({ required: true, default: [] }) leagueCodes: string[]; // 联军 @prop({ required: false }) @@ -24,6 +24,20 @@ export default class GVGCity extends BaseModel { @prop({ required: true, default: 0 }) teamCnt: number; // 城池队伍数 + + // 创建城市 + public static async createCity(configId: 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(); + return city; + } + + // 通过 cityId 获取城市 + public static async getCityByCityId(cityId: number) { + const city: GVGCityType | null = await GVGCityModel.findOne({ cityId }).lean(); + return city; + } } diff --git a/shared/db/GVGTeam.ts b/shared/db/GVGTeam.ts index 79b723deb..eaabf7778 100644 --- a/shared/db/GVGTeam.ts +++ b/shared/db/GVGTeam.ts @@ -1,6 +1,7 @@ // GVGTeam 数据库表,存储 GVG 队伍信息 import BaseModel from "./BaseModel"; import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose'; +import { genCode } from "../pubUtils/util"; @index({ roleId: 1, teamId: 1 }) @index({ teamCode: 1 }) @@ -9,7 +10,10 @@ export default class GVGTeam extends BaseModel { roleId: string; // 玩家id @prop({ required: true }) - teamCode: string; // 玩家队伍id,3个队伍 + teamCode: string; // 玩家队伍唯一标识 + + @prop({ required: true }) + teamId: number; // 队伍id,1-3,玩家的第几个队伍 @prop({ required: true }) leagueCode: string; // 联军 @@ -53,6 +57,15 @@ export default class GVGTeam extends BaseModel { dataId: number; // 位置 order: number; // 进攻顺序 }] + + // 创建队伍 + public static async createTeam(roleId: string, leagueCode: string, teamId: number, head: number, spine: number, frame: number, lineup: any) { + const doc = new GVGTeamModel(); + const teamCode = genCode(8); + let update = Object.assign(doc.toJSON(), { roleId, leagueCode, teamId, teamCode, head, spine, frame, lineup }); + const team: GVGTeamType | null = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $setOnInsert: update }, { upsert: true, new: true }).lean(); + return team; + } } export const GVGTeamModel = getModelForClass(GVGTeam);