[Game] Reveal multiple distinct random hand cards to a recipient (#7753)

* Add distinct random hand reveals with private recipient delivery

* Route random hand reveals through PlayerActions

Keep command creation, dispatch and response handling in the game action
layer. HandMenu requests the typed operation and presents the count and
failure dialogs. Show the chosen recipient, distinguish the count action
from the immediate single-card reveal, and use the game window as parent.

* Apply project formatting to random-reveal warning construction

* Simplify random reveal to follow existing command patterns

Forward server dispatch through cmdRevealRandomCards and use ordinary PlayerActions command sending. Remove the bespoke server-version error UI and long-lived-object guards.

Reduce the test from 246 to 150 lines with two focused cases using the current RoleInfo player API, preserving distinct-card, private-event and rejected-count coverage.

* Extract the shared reveal helper and name the test's CardRef fields

RickyRister asked for cmdRevealCards and cmdRevealRandomCards to share a
helper instead of threading a randomCount parameter through the reveal
virtual. Restore the three-argument cmdRevealCards signature, resolve the
reveal preconditions and zone in resolveRevealZone, and let both commands
build their card list and hand it to revealCards, which owns the private and
public Event_RevealCards construction and the enqueue. The random command no
longer fabricates a Command_RevealCards with the -2 sentinel to re-enter the
legacy path; its behaviour is unchanged.

Name the CardRef fields in random_reveal_test instead of relying on
declaration order, and state in the user documentation that a rejected
reveal is not reported in the client, matching what the client does.

---------

Co-authored-by: Lukas Brübach <44814898+BruebachL@users.noreply.github.com>
This commit is contained in:
Bryce! 2026-11-08 10:41:14 -05:00 • committed by GitHub
parent 39220a2ea9
commit 078d0858a3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 375 additions and 17 deletions

View file

@ -6,6 +6,9 @@
#include "../player_graphics_item.h"
#include <QAction>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QInputDialog>
#include <QKeySequence>
#include <QList>
#include <QMap>
@ -67,6 +70,15 @@ HandMenu::HandMenu(PlayerGraphicsItem *_player, QWidget *parent) : TearOffMenu(p
aRevealRandomHandCardToAll->setData(-1);
connect(aRevealRandomHandCardToAll, &QAction::triggered, this, &HandMenu::onRevealRandomHandCardTriggered);
mRevealRandomHandCards = addMenu(QString());
mRevealRandomHandCards->setObjectName("revealRandomHandCardsMenu");
connect(mRevealRandomHandCards, &QMenu::aboutToShow, this,
&HandMenu::populateRevealRandomHandCardsMenuWithActivePlayers);
aRevealRandomHandCardsToAll = new QAction(this);
aRevealRandomHandCardsToAll->setData(-1);
connect(aRevealRandomHandCardsToAll, &QAction::triggered, this, &HandMenu::onRevealRandomHandCardsTriggered);
mRevealRandomHandCards->addAction(aRevealRandomHandCardsToAll);
// We still need to add these actions to menu here so that the shortcuts are active right away
mRevealHand->addAction(aRevealHandToAll);
mRevealRandomHandCard->addAction(aRevealRandomHandCardToAll);
@ -146,6 +158,8 @@ void HandMenu::retranslateUi()
mRevealRandomHandCard->setTitle(tr("Reveal r&andom card to..."));
aRevealRandomHandCardToAll->setText(tr("All players"));
mRevealRandomHandCards->setTitle(tr("Reveal a chosen number of random cards to..."));
aRevealRandomHandCardsToAll->setText(tr("All players"));
}
}
@ -233,3 +247,51 @@ void HandMenu::onRevealRandomHandCardTriggered()
const int targetId = action->data().toInt();
player->getLogic()->getPlayerActions()->actRevealRandomHandCard(targetId);
}
void HandMenu::populateRevealRandomHandCardsMenuWithActivePlayers()
{
const bool hasCards = !player->getLogic()->getHandZone()->getCards().isEmpty();
mRevealRandomHandCards->clear();
aRevealRandomHandCardsToAll->setEnabled(hasCards);
mRevealRandomHandCards->addAction(aRevealRandomHandCardsToAll);
mRevealRandomHandCards->addSeparator();
const auto &players = player->getLogic()->getGame()->getPlayerManager()->getPlayers().values();
for (auto *other : players) {
if (other == player->getLogic()) {
continue;
}
auto *action = mRevealRandomHandCards->addAction(other->getPlayerInfo()->getName());
action->setData(other->getPlayerInfo()->getId());
action->setEnabled(hasCards);
connect(action, &QAction::triggered, this, &HandMenu::onRevealRandomHandCardsTriggered);
}
}
void HandMenu::onRevealRandomHandCardsTriggered()
{
const auto *action = qobject_cast<QAction *>(sender());
const int handSize = player->getLogic()->getHandZone()->getCards().size();
if (!action || handSize == 0) {
return;
}
const int targetId = action->data().toInt();
auto *actions = player->getLogic()->getPlayerActions();
auto *dialog = new QInputDialog(dialogParent());
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->setWindowTitle(tr("Reveal Random Hand Cards"));
dialog->setLabelText(tr("Number of distinct random cards to reveal to %1:").arg(action->text()));
dialog->setInputMode(QInputDialog::IntInput);
dialog->setIntRange(1, handSize);
dialog->setIntValue(qMin(2, handSize));
connect(dialog, &QDialog::accepted, actions,
[dialog, actions, targetId] { actions->actRevealRandomHandCards(targetId, dialog->intValue()); });
dialog->open();
}
QWidget *HandMenu::dialogParent() const
{
if (auto *view = player->scene() ? player->scene()->views().value(0) : nullptr) {
return view->window();
}
return nullptr;
}

View file

@ -42,8 +42,11 @@ private slots:
void populateRevealRandomHandCardMenuWithActivePlayers();
void onRevealHandTriggered();
void onRevealRandomHandCardTriggered();
void populateRevealRandomHandCardsMenuWithActivePlayers();
void onRevealRandomHandCardsTriggered();
private:
QWidget *dialogParent() const;
PlayerGraphicsItem *player;
QAction *aViewHand = nullptr;
@ -62,6 +65,9 @@ private:
QMenu *mRevealRandomHandCard = nullptr;
QAction *aRevealRandomHandCardToAll = nullptr;
QMenu *mRevealRandomHandCards = nullptr;
QAction *aRevealRandomHandCardsToAll = nullptr;
QMenu *mMoveHandMenu = nullptr;
QAction *aMoveHandToTopLibrary = nullptr;
QAction *aMoveHandToBottomLibrary = nullptr;