[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

@ -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) {