24 lines
696 B
TypeScript
24 lines
696 B
TypeScript
import {Command} from "@colyseus/command";
|
|
import {CardGameState} from "../schema/CardGameState";
|
|
import {Player} from "../schema/Player";
|
|
import {Client} from "colyseus";
|
|
|
|
/**
|
|
* 玩家成功加入房间
|
|
*/
|
|
export class OnJoinCommand extends Command<CardGameState, {
|
|
client: Client
|
|
}> {
|
|
|
|
execute({client}: { client: Client }) {
|
|
let team = this.state.players.size / 2 | 0;
|
|
this.state.players.set(client.sessionId, new Player(0, team));
|
|
if (this.state.players.size >= this.room.maxClients) {
|
|
this.room.lock();
|
|
this.state.gameState = 1;
|
|
}
|
|
this.room.broadcast("player_join", `${client.sessionId}`, {except: client});
|
|
}
|
|
|
|
}
|