mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-15 19:47:46 -07:00
[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:
parent
67f6ab66f0
commit
762e742be0
7 changed files with 58 additions and 0 deletions
|
|
@ -537,6 +537,9 @@ private:
|
||||||
{"Player/aSetAnnotation", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Set Annotation..."),
|
{"Player/aSetAnnotation", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Set Annotation..."),
|
||||||
parseSequenceString("Alt+N"),
|
parseSequenceString("Alt+N"),
|
||||||
ShortcutGroup::Playing_Area)},
|
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"),
|
{"Player/aSelectAll", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Select All Cards in Zone"),
|
||||||
parseSequenceString("Ctrl+A"),
|
parseSequenceString("Ctrl+A"),
|
||||||
ShortcutGroup::Playing_Area)},
|
ShortcutGroup::Playing_Area)},
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,9 @@ CardMenu::CardMenu(Player *_player, const CardItem *_card, bool _shortcutsActive
|
||||||
aSelectColumn = new QAction(this);
|
aSelectColumn = new QAction(this);
|
||||||
connect(aSelectColumn, &QAction::triggered, playerActions, &PlayerActions::actSelectColumn);
|
connect(aSelectColumn, &QAction::triggered, playerActions, &PlayerActions::actSelectColumn);
|
||||||
|
|
||||||
|
aReduceLifeByPower = new QAction(this);
|
||||||
|
connect(aReduceLifeByPower, &QAction::triggered, playerActions, &PlayerActions::actReduceLifeByPower);
|
||||||
|
|
||||||
aPlay = new QAction(this);
|
aPlay = new QAction(this);
|
||||||
connect(aPlay, &QAction::triggered, playerActions, &PlayerActions::actPlay);
|
connect(aPlay, &QAction::triggered, playerActions, &PlayerActions::actPlay);
|
||||||
aHide = new QAction(this);
|
aHide = new QAction(this);
|
||||||
|
|
@ -153,6 +156,8 @@ void CardMenu::createTableMenu(bool canModifyCard)
|
||||||
addSeparator();
|
addSeparator();
|
||||||
addAction(aClone);
|
addAction(aClone);
|
||||||
addSeparator();
|
addSeparator();
|
||||||
|
addAction(aReduceLifeByPower);
|
||||||
|
addSeparator();
|
||||||
addAction(aSelectAll);
|
addAction(aSelectAll);
|
||||||
addAction(aSelectRow);
|
addAction(aSelectRow);
|
||||||
addRelatedCardView();
|
addRelatedCardView();
|
||||||
|
|
@ -179,6 +184,8 @@ void CardMenu::createTableMenu(bool canModifyCard)
|
||||||
addMenu(new PtMenu(player));
|
addMenu(new PtMenu(player));
|
||||||
addAction(aSetAnnotation);
|
addAction(aSetAnnotation);
|
||||||
addSeparator();
|
addSeparator();
|
||||||
|
addAction(aReduceLifeByPower);
|
||||||
|
addSeparator();
|
||||||
addAction(aSelectAll);
|
addAction(aSelectAll);
|
||||||
addAction(aSelectRow);
|
addAction(aSelectRow);
|
||||||
|
|
||||||
|
|
@ -463,6 +470,7 @@ void CardMenu::retranslateUi()
|
||||||
aUnattach->setText(tr("Unattac&h"));
|
aUnattach->setText(tr("Unattac&h"));
|
||||||
aDrawArrow->setText(tr("&Draw arrow..."));
|
aDrawArrow->setText(tr("&Draw arrow..."));
|
||||||
aSetAnnotation->setText(tr("&Set annotation..."));
|
aSetAnnotation->setText(tr("&Set annotation..."));
|
||||||
|
aReduceLifeByPower->setText(tr("Reduce life by power"));
|
||||||
|
|
||||||
mCardCounters->setTitle(tr("Ca&rd counters"));
|
mCardCounters->setTitle(tr("Ca&rd counters"));
|
||||||
|
|
||||||
|
|
@ -497,6 +505,7 @@ void CardMenu::setShortcutsActive()
|
||||||
aUnattach->setShortcuts(shortcuts.getShortcut("Player/aUnattach"));
|
aUnattach->setShortcuts(shortcuts.getShortcut("Player/aUnattach"));
|
||||||
aDrawArrow->setShortcuts(shortcuts.getShortcut("Player/aDrawArrow"));
|
aDrawArrow->setShortcuts(shortcuts.getShortcut("Player/aDrawArrow"));
|
||||||
aSetAnnotation->setShortcuts(shortcuts.getShortcut("Player/aSetAnnotation"));
|
aSetAnnotation->setShortcuts(shortcuts.getShortcut("Player/aSetAnnotation"));
|
||||||
|
aReduceLifeByPower->setShortcuts(shortcuts.getShortcut("Player/aReduceLifeByPower"));
|
||||||
|
|
||||||
aSelectAll->setShortcuts(shortcuts.getShortcut("Player/aSelectAll"));
|
aSelectAll->setShortcuts(shortcuts.getShortcut("Player/aSelectAll"));
|
||||||
aSelectRow->setShortcuts(shortcuts.getShortcut("Player/aSelectRow"));
|
aSelectRow->setShortcuts(shortcuts.getShortcut("Player/aSelectRow"));
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ public:
|
||||||
QAction *aFlip, *aPeek;
|
QAction *aFlip, *aPeek;
|
||||||
QAction *aAttach, *aUnattach;
|
QAction *aAttach, *aUnattach;
|
||||||
QAction *aSetAnnotation;
|
QAction *aSetAnnotation;
|
||||||
|
QAction *aReduceLifeByPower;
|
||||||
|
|
||||||
QList<QAction *> aAddCounter, aSetCounter, aRemoveCounter;
|
QList<QAction *> aAddCounter, aSetCounter, aRemoveCounter;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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)
|
ArrowItem *Player::addArrow(const ServerInfo_Arrow &arrow)
|
||||||
{
|
{
|
||||||
const QMap<int, Player *> &playerList = game->getPlayerManager()->getPlayers();
|
const QMap<int, Player *> &playerList = game->getPlayerManager()->getPlayers();
|
||||||
|
|
|
||||||
|
|
@ -199,6 +199,11 @@ public:
|
||||||
return counters;
|
return counters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the counter that represents the life total.
|
||||||
|
*/
|
||||||
|
AbstractCounter *getLifeCounter() const;
|
||||||
|
|
||||||
ArrowItem *addArrow(const ServerInfo_Arrow &arrow);
|
ArrowItem *addArrow(const ServerInfo_Arrow &arrow);
|
||||||
ArrowItem *addArrow(int arrowId, CardItem *startCard, ArrowTarget *targetItem, const QColor &color);
|
ArrowItem *addArrow(int arrowId, CardItem *startCard, ArrowTarget *targetItem, const QColor &color);
|
||||||
void delArrow(int arrowId);
|
void delArrow(int arrowId);
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
#include <libcockatrice/protocol/pb/command_draw_cards.pb.h>
|
#include <libcockatrice/protocol/pb/command_draw_cards.pb.h>
|
||||||
#include <libcockatrice/protocol/pb/command_flip_card.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_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_move_card.pb.h>
|
||||||
#include <libcockatrice/protocol/pb/command_mulligan.pb.h>
|
#include <libcockatrice/protocol/pb/command_mulligan.pb.h>
|
||||||
#include <libcockatrice/protocol/pb/command_reveal_cards.pb.h>
|
#include <libcockatrice/protocol/pb/command_reveal_cards.pb.h>
|
||||||
|
|
@ -1378,6 +1379,32 @@ void PlayerActions::actFlowT()
|
||||||
actIncPT(-1, 1);
|
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)
|
void AnnotationDialog::keyPressEvent(QKeyEvent *event)
|
||||||
{
|
{
|
||||||
if (event->key() == Qt::Key_Return && event->modifiers() & Qt::ControlModifier) {
|
if (event->key() == Qt::Key_Return && event->modifiers() & Qt::ControlModifier) {
|
||||||
|
|
|
||||||
|
|
@ -145,6 +145,9 @@ public slots:
|
||||||
void actDecPT();
|
void actDecPT();
|
||||||
void actFlowP();
|
void actFlowP();
|
||||||
void actFlowT();
|
void actFlowT();
|
||||||
|
|
||||||
|
void actReduceLifeByPower();
|
||||||
|
|
||||||
void actSetAnnotation();
|
void actSetAnnotation();
|
||||||
void actReveal(QAction *action);
|
void actReveal(QAction *action);
|
||||||
void actRevealHand(int revealToPlayerId);
|
void actRevealHand(int revealToPlayerId);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue