33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import {Command} from "@colyseus/command";
|
|
import {CardGameState} from "../schema/CardGameState";
|
|
import {Client} from "colyseus";
|
|
import {PlayerStateConst} from "../../constants/PlayerStateConst";
|
|
import {GameStateConst} from "../../constants/GameStateConst";
|
|
|
|
/**
|
|
* 玩家已准备
|
|
*/
|
|
export class PlayReadyCommand extends Command<CardGameState, {
|
|
client: Client
|
|
}> {
|
|
|
|
execute({client}: { client: Client }) {
|
|
this.state.players.get(client.sessionId).state = PlayerStateConst.PLAYER_READY;
|
|
this.room.broadcast("player_ready_s2c", {player: client.sessionId}, {except: client});
|
|
let readyCount = 0;
|
|
for (let [sessionId, player] of this.state.players) {
|
|
if (player.state === PlayerStateConst.PLAYER_READY) {
|
|
readyCount++;
|
|
}
|
|
}
|
|
// 如果所有人的状态都为已准备状态, 则开始发牌
|
|
if (readyCount >= this.room.maxClients) {
|
|
// 比大小, 确定先手
|
|
// return [new PrepareCommand()];
|
|
this.room.state.gameState = GameStateConst.CHANGE_HERO;
|
|
}
|
|
|
|
}
|
|
|
|
}
|