diff --git a/src/rooms/GeneralRoom.ts b/src/rooms/GeneralRoom.ts index 4f767b7..3f18b9d 100644 --- a/src/rooms/GeneralRoom.ts +++ b/src/rooms/GeneralRoom.ts @@ -36,7 +36,7 @@ export class GeneralRoom extends Room { }); this.onMessage("discard_card_c2s", (client, message) => { debugRoom('discard_card from ', client.sessionId, message); - this.dispatcher.dispatch(new DiscardCommand(), {client, cards: message.cards}); + this.dispatcher.dispatch(new DiscardCommand(), {client, cards: message.cards, dtype: 0}); }); this.onMessage("eat_card_c2s", (client, message) => { debugRoom('eat_card from ', client.sessionId, message); diff --git a/src/rooms/commands/DiscardCommand.ts b/src/rooms/commands/DiscardCommand.ts index 3b6895f..b3b771c 100644 --- a/src/rooms/commands/DiscardCommand.ts +++ b/src/rooms/commands/DiscardCommand.ts @@ -7,14 +7,16 @@ import {GameStateConst} from "../../constants/GameStateConst"; /** * 出牌 + * type: 0, 正常的抽牌 + * type: 1, 到时间后, 自动的抽牌 */ -export class DiscardCommand extends Command { +export class DiscardCommand extends Command { // validate({ client, cards } = this.payload) { // const player = this.state.players.get(client.sessionId); // return player !== undefined && gameUtil.checkCardsExists(player.cards, cards); // } - execute({ client, cards } = this.payload) { + execute({ client, cards , dtype} = this.payload) { const player = this.state.players.get(client.sessionId); if (!player) { client.send('discard_card_s2c', {errcode: 1, errmsg: 'player不存在'}); @@ -47,6 +49,7 @@ export class DiscardCommand extends Command { let maxTime = singleton(GameEnv).maxDiscardTime; await this.delay(maxTime * 1000); if (sessionId == this.state.currentTurn) { + let client = this.room.getClient(sessionId); error('出牌时间到, 自动出牌'); - //TODO: 自动出牌 + let player = this.state.players.get(sessionId); + let card = player.cards.values().next().value; + return [new DiscardCommand().setPayload({client, cards: [card.id], dtype: 1})] } } }