[Game] Implement action to automatically take damage from creatures (#6869)

* [Game] Implement action to automatically take damage from creatures

* cleanup
This commit is contained in:
RickyRister 2026-05-13 15:03:41 -07:00 committed by GitHub
parent 67f6ab66f0
commit 762e742be0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 58 additions and 0 deletions

View file

@ -537,6 +537,9 @@ private:
{"Player/aSetAnnotation", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Set Annotation..."),
parseSequenceString("Alt+N"),
ShortcutGroup::Playing_Area)},
{"Player/aReduceLifeByPower", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Reduce Life by Power"),
parseSequenceString("Ctrl+Shift+L"),
ShortcutGroup::Playing_Area)},
{"Player/aSelectAll", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Select All Cards in Zone"),
parseSequenceString("Ctrl+A"),
ShortcutGroup::Playing_Area)},

View file

@ -62,6 +62,9 @@ CardMenu::CardMenu(Player *_player, const CardItem *_card, bool _shortcutsActive
aSelectColumn = new QAction(this);
connect(aSelectColumn, &QAction::triggered, playerActions, &PlayerActions::actSelectColumn);
aReduceLifeByPower = new QAction(this);
connect(aReduceLifeByPower, &QAction::triggered, playerActions, &PlayerActions::actReduceLifeByPower);
aPlay = new QAction(this);
connect(aPlay, &QAction::triggered, playerActions, &PlayerActions::actPlay);
aHide = new QAction(this);
@ -153,6 +156,8 @@ void CardMenu::createTableMenu(bool canModifyCard)
addSeparator();
addAction(aClone);
addSeparator();
addAction(aReduceLifeByPower);
addSeparator();
addAction(aSelectAll);
addAction(aSelectRow);
addRelatedCardView();
@ -179,6 +184,8 @@ void CardMenu::createTableMenu(bool canModifyCard)
addMenu(new PtMenu(player));
addAction(aSetAnnotation);
addSeparator();
addAction(aReduceLifeByPower);
addSeparator();
addAction(aSelectAll);
addAction(aSelectRow);
@ -463,6 +470,7 @@ void CardMenu::retranslateUi()
aUnattach->setText(tr("Unattac&h"));
aDrawArrow->setText(tr("&Draw arrow..."));
aSetAnnotation->setText(tr("&Set annotation..."));
aReduceLifeByPower->setText(tr("Reduce life by power"));
mCardCounters->setTitle(tr("Ca&rd counters"));
@ -497,6 +505,7 @@ void CardMenu::setShortcutsActive()
aUnattach->setShortcuts(shortcuts.getShortcut("Player/aUnattach"));
aDrawArrow->setShortcuts(shortcuts.getShortcut("Player/aDrawArrow"));
aSetAnnotation->setShortcuts(shortcuts.getShortcut("Player/aSetAnnotation"));
aReduceLifeByPower->setShortcuts(shortcuts.getShortcut("Player/aReduceLifeByPower"));
aSelectAll->setShortcuts(shortcuts.getShortcut("Player/aSelectAll"));
aSelectRow->setShortcuts(shortcuts.getShortcut("Player/aSelectRow"));

View file

@ -36,6 +36,7 @@ public:
QAction *aFlip, *aPeek;
QAction *aAttach, *aUnattach;
QAction *aSetAnnotation;
QAction *aReduceLifeByPower;
QList<QAction *> aAddCounter, aSetCounter, aRemoveCounter;

View file

@ -343,6 +343,16 @@ void Player::incrementAllCardCounters()
}
}
AbstractCounter *Player::getLifeCounter() const
{
for (auto counter : counters.values()) {
if (counter->getName() == "life") {
return counter;
}
}
return nullptr;
}
ArrowItem *Player::addArrow(const ServerInfo_Arrow &arrow)
{
const QMap<int, Player *> &playerList = game->getPlayerManager()->getPlayers();

View file

@ -199,6 +199,11 @@ public:
return counters;
}
/**
* Gets the counter that represents the life total.
*/
AbstractCounter *getLifeCounter() const;
ArrowItem *addArrow(const ServerInfo_Arrow &arrow);
ArrowItem *addArrow(int arrowId, CardItem *startCard, ArrowTarget *targetItem, const QColor &color);
void delArrow(int arrowId);

View file

@ -19,6 +19,7 @@
#include <libcockatrice/protocol/pb/command_draw_cards.pb.h>
#include <libcockatrice/protocol/pb/command_flip_card.pb.h>
#include <libcockatrice/protocol/pb/command_game_say.pb.h>
#include <libcockatrice/protocol/pb/command_inc_counter.pb.h>
#include <libcockatrice/protocol/pb/command_move_card.pb.h>
#include <libcockatrice/protocol/pb/command_mulligan.pb.h>
#include <libcockatrice/protocol/pb/command_reveal_cards.pb.h>
@ -1378,6 +1379,32 @@ void PlayerActions::actFlowT()
actIncPT(-1, 1);
}
void PlayerActions::actReduceLifeByPower()
{
// find life counter
auto lifeCounter = player->getLifeCounter();
if (!lifeCounter) {
return;
}
// calculate total power
auto cards = player->getGameScene()->selectedCards();
int total = 0;
for (auto card : cards) {
QVariantList parsed = CardItem::parsePT(card->getPT());
if (!parsed.isEmpty()) {
int power = parsed.first().toInt(); // toInt will default to 0 if it's not an int
total += qMax(power, 0);
}
}
// send cmd
Command_IncCounter cmd;
cmd.set_counter_id(lifeCounter->getId());
cmd.set_delta(-total);
sendGameCommand(prepareGameCommand(cmd));
}
void AnnotationDialog::keyPressEvent(QKeyEvent *event)
{
if (event->key() == Qt::Key_Return && event->modifiers() & Qt::ControlModifier) {

View file

@ -145,6 +145,9 @@ public slots:
void actDecPT();
void actFlowP();
void actFlowT();
void actReduceLifeByPower();
void actSetAnnotation();
void actReveal(QAction *action);
void actRevealHand(int revealToPlayerId);