do nothing if target is already attached

This commit is contained in:
RickyRister 2024-12-15 18:12:06 -08:00
parent 4f7326f637
commit 3eea394236
2 changed files with 31 additions and 19 deletions

View file

@ -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<CardItem *>(startItem);
CardZone *startZone = startCard->getZone();
CardItem *targetCard = qgraphicsitem_cast<CardItem *>(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<CardItem *>(startItem);
auto targetCard = qgraphicsitem_cast<CardItem *>(targetItem);
attachCards(startCard, targetCard);
}
delArrow();

View file

@ -88,6 +88,8 @@ class ArrowAttachItem : public ArrowItem
private:
QList<ArrowAttachItem *> childArrows;
void attachCards(CardItem *startCard, const CardItem *targetCard);
public:
ArrowAttachItem(ArrowTarget *_startItem);
void addChildArrow(ArrowAttachItem *childArrow);