import {Command} from "@colyseus/command"; import {CardGameState} from "../schema/CardGameState"; import {Client} from "colyseus"; import {PlayerStateConst} from "../../constants/PlayerStateConst"; import {BeginGameCommand} from "./BeginGameCommand"; import {BattleHandler} from "../logic/Handler/BattleHandler"; import {BaseConst} from "../../constants/BaseConst"; /** * 选择英雄 */ export class SelectHeroCommand extends Command { execute({ client, heroId} = this.payload) { let player = this.state.players.get(client.sessionId); const heroMap = global.$cfg.get(BaseConst.HERO); if (!heroMap || !heroMap.has(heroId)) { this.room.sSelectHero(client, {errcode: 1, errmsg: '无法找到对应英雄的配置'}); return; } player.heroId = heroId; player.state = PlayerStateConst.PLAYER_SELECT_HERO; this.room.battleMan.addPlayer(player); this.room.bSelectHero({errocode: 0, errmsg: '', player: client.sessionId, heroId: heroId}); let readyCount = 0; for (let [sessionId, player] of this.state.players) { if (player.state === PlayerStateConst.PLAYER_SELECT_HERO) { readyCount++; } } if (readyCount >= this.room.maxClients) { return [new BeginGameCommand()]; } } }