card_svr/src/rooms/commands/OnJoinCommand.ts
2020-12-04 16:51:38 +08:00

27 lines
937 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
}> {
execute({client} = this.payload) {
let team = this.state.players.size / 2 | 0;
let player = new Player(client.sessionId, 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});
}
}