From b048727ac31965f69164dafdada43f55f0c025f1 Mon Sep 17 00:00:00 2001 From: zhl Date: Sat, 20 Feb 2021 11:44:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=9C=BA=E5=99=A8=E4=BA=BA?= =?UTF-8?q?=E7=9A=84=E5=87=BA=E7=89=8C=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/robot/Robot.ts | 23 +++++++++++++++++------ src/robot/RobotClient.ts | 22 +++++++++++++++++----- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/src/robot/Robot.ts b/src/robot/Robot.ts index 9ea162e..e2c76ee 100644 --- a/src/robot/Robot.ts +++ b/src/robot/Robot.ts @@ -168,13 +168,24 @@ export class Robot { if (!cards) { return; } - let cardIds = cards.map(o => o.id); - // let cardIds = [cardArr[0].id] + let cardIds: number[] = []; + let hasEatCard = false; + for (let card of cards) { + if (!targetCard || (targetCard && card.id !== targetCard.id)) { + cardIds.push(card.id); + } + if (targetCard && card.id == targetCard.id) { + hasEatCard = true + } + } log(`discard: ${self.sessionId} ${cardIds}`); - self.reply('discard_card_c2s', { - cards: cardIds, - target: targetCard.id - }); + let repData: any = { + cards: cardIds + } + if (hasEatCard) { + repData.target = targetCard.id + } + self.reply('discard_card_c2s', repData); } /** diff --git a/src/robot/RobotClient.ts b/src/robot/RobotClient.ts index 64de35c..390e46e 100644 --- a/src/robot/RobotClient.ts +++ b/src/robot/RobotClient.ts @@ -145,12 +145,24 @@ export class RobotClient implements Client { if (!cards) { return; } - let cardIds = cards.map(o => o.id); + let cardIds: number[] = []; + let hasEatCard = false; + for (let card of cards) { + if (!targetCard || (targetCard && card.id !== targetCard.id)) { + cardIds.push(card.id); + } + if (targetCard && card.id == targetCard.id) { + hasEatCard = true + } + } log(`discard: ${self.sessionId} ${cardIds}`); - self.reply('discard_card_c2s', { - cards: cardIds, - target: targetCard.id - }); + let repData: any = { + cards: cardIds + } + if (hasEatCard) { + repData.target = targetCard.id + } + self.reply('discard_card_c2s', repData); } /**