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"; import {error} from "../../common/Debug"; /** * 选择英雄 */ 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; } const heroData = heroMap.get(heroId); player.heroId = heroId; const unitMap = global.$cfg.get(BaseConst.UNIT); const unitData = unitMap.get(heroData.herounit_id); if (!unitData) { error(`未找到英雄的Unit配置: ${heroId}`); } player.state = PlayerStateConst.PLAYER_SELECT_HERO; player.hp = unitData.hero_hp; let heroPet = player.pets.get('0'); heroPet.ap = unitData.powernum; if (unitData.base_skill1id) heroPet.skills.push(unitData.base_skill1id); if (unitData.base_skill2id) heroPet.skills.push(unitData.base_skill2id); if (unitData.base_skill3id) heroPet.skills.push(unitData.base_skill3id); 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()]; } } }