From 09480cd4c0b638c6e02783b4236859d232f85323 Mon Sep 17 00:00:00 2001 From: zhl Date: Mon, 7 Dec 2020 17:36:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8A=BD=E5=8D=A1=E5=90=8E?= =?UTF-8?q?=E8=B6=85=E6=97=B6=E8=87=AA=E5=8A=A8=E5=87=BA=E5=8D=A1=E7=9A=84?= =?UTF-8?q?=E8=AE=BE=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/rooms/GeneralRoom.ts | 2 +- src/rooms/commands/DiscardCommand.ts | 7 +++++-- src/rooms/commands/DrawCommand.ts | 6 +++++- 3 files changed, 11 insertions(+), 4 deletions(-) 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})] } } }