37 lines
1.2 KiB
TypeScript
37 lines
1.2 KiB
TypeScript
import {Command} from "@colyseus/command";
|
|
import {CardGameState} from "../schema/CardGameState";
|
|
import {GameStateConst} from "../../constants/GameStateConst";
|
|
import gameUtil from "../../utils/game.util";
|
|
import {GameEnv} from "../../cfg/GameEnv";
|
|
import {NextTurnCommand} from "./NextTurnCommand";
|
|
|
|
/**
|
|
* 开始游戏
|
|
* 1. 生成卡组
|
|
* 2. 将游戏状态改为 STATE_CHANGE_CARD
|
|
*/
|
|
export class BeginGameCommand extends Command<CardGameState, {}> {
|
|
|
|
async execute() {
|
|
this.room.battleMan.onGameStart();
|
|
this.state.maxCardId = 0;
|
|
let card0 = gameUtil.initCardQue();
|
|
let card1 = gameUtil.initCardQue();
|
|
let cardAll = card0.concat(card1);
|
|
cardAll.randomSort();
|
|
this.state.cardQueue = cardAll;
|
|
let i = 1;
|
|
for (let [id] of this.state.players) {
|
|
this.room.addCard(id, new GameEnv().playerInitNums[i++], 0);
|
|
}
|
|
this.state.updateGameState(GameStateConst.STATE_CHANGE_CARD);
|
|
// 超时后结束换卡, 进入下一轮
|
|
const cardChangeTime = new GameEnv().cardChangeTime;
|
|
await this.delay(cardChangeTime*1000);
|
|
if (this.state.gameState == GameStateConst.STATE_CHANGE_CARD) {
|
|
return [new NextTurnCommand()];
|
|
}
|
|
}
|
|
|
|
}
|