diff --git a/cockatrice/src/client/settings/shortcuts_settings.h b/cockatrice/src/client/settings/shortcuts_settings.h index d9ea494dc..fc159db48 100644 --- a/cockatrice/src/client/settings/shortcuts_settings.h +++ b/cockatrice/src/client/settings/shortcuts_settings.h @@ -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)}, diff --git a/cockatrice/src/game/player/menu/card_menu.cpp b/cockatrice/src/game/player/menu/card_menu.cpp index 34ed254fb..54403e237 100644 --- a/cockatrice/src/game/player/menu/card_menu.cpp +++ b/cockatrice/src/game/player/menu/card_menu.cpp @@ -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")); diff --git a/cockatrice/src/game/player/menu/card_menu.h b/cockatrice/src/game/player/menu/card_menu.h index b7f2f8241..3cff238de 100644 --- a/cockatrice/src/game/player/menu/card_menu.h +++ b/cockatrice/src/game/player/menu/card_menu.h @@ -36,6 +36,7 @@ public: QAction *aFlip, *aPeek; QAction *aAttach, *aUnattach; QAction *aSetAnnotation; + QAction *aReduceLifeByPower; QList aAddCounter, aSetCounter, aRemoveCounter; diff --git a/cockatrice/src/game/player/player.cpp b/cockatrice/src/game/player/player.cpp index e95e2b2ef..8f5067eae 100644 --- a/cockatrice/src/game/player/player.cpp +++ b/cockatrice/src/game/player/player.cpp @@ -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 &playerList = game->getPlayerManager()->getPlayers(); diff --git a/cockatrice/src/game/player/player.h b/cockatrice/src/game/player/player.h index 9b8456aaf..1e7bc928d 100644 --- a/cockatrice/src/game/player/player.h +++ b/cockatrice/src/game/player/player.h @@ -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); diff --git a/cockatrice/src/game/player/player_actions.cpp b/cockatrice/src/game/player/player_actions.cpp index bce8af74b..24da37c82 100644 --- a/cockatrice/src/game/player/player_actions.cpp +++ b/cockatrice/src/game/player/player_actions.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -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) { diff --git a/cockatrice/src/game/player/player_actions.h b/cockatrice/src/game/player/player_actions.h index 181b1b135..ba62f1c59 100644 --- a/cockatrice/src/game/player/player_actions.h +++ b/cockatrice/src/game/player/player_actions.h @@ -145,6 +145,9 @@ public slots: void actDecPT(); void actFlowP(); void actFlowT(); + + void actReduceLifeByPower(); + void actSetAnnotation(); void actReveal(QAction *action); void actRevealHand(int revealToPlayerId);