diff --git a/cockatrice/src/game/player/player.cpp b/cockatrice/src/game/player/player.cpp index 75f4ebfde..871e289c9 100644 --- a/cockatrice/src/game/player/player.cpp +++ b/cockatrice/src/game/player/player.cpp @@ -1331,10 +1331,10 @@ void Player::actMoveTopCardsToExile() void Player::actMoveTopCardsUntil() { - moveTopCardTimer->stop(); - movingCardsUntil = false; + stopMoveTopCardsUntil(); + QString expr = previousMovingCardsUntilExpr; - uint numberOfHits = 1; + int numberOfHits = previousMovingCardsUntilNumberOfHits; for (;;) { DlgMoveTopCardsUntil dlg(game, expr, numberOfHits); if (!dlg.exec()) { @@ -1355,9 +1355,11 @@ void Player::actMoveTopCardsUntil() } } previousMovingCardsUntilExpr = expr; + previousMovingCardsUntilNumberOfHits = numberOfHits; if (zones.value("deck")->getCards().empty()) { - movingCardsUntil = false; + stopMoveTopCardsUntil(); } else { + movingCardsUntilCounter = numberOfHits; movingCardsUntil = true; actMoveTopCardToPlay(); } @@ -1366,13 +1368,30 @@ void Player::actMoveTopCardsUntil() void Player::moveOneCardUntil(const CardInfoPtr card) { moveTopCardTimer->stop(); - if (zones.value("deck")->getCards().empty() || card.isNull() || movingCardsUntilFilter.check(card)) { - movingCardsUntil = false; + if (zones.value("deck")->getCards().empty() || card.isNull()) { + stopMoveTopCardsUntil(); + } else if (movingCardsUntilFilter.check(card)) { + --movingCardsUntilCounter; + if (movingCardsUntilCounter > 0) { + moveTopCardTimer->start(); + } else { + stopMoveTopCardsUntil(); + } } else { moveTopCardTimer->start(); } } +/** + * @brief Immediately stops any ongoing `play top card to stack until...` process, resetting all variables involved. + */ +void Player::stopMoveTopCardsUntil() +{ + moveTopCardTimer->stop(); + movingCardsUntilCounter = 0; + movingCardsUntil = false; +} + void Player::actMoveTopCardToBottom() { if (zones.value("deck")->getCards().empty()) { diff --git a/cockatrice/src/game/player/player.h b/cockatrice/src/game/player/player.h index 7f744a909..24641679f 100644 --- a/cockatrice/src/game/player/player.h +++ b/cockatrice/src/game/player/player.h @@ -267,7 +267,10 @@ private: bool movingCardsUntil; QTimer *moveTopCardTimer; QString previousMovingCardsUntilExpr = {}; + int previousMovingCardsUntilNumberOfHits = 1; FilterString movingCardsUntilFilter; + int movingCardsUntilCounter = 0; + void stopMoveTopCardsUntil(); bool shortcutsActive; int defaultNumberTopCards = 1;