mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-19 17:02:15 -07:00
implement attaching from other zones
This commit is contained in:
parent
cbb123946d
commit
481858016a
3 changed files with 48 additions and 1 deletions
|
|
@ -318,8 +318,14 @@ void ArrowAttachItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|||
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(startZone->getName().toStdString());
|
||||
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());
|
||||
|
|
|
|||
|
|
@ -2666,6 +2666,46 @@ void Player::playCard(CardItem *card, bool faceDown, bool tapped)
|
|||
sendGameCommand(cmd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Like {@link Player::playCard}, but forces the card to be played to the table zone.
|
||||
* Cards with tablerow 3 (the stack) will be played to tablerow 1 (the noncreatures row).
|
||||
*/
|
||||
void Player::playCardToTable(CardItem *card, bool faceDown, bool tapped)
|
||||
{
|
||||
if (card == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
Command_MoveCard cmd;
|
||||
cmd.set_start_player_id(card->getZone()->getPlayer()->getId());
|
||||
cmd.set_start_zone(card->getZone()->getName().toStdString());
|
||||
cmd.set_target_player_id(getId());
|
||||
CardToMove *cardToMove = cmd.mutable_cards_to_move()->add_card();
|
||||
cardToMove->set_card_id(card->getId());
|
||||
|
||||
CardInfoPtr info = card->getInfo();
|
||||
if (!info) {
|
||||
return;
|
||||
}
|
||||
|
||||
int tableRow = faceDown ? 2 : info->getTableRow();
|
||||
// default instant/sorcery cards to the noncreatures row
|
||||
if (tableRow > 2) {
|
||||
tableRow = 1;
|
||||
}
|
||||
|
||||
QPoint gridPoint = QPoint(-1, TableZone::clampValidTableRow(2 - tableRow));
|
||||
cardToMove->set_face_down(faceDown);
|
||||
if (!faceDown) {
|
||||
cardToMove->set_pt(info->getPowTough().toStdString());
|
||||
}
|
||||
cardToMove->set_tapped(faceDown ? false : tapped);
|
||||
cmd.set_target_zone("table");
|
||||
cmd.set_x(gridPoint.x());
|
||||
cmd.set_y(gridPoint.y());
|
||||
sendGameCommand(cmd);
|
||||
}
|
||||
|
||||
void Player::addCard(CardItem *card)
|
||||
{
|
||||
emit newCardAdded(card);
|
||||
|
|
|
|||
|
|
@ -390,6 +390,7 @@ public:
|
|||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
||||
|
||||
void playCard(CardItem *c, bool faceDown, bool tapped);
|
||||
void playCardToTable(CardItem *c, bool faceDown, bool tapped);
|
||||
void addCard(CardItem *c);
|
||||
void deleteCard(CardItem *c);
|
||||
void addZone(CardZone *z);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue