Skip to content

Commit

Permalink
Merge pull request #21 from jprzimba/mana-drain-update
Browse files Browse the repository at this point in the history
* Fix mana drain not displayed in Input Analyzer
  • Loading branch information
jprzimba authored Jan 15, 2025
2 parents 430643b + 585e64f commit e9c5fc8
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7466,7 +7466,7 @@ bool Game::combatChangeHealth(const std::shared_ptr<Creature> &attacker, const s
}

auto targetHealth = target->getHealth();
realDamage = damage.primary.value + damage.secondary.value;
realDamage = std::min<int32_t>(targetHealth, damage.primary.value + damage.secondary.value);
if (realDamage == 0) {
return true;
} else if (realDamage >= targetHealth) {
Expand Down Expand Up @@ -7502,13 +7502,6 @@ bool Game::combatChangeHealth(const std::shared_ptr<Creature> &attacker, const s

addCreatureHealth(spectators.data(), target);

int32_t adjustedDamage = realDamage;
if (target) {
if (realDamage > targetHealth) {
adjustedDamage = targetHealth > 0 ? targetHealth : realDamage;
}
}

sendDamageMessageAndEffects(
attacker,
target,
Expand All @@ -7518,7 +7511,7 @@ bool Game::combatChangeHealth(const std::shared_ptr<Creature> &attacker, const s
targetPlayer,
message,
spectators.data(),
adjustedDamage // realDamage
realDamage
);

if (attackerPlayer) {
Expand Down Expand Up @@ -7933,6 +7926,14 @@ bool Game::combatChangeMana(const std::shared_ptr<Creature> &attacker, const std
}

target->drainMana(attacker, manaLoss);
std::string cause = "(other)";
if (attacker) {
cause = attacker->getName();
}

if (targetPlayer) {
targetPlayer->updateInputAnalyzer(damage.primary.type, manaLoss, cause);
}

std::stringstream ss;

Expand Down Expand Up @@ -7964,7 +7965,7 @@ bool Game::combatChangeMana(const std::shared_ptr<Creature> &attacker, const std
} else if (targetPlayer == attackerPlayer) {
ss << " due to your own attack.";
} else {
ss << " mana due to an attack by " << attacker->getNameDescription() << '.';
ss << " due to an attack by " << attacker->getNameDescription() << '.';
}
message.type = MESSAGE_DAMAGE_RECEIVED;
message.text = ss.str();
Expand Down

0 comments on commit e9c5fc8

Please sign in to comment.