28 lines
979 B
TypeScript
28 lines
979 B
TypeScript
import {Command} from "@colyseus/command";
|
|
import {CardGameState} from "../schema/CardGameState";
|
|
import {Player} from "../schema/Player";
|
|
import {Client} from "colyseus";
|
|
import {GameStateConst} from "../../constants/GameStateConst";
|
|
import { BattleHandler } from "rooms/logic/Handler/BattleHandler";
|
|
import {BaseConst} from "../../constants/BaseConst";
|
|
|
|
/**
|
|
* 玩家成功加入房间
|
|
*/
|
|
export class OnJoinCommand extends Command<CardGameState, {
|
|
client: Client, battle: BattleHandler
|
|
}> {
|
|
|
|
execute({client, battle}: { client: Client, battle: BattleHandler }) {
|
|
let team = this.state.players.size / 2 | 0;
|
|
let player = new Player(0, team);
|
|
this.state.players.set(client.sessionId, player);
|
|
if (this.state.players.size >= this.room.maxClients) {
|
|
this.room.lock();
|
|
this.state.gameState = GameStateConst.STATE_WAIT_PREPARE;
|
|
}
|
|
this.room.bUserJoin(`${client.sessionId}`, {except: client});
|
|
}
|
|
|
|
}
|