1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-08 23:36:33 +02:00

show resurrect message in the battle log

This commit is contained in:
Andrey Filipenkov 2023-01-25 18:13:06 +03:00
parent 54537fc02c
commit 0bbf70f30a
2 changed files with 19 additions and 3 deletions

View File

@ -49,10 +49,13 @@ void Heal::apply(ServerCallback * server, const Mechanics * m, const EffectTarge
void Heal::apply(int64_t value, ServerCallback * server, const Mechanics * m, const EffectTarget & target) const void Heal::apply(int64_t value, ServerCallback * server, const Mechanics * m, const EffectTarget & target) const
{ {
BattleLogMessage logMessage;
BattleUnitsChanged pack; BattleUnitsChanged pack;
prepareHealEffect(value, pack, *server->getRNG(), m, target); prepareHealEffect(value, pack, logMessage, *server->getRNG(), m, target);
if(!pack.changedStacks.empty()) if(!pack.changedStacks.empty())
server->apply(&pack); server->apply(&pack);
if(!logMessage.lines.empty())
server->apply(&logMessage);
} }
bool Heal::isValidTarget(const Mechanics * m, const battle::Unit * unit) const bool Heal::isValidTarget(const Mechanics * m, const battle::Unit * unit) const
@ -112,7 +115,7 @@ void Heal::serializeJsonUnitEffect(JsonSerializeFormat & handler)
handler.serializeInt("minFullUnits", minFullUnits); handler.serializeInt("minFullUnits", minFullUnits);
} }
void Heal::prepareHealEffect(int64_t value, BattleUnitsChanged & pack, RNG & rng, const Mechanics * m, const EffectTarget & target) const void Heal::prepareHealEffect(int64_t value, BattleUnitsChanged & pack, BattleLogMessage & logMessage, RNG & rng, const Mechanics * m, const EffectTarget & target) const
{ {
for(auto & oneTarget : target) for(auto & oneTarget : target)
{ {
@ -123,8 +126,20 @@ void Heal::prepareHealEffect(int64_t value, BattleUnitsChanged & pack, RNG & rng
auto unitHPgained = m->applySpellBonus(value, unit); auto unitHPgained = m->applySpellBonus(value, unit);
auto state = unit->acquire(); auto state = unit->acquire();
const auto countBeforeHeal = state->getCount();
state->heal(unitHPgained, healLevel, healPower); state->heal(unitHPgained, healLevel, healPower);
if(const auto resurrectedCount = std::max(0, state->getCount() - countBeforeHeal))
{
// %d %s rise from the dead!
// in the table first comes plural string, then the singular one
MetaString resurrectText;
state->addText(resurrectText, MetaString::GENERAL_TXT, 116, resurrectedCount == 1);
state->addNameReplacement(resurrectText);
resurrectText.addReplacement(resurrectedCount);
logMessage.lines.push_back(std::move(resurrectText));
}
if(unitHPgained > 0) if(unitHPgained > 0)
{ {
UnitChanges info(state->unitId(), UnitChanges::EOperation::RESET_STATE); UnitChanges info(state->unitId(), UnitChanges::EOperation::RESET_STATE);

View File

@ -15,6 +15,7 @@
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
struct BattleLogMessage;
struct BattleUnitsChanged; struct BattleUnitsChanged;
namespace spells namespace spells
@ -42,7 +43,7 @@ private:
int32_t minFullUnits; int32_t minFullUnits;
void prepareHealEffect(int64_t value, BattleUnitsChanged & pack, RNG & rng, const Mechanics * m, const EffectTarget & target) const; void prepareHealEffect(int64_t value, BattleUnitsChanged & pack, BattleLogMessage & logMessage, RNG & rng, const Mechanics * m, const EffectTarget & target) const;
}; };
} }