1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Merge pull request #1496 from kambala-decapitator/resurrect-message

show resurrect message in the battle log
This commit is contained in:
Andrey Filipenkov 2023-01-29 22:18:32 +03:00 committed by GitHub
commit 07dc2e1c48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 4 deletions

View File

@ -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,

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

View File

@ -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;
};
}