From 2599b711cdb9604d0c8d2a6a80f2fc2969105e49 Mon Sep 17 00:00:00 2001 From: zhl Date: Fri, 19 Feb 2021 19:27:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=88=E5=B9=B6=E5=90=83=E7=89=8C=E5=92=8C?= =?UTF-8?q?=E5=87=BA=E7=89=8C=E6=B5=81=E7=A8=8B?= 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 | 36 +++++++++++++++++++--------- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/rooms/GeneralRoom.ts b/src/rooms/GeneralRoom.ts index 16c776f..868d4eb 100644 --- a/src/rooms/GeneralRoom.ts +++ b/src/rooms/GeneralRoom.ts @@ -66,7 +66,7 @@ export class GeneralRoom extends Room { }); this.onMessage("discard_card_c2s", (client, message) => { msgLog('discard_card from ', client.sessionId, JSON.stringify(message)); - this.dispatcher.dispatch(new DiscardCommand(), {client, cards: message.cards, dtype: 0}); + this.dispatcher.dispatch(new DiscardCommand(), {client, cards: message.cards, target: message.target, dtype: 0}); }); this.onMessage("eat_card_c2s", (client, message) => { msgLog('eat_card from ', client.sessionId, JSON.stringify(message)); diff --git a/src/rooms/commands/DiscardCommand.ts b/src/rooms/commands/DiscardCommand.ts index 2351158..1600197 100644 --- a/src/rooms/commands/DiscardCommand.ts +++ b/src/rooms/commands/DiscardCommand.ts @@ -14,16 +14,17 @@ import {StateTypeEnum} from "../enums/StateTypeEnum"; /** * 出牌 + * target: 如果是吃牌, 则带上此字段 * 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); // } - async execute({ client, cards , dtype} = this.payload) { + async execute({ client, cards , target, dtype} = this.payload) { const player = this.state.players.get(client.sessionId); if (!player) { this.room.send(client,'discard_card_s2c', {errcode: 1, errmsg: 'player不存在'}); @@ -52,9 +53,21 @@ export class DiscardCommand extends Command 1) { + this.room.send(client,'discard_card_s2c', {errcode: 6, errmsg: '不符合吃牌规则'}); + return; + } + if (!this.state.cards.has(target)) { + this.room.send(client,'discard_card_s2c', {errcode: 5, errmsg: '找不到要吃的牌'}); + return; + } + } else { + for (let [key, val] of this.state.cards) { + this.state.cards.delete(key); + } } + //停止出牌计时, 并更新player.extraTime; let elapsedTime = this.room.stopSchedule('draw_card'); if (elapsedTime >= 0) { @@ -78,17 +91,18 @@ export class DiscardCommand extends Command o.id) let self = this; - this.room.send(client,'eat_card_s2c', {player: player.id, errcode: 0, errmsg: '', cards: cardids}); + this.room.send(client,'eat_card_s2c', {player: player.id, errcode: 0, errmsg: '', cards: cards}); let delay = this.room.battleMan.onCardLinkOver(player, cardArr); player.statData.inc(StateTypeEnum.EATCOUNT, 1); await this.delay(delay);