Skip to content

Commit

Permalink
Fix issue vcmi#3957: amount of resurrected Vampires doesn't appear in…
Browse files Browse the repository at this point in the history
… battle log

Fixed plurar / singular text choice - creatures after life drain action
  • Loading branch information
MichalZr6 committed May 24, 2024
1 parent 5b7e355 commit 56a8ba7
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 17 deletions.
60 changes: 45 additions & 15 deletions server/battles/BattleActionProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1039,26 +1039,16 @@ void BattleActionProcessor::makeAttack(const CBattleInfoCallback & battle, const
totalKills += bsa.killedAmount;
}

{
MetaString text;
attacker->addText(text, EMetaText::GENERAL_TXT, 376);
attacker->addNameReplacement(text);
text.replaceNumber(totalDamage);
blm.lines.push_back(text);
}
addGenericDamageLog(blm, attackerState, totalDamage);

addGenericKilledLog(blm, defender, totalKills, multipleTargets);
}

// drain life effect (as well as log entry) must be applied after the attack
if(drainedLife > 0)
{
MetaString text;
attackerState->addText(text, EMetaText::GENERAL_TXT, 361);
attackerState->addNameReplacement(text, false);
text.replaceNumber(drainedLife);
defender->addNameReplacement(text, true);
blm.lines.push_back(std::move(text));
addGenericDrainedLifeLog(blm, attackerState, defender, drainedLife);
addGenericResurrectedLog(blm, attackerState, defender, static_cast<int64_t>(drainedLife / attackerState->health.getFirstHPleft()));
}

if(!fireShield.empty())
Expand Down Expand Up @@ -1435,7 +1425,7 @@ void BattleActionProcessor::handleAfterAttackCasting(const CBattleInfoCallback &
}
}

int64_t BattleActionProcessor::applyBattleEffects(const CBattleInfoCallback & battle, BattleAttack & bat, std::shared_ptr<battle::CUnitState> attackerState, FireShieldInfo & fireShield, const CStack * def, int distance, bool secondary)
int64_t BattleActionProcessor::applyBattleEffects(const CBattleInfoCallback & battle, BattleAttack & bat, std::shared_ptr<battle::CUnitState> attackerState, FireShieldInfo & fireShield, const CStack * def, int distance, bool secondary) const
{
BattleStackAttacked bsa;
if(secondary)
Expand Down Expand Up @@ -1514,7 +1504,7 @@ void BattleActionProcessor::sendGenericKilledLog(const CBattleInfoCallback & bat
}
}

void BattleActionProcessor::addGenericKilledLog(BattleLogMessage & blm, const CStack * defender, int32_t killed, bool multiple)
void BattleActionProcessor::addGenericKilledLog(BattleLogMessage & blm, const CStack * defender, int32_t killed, bool multiple) const
{
if(killed > 0)
{
Expand Down Expand Up @@ -1542,6 +1532,46 @@ void BattleActionProcessor::addGenericKilledLog(BattleLogMessage & blm, const CS
}
}

void BattleActionProcessor::addGenericDamageLog(BattleLogMessage& blm, const std::shared_ptr<battle::CUnitState> &attackerState, int64_t dmg) const
{
MetaString text;
attackerState->addText(text, EMetaText::GENERAL_TXT, 376);
attackerState->addNameReplacement(text);
text.replaceNumber(dmg);
blm.lines.push_back(std::move(text));
}

void BattleActionProcessor::addGenericDrainedLifeLog(BattleLogMessage& blm, const std::shared_ptr<battle::CUnitState>& attackerState, const CStack* defender, int64_t drainedLife) const
{
MetaString text;
attackerState->addText(text, EMetaText::GENERAL_TXT, 361);
attackerState->addNameReplacement(text);
text.replaceNumber(drainedLife);
defender->addNameReplacement(text);
blm.lines.push_back(std::move(text));
}

void BattleActionProcessor::addGenericResurrectedLog(BattleLogMessage& blm, const std::shared_ptr<battle::CUnitState>& attackerState, const CStack* defender, int64_t resurrected) const
{
if (resurrected > 0)
{
auto text = blm.lines.back().toString();
text.pop_back(); // erase '.' at the end of line with life drain info
MetaString ms = MetaString::createFromRawString(text);
if (resurrected == 1)
{
ms.appendLocalString(EMetaText::GENERAL_TXT, 363); // "\n and one rises from the dead."
}
else
{
ms.appendLocalString(EMetaText::GENERAL_TXT, 364); // "\n and %d rise from the dead."
ms.replaceNumber(resurrected);
}
blm.lines[blm.lines.size() - 1] = std::move(ms);
}

}

bool BattleActionProcessor::makeAutomaticBattleAction(const CBattleInfoCallback & battle, const BattleAction & ba)
{
return makeBattleActionImpl(battle, ba);
Expand Down
7 changes: 5 additions & 2 deletions server/battles/BattleActionProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,13 @@ class BattleActionProcessor : boost::noncopyable
std::set<SpellID> getSpellsForAttackCasting(TConstBonusListPtr spells, const CStack *defender);

// damage, drain life & fire shield; returns amount of drained life
int64_t applyBattleEffects(const CBattleInfoCallback & battle, BattleAttack & bat, std::shared_ptr<battle::CUnitState> attackerState, FireShieldInfo & fireShield, const CStack * def, int distance, bool secondary);
int64_t applyBattleEffects(const CBattleInfoCallback & battle, BattleAttack & bat, std::shared_ptr<battle::CUnitState> attackerState, FireShieldInfo & fireShield, const CStack * def, int distance, bool secondary) const;

void sendGenericKilledLog(const CBattleInfoCallback & battle, const CStack * defender, int32_t killed, bool multiple);
void addGenericKilledLog(BattleLogMessage & blm, const CStack * defender, int32_t killed, bool multiple);
void addGenericKilledLog(BattleLogMessage & blm, const CStack * defender, int32_t killed, bool multiple) const;
void addGenericDamageLog(BattleLogMessage& blm, const std::shared_ptr<battle::CUnitState> &attackerState, int64_t dmg) const;
void addGenericDrainedLifeLog(BattleLogMessage& blm, const std::shared_ptr<battle::CUnitState> &attackerState, const CStack* defender, int64_t drainedLife) const;
void addGenericResurrectedLog(BattleLogMessage& blm, const std::shared_ptr<battle::CUnitState> &attackerState, const CStack* defender, int64_t resurrected) const;

bool canStackAct(const CBattleInfoCallback & battle, const CStack * stack);

Expand Down

0 comments on commit 56a8ba7

Please sign in to comment.