From f19adf27f928b697ad9d355f82a0fe9240c0cf3f Mon Sep 17 00:00:00 2001 From: zhl Date: Mon, 14 Dec 2020 14:06:49 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=89=E6=8B=A9=E8=8B=B1=E9=9B=84=E7=95=8C?= =?UTF-8?q?=E9=9D=A2=E5=A2=9E=E5=8A=A0=E8=B6=85=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cfg/GameEnv.ts | 3 +++ src/constants/BaseConst.ts | 2 ++ src/rooms/commands/PlayReadyCommand.ts | 23 +++++++++++++++++++++++ src/rooms/commands/SelectHeroCommand.ts | 10 +++++++--- 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/cfg/GameEnv.ts b/src/cfg/GameEnv.ts index 711aa75..9fab6f4 100644 --- a/src/cfg/GameEnv.ts +++ b/src/cfg/GameEnv.ts @@ -40,6 +40,8 @@ export class GameEnv { public waitingPlayerTime: number; // 匹配等待时, 每进入一个玩家, 等待时间延长n秒 public waitingPlayerOnePlus: number; + // 英雄选择时间 + public pickHeroTime: number; public init(data: Map) { this.initCardNum = data.get(BaseConst.INIT_CARD_NUM).value; @@ -61,5 +63,6 @@ export class GameEnv { this.gameResultTime = data.get(BaseConst.GAME_RESULT_TIME).value; this.waitingPlayerTime = data.get(BaseConst.WAITING_PLAYER_TIME).value; this.waitingPlayerOnePlus = data.get(BaseConst.WAITING_PLAYER_ONEPLUS).value; + this.pickHeroTime = data.get(BaseConst.PICK_HERO_TIME).value; } } diff --git a/src/constants/BaseConst.ts b/src/constants/BaseConst.ts index 0fd9dac..5784ede 100644 --- a/src/constants/BaseConst.ts +++ b/src/constants/BaseConst.ts @@ -37,6 +37,8 @@ export class BaseConst { public static readonly WAITING_PLAYER_TIME = 99018; // 匹配等待时, 每进入一个玩家, 等待时间延长n秒 public static readonly WAITING_PLAYER_ONEPLUS = 99019; + // 英雄选择时间 + public static readonly PICK_HERO_TIME = 99020; diff --git a/src/rooms/commands/PlayReadyCommand.ts b/src/rooms/commands/PlayReadyCommand.ts index 6bd9312..03e322f 100644 --- a/src/rooms/commands/PlayReadyCommand.ts +++ b/src/rooms/commands/PlayReadyCommand.ts @@ -3,6 +3,12 @@ import {CardGameState} from "../schema/CardGameState"; import {Client} from "colyseus"; import {PlayerStateConst} from "../../constants/PlayerStateConst"; import {GameStateConst} from "../../constants/GameStateConst"; +import {singleton} from "../../common/Singleton"; +import {GameEnv} from "../../cfg/GameEnv"; +import {SelectHeroCommand} from "./SelectHeroCommand"; +import {HeroCfg} from "../../cfg/parsers/HeroCfg"; +import {BaseConst} from "../../constants/BaseConst"; +import arrUtil from "../../utils/array.util"; /** * 玩家已准备 @@ -32,6 +38,23 @@ export class PlayReadyCommand extends Command = global.$cfg.get(BaseConst.HERO); + let heroArr = [...heroMap.values()]; + let hero = arrUtil.randomGet(heroArr, 1); + let targetClient = self.room.getClient(curPlayer); + self.room.dispatcher.dispatch(new SelectHeroCommand(), {client: targetClient, heroId: hero[0].id}); + } + } + } + let time = singleton(GameEnv).pickHeroTime * 1000; + this.room.beginSchedule(time, pickHeroTimeOut, 'pick_hero'); } } diff --git a/src/rooms/commands/SelectHeroCommand.ts b/src/rooms/commands/SelectHeroCommand.ts index 733c807..8227324 100644 --- a/src/rooms/commands/SelectHeroCommand.ts +++ b/src/rooms/commands/SelectHeroCommand.ts @@ -11,9 +11,12 @@ import {GameEnv} from "../../cfg/GameEnv"; /** * 选择英雄 */ -export class SelectHeroCommand extends Command { - execute({ client, heroId} = this.payload) { +export class SelectHeroCommand extends Command { + execute({client, heroId} = this.payload) { let player = this.state.players.get(client.sessionId); + if (player.state != PlayerStateConst.PLAYER_READY) { + return; + } const heroMap = global.$cfg.get(BaseConst.HERO); if (!heroMap || !heroMap.has(heroId)) { this.room.sSelectHero(client, {errcode: 1, errmsg: '无法找到对应英雄的配置'}); @@ -39,12 +42,13 @@ export class SelectHeroCommand extends Command= this.room.maxClients) { + this.room.stopSchedule('pick_hero'); return [new BeginGameCommand()]; } }