ability to directly attach from other zones (#5250)

* add attach and draw arrow actions to more card menus

* implement attaching from other zones

* disallow attaching from deck

* do nothing if target is already attached

* add null check
This commit is contained in:
RickyRister 2024-12-17 20:38:22 -08:00 committed by GitHub
parent c9d5d5609c
commit 03db4ccce6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 89 additions and 13 deletions

View file

@ -307,25 +307,43 @@ 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();
Command_AttachCard cmd;
cmd.set_start_zone(startZone->getName().toStdString());
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);
if (startCard && targetCard) {
attachCards(startCard, targetCard);
}
}
delArrow();