From 3eea394236850a56c833b55fdf8f66dffe7a687d Mon Sep 17 00:00:00 2001 From: RickyRister Date: Sun, 15 Dec 2024 18:12:06 -0800 Subject: [PATCH] do nothing if target is already attached --- cockatrice/src/game/board/arrow_item.cpp | 48 ++++++++++++++---------- cockatrice/src/game/board/arrow_item.h | 2 + 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/cockatrice/src/game/board/arrow_item.cpp b/cockatrice/src/game/board/arrow_item.cpp index 7a3a7dd35..61fab0b76 100644 --- a/cockatrice/src/game/board/arrow_item.cpp +++ b/cockatrice/src/game/board/arrow_item.cpp @@ -307,31 +307,41 @@ void ArrowAttachItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) } } +void ArrowAttachItem::attachCards(CardItem *startCard, const CardItem *targetCard) +{ + // do nothing if target is already attached to another card + if (targetCard->getAttachedTo()) { + return; + } + + CardZone *startZone = startCard->getZone(); + CardZone *targetZone = targetCard->getZone(); + + // move card onto table first if attaching from some other zone + if (startZone->getName() != "table") { + auto info = startCard->getInfo(); + player->playCardToTable(startCard, false, info ? info->getCipt() : false); + } + + Command_AttachCard cmd; + cmd.set_start_zone("table"); + cmd.set_card_id(startCard->getId()); + cmd.set_target_player_id(targetZone->getPlayer()->getId()); + cmd.set_target_zone(targetZone->getName().toStdString()); + cmd.set_target_card_id(targetCard->getId()); + + player->sendGameCommand(cmd); +} + void ArrowAttachItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { if (!startItem) return; if (targetItem && (targetItem != startItem)) { - CardItem *startCard = qgraphicsitem_cast(startItem); - CardZone *startZone = startCard->getZone(); - CardItem *targetCard = qgraphicsitem_cast(targetItem); - CardZone *targetZone = targetCard->getZone(); - - // move card onto table first if attaching from some other zone - if (startZone->getName() != "table") { - auto info = startCard->getInfo(); - player->playCardToTable(startCard, false, info ? info->getCipt() : false); - } - - Command_AttachCard cmd; - cmd.set_start_zone("table"); - cmd.set_card_id(startCard->getId()); - cmd.set_target_player_id(targetZone->getPlayer()->getId()); - cmd.set_target_zone(targetZone->getName().toStdString()); - cmd.set_target_card_id(targetCard->getId()); - - player->sendGameCommand(cmd); + auto startCard = qgraphicsitem_cast(startItem); + auto targetCard = qgraphicsitem_cast(targetItem); + attachCards(startCard, targetCard); } delArrow(); diff --git a/cockatrice/src/game/board/arrow_item.h b/cockatrice/src/game/board/arrow_item.h index 04d4bc207..9ca21d938 100644 --- a/cockatrice/src/game/board/arrow_item.h +++ b/cockatrice/src/game/board/arrow_item.h @@ -88,6 +88,8 @@ class ArrowAttachItem : public ArrowItem private: QList childArrows; + void attachCards(CardItem *startCard, const CardItem *targetCard); + public: ArrowAttachItem(ArrowTarget *_startItem); void addChildArrow(ArrowAttachItem *childArrow);