card_svr/src/rooms/commands/DrawCommand.ts
2020-12-14 13:15:47 +08:00

30 lines
1.2 KiB
TypeScript

import {Command} from "@colyseus/command";
import {CardGameState} from "../schema/CardGameState";
import {singleton} from "../../common/Singleton";
import {GameEnv} from "../../cfg/GameEnv";
import {debugRoom} from "../../common/Debug";
import {DiscardCommand} from "./DiscardCommand";
/**
* 正常的抽卡
*/
export class DrawCommand extends Command<CardGameState, {}> {
async execute() {
let sessionId = this.state.currentTurn;
this.room.addCard(sessionId, singleton(GameEnv).roundDrawNum, 0);
let maxTime = singleton(GameEnv).maxDiscardTime * 1000;
let player = this.state.players.get(sessionId);
let self = this;
let timeOverDraw = function () {
if (sessionId == self.state.currentTurn) {
let client = self.room.getClient(sessionId);
let card = player.cards.values().next().value;
debugRoom('出牌时间到, 自动出牌: ', card.id);
player.extraTime = 0;
self.room.dispatcher.dispatch(new DiscardCommand(), {client, cards: [card.id], dtype: 1});
}
}
this.room.beginSchedule(maxTime + player.extraTime, timeOverDraw, `draw_card`);
}
}