From bd7c8dfae5d34c51b824d294b4c813a6087c91f8 Mon Sep 17 00:00:00 2001 From: zhl Date: Mon, 14 Dec 2020 20:40:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=9C=AA=E7=82=B9=E5=87=BB?= =?UTF-8?q?=E7=A1=AE=E8=AE=A4=E7=8E=A9=E5=AE=B6=E7=9A=84=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/rooms/commands/GameRestartCommand.ts | 17 +++++++++++++---- src/rooms/commands/GameResultCommand.ts | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/rooms/commands/GameRestartCommand.ts b/src/rooms/commands/GameRestartCommand.ts index fd0e94f..3c9a926 100644 --- a/src/rooms/commands/GameRestartCommand.ts +++ b/src/rooms/commands/GameRestartCommand.ts @@ -2,15 +2,24 @@ import {Command} from "@colyseus/command"; import {CardGameState} from "../schema/CardGameState"; import {Client} from "colyseus"; import {PlayReadyCommand} from "./PlayReadyCommand"; +import {PlayerStateConst} from "../../constants/PlayerStateConst"; +import {error} from "../../common/Debug"; export class GameRestartCommand extends Command { execute({client} = this.payload) { - this.state.restartCount ++; - if (this.state.restartCount >= this.room.maxClients) { - this.room.stopSchedule('restart_schedule'); + let player = this.state.players.get(client.sessionId); + if (player) { + this.state.restartCount ++; + player.state = PlayerStateConst.PLAYER_NORMAL; + if (this.state.restartCount >= this.room.maxClients) { + this.room.stopSchedule('restart_schedule'); + } + } else { + error(`${client.sessionId} not found!!`) } - return [new PlayReadyCommand().setPayload({client})]; + + // return [new PlayReadyCommand().setPayload({client})]; } } diff --git a/src/rooms/commands/GameResultCommand.ts b/src/rooms/commands/GameResultCommand.ts index c18e8fb..7abbef1 100644 --- a/src/rooms/commands/GameResultCommand.ts +++ b/src/rooms/commands/GameResultCommand.ts @@ -69,7 +69,7 @@ export class GameResultCommand extends Command { } else if (self.state.restartCount < self.room.maxClients){ // 如果点击重开的玩家少于房间最大人数, 则把房间设为公开, 等待其他玩家匹配进来 for (let [,player] of self.state.players) { - if (player.state !== PlayerStateConst.PLAYER_READY) { + if (player.state !== PlayerStateConst.PLAYER_NORMAL) { let client = self.room.getClient(player); debugRoom(`清除没点击重新开始的玩家 ${client.sessionId}`); client.leave();