From 0bbf70f30a603c329976d417abdb3efec2e980a9 Mon Sep 17 00:00:00 2001 From: Andrey Filipenkov Date: Wed, 25 Jan 2023 18:13:06 +0300 Subject: [PATCH 1/2] show resurrect message in the battle log --- lib/spells/effects/Heal.cpp | 19 +++++++++++++++++-- lib/spells/effects/Heal.h | 3 ++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/spells/effects/Heal.cpp b/lib/spells/effects/Heal.cpp index 4723d908b..b1b0007e9 100644 --- a/lib/spells/effects/Heal.cpp +++ b/lib/spells/effects/Heal.cpp @@ -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 { + BattleLogMessage logMessage; BattleUnitsChanged pack; - prepareHealEffect(value, pack, *server->getRNG(), m, target); + prepareHealEffect(value, pack, logMessage, *server->getRNG(), m, target); if(!pack.changedStacks.empty()) server->apply(&pack); + if(!logMessage.lines.empty()) + server->apply(&logMessage); } bool Heal::isValidTarget(const Mechanics * m, const battle::Unit * unit) const @@ -112,7 +115,7 @@ void Heal::serializeJsonUnitEffect(JsonSerializeFormat & handler) 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) { @@ -123,8 +126,20 @@ void Heal::prepareHealEffect(int64_t value, BattleUnitsChanged & pack, RNG & rng auto unitHPgained = m->applySpellBonus(value, unit); auto state = unit->acquire(); + const auto countBeforeHeal = state->getCount(); 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) { UnitChanges info(state->unitId(), UnitChanges::EOperation::RESET_STATE); diff --git a/lib/spells/effects/Heal.h b/lib/spells/effects/Heal.h index 138935626..886c45781 100644 --- a/lib/spells/effects/Heal.h +++ b/lib/spells/effects/Heal.h @@ -15,6 +15,7 @@ VCMI_LIB_NAMESPACE_BEGIN +struct BattleLogMessage; struct BattleUnitsChanged; namespace spells @@ -42,7 +43,7 @@ private: 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; }; } From a2ac189e036f32ab45803d11aff6e8d9bc3c7391 Mon Sep 17 00:00:00 2001 From: Andrey Filipenkov Date: Wed, 25 Jan 2023 18:13:11 +0300 Subject: [PATCH 2/2] fix typo --- client/battle/BattleConstants.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/battle/BattleConstants.h b/client/battle/BattleConstants.h index 0a6b0deba..b815132a1 100644 --- a/client/battle/BattleConstants.h +++ b/client/battle/BattleConstants.h @@ -79,7 +79,7 @@ enum class ECreatureAnimType DEAD = 22, // new group, used to show dead stacks. If empty - last frame from "DEATH" will be copied here DEAD_RANGED = 23, // new group, used to show dead stacks (if DEATH_RANGED was used). If empty - last frame from "DEATH_RANGED" will be copied here - RESURRECTION = 24, // new group, used for animating resurrection, if empty - reversed "DEATH" animation will be copiend here + RESURRECTION = 24, // new group, used for animating resurrection, if empty - reversed "DEATH" animation will be copied here FROZEN = 25, // new group, used when stack animation is paused (e.g. petrified). If empty - consist of first frame from HOLDING animation CAST_UP = 30,