1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-24 03:47:18 +02:00

Fixed issues from review

This commit is contained in:
MichalZr6 2024-06-11 16:47:23 +02:00
parent 65d22f17ae
commit 15f86c0284
4 changed files with 11 additions and 17 deletions

View File

@ -44,17 +44,15 @@ namespace BattlePhases
// Healed HP (also drained life) and resurrected units info
struct HealInfo
{
HealInfo()
: healedHealthPoints(0), resurrectedCount(0)
{ }
HealInfo() = default;
HealInfo(int64_t healedHP, int32_t resurrected)
: healedHealthPoints(healedHP), resurrectedCount(resurrected)
{ }
int64_t healedHealthPoints;
int32_t resurrectedCount;
int64_t healedHealthPoints = 0;
int32_t resurrectedCount = 0;
HealInfo& operator +=(const HealInfo& other)
HealInfo & operator+=(const HealInfo & other)
{
healedHealthPoints += other.healedHealthPoints;
resurrectedCount += other.resurrectedCount;

View File

@ -122,7 +122,6 @@ int32_t Summon::summonedCreatureAmount(const Mechanics * m) const
void Summon::apply(ServerCallback * server, const Mechanics * m, const EffectTarget & target) const
{
using battle::HealInfo;
BattleUnitsChanged pack;
pack.battleID = m->battle()->getBattle()->getBattleID();

View File

@ -960,14 +960,14 @@ void BattleActionProcessor::makeAttack(const CBattleInfoCallback & battle, const
// only primary target
if(defender->alive())
applyBattleEffects(battle, bat, attackerState, fireShield, defender, &healInfo, distance, false);
applyBattleEffects(battle, bat, attackerState, fireShield, defender, healInfo, distance, false);
//multiple-hex normal attack
std::set<const CStack*> attackedCreatures = battle.getAttackedCreatures(attacker, targetHex, bat.shot()); //creatures other than primary target
for(const CStack * stack : attackedCreatures)
{
if(stack != defender && stack->alive()) //do not hit same stack twice
applyBattleEffects(battle, bat, attackerState, fireShield, stack, &healInfo, distance, true);
applyBattleEffects(battle, bat, attackerState, fireShield, stack, healInfo, distance, true);
}
std::shared_ptr<const Bonus> bonus = attacker->getFirstBonus(Selector::type()(BonusType::SPELL_LIKE_ATTACK));
@ -995,7 +995,7 @@ void BattleActionProcessor::makeAttack(const CBattleInfoCallback & battle, const
{
if(stack != defender && stack->alive()) //do not hit same stack twice
{
applyBattleEffects(battle, bat, attackerState, fireShield, stack, &healInfo, distance, true);
applyBattleEffects(battle, bat, attackerState, fireShield, stack, healInfo, distance, true);
}
}
@ -1425,7 +1425,7 @@ void BattleActionProcessor::handleAfterAttackCasting(const CBattleInfoCallback &
}
}
void BattleActionProcessor::applyBattleEffects(const CBattleInfoCallback & battle, BattleAttack & bat, std::shared_ptr<battle::CUnitState> attackerState, FireShieldInfo & fireShield, const CStack * def, battle::HealInfo * healInfo, int distance, bool secondary) const
void BattleActionProcessor::applyBattleEffects(const CBattleInfoCallback & battle, BattleAttack & bat, std::shared_ptr<battle::CUnitState> attackerState, FireShieldInfo & fireShield, const CStack * def, battle::HealInfo & healInfo, int distance, bool secondary) const
{
BattleStackAttacked bsa;
if(secondary)
@ -1446,13 +1446,11 @@ void BattleActionProcessor::applyBattleEffects(const CBattleInfoCallback & battl
CStack::prepareAttacked(bsa, gameHandler->getRandomGenerator(), bai.defender->acquireState()); //calculate casualties
}
battle::HealInfo tmpHealInfo;
//life drain handling
if(attackerState->hasBonusOfType(BonusType::LIFE_DRAIN) && def->isLiving())
{
int64_t toHeal = bsa.damageAmount * attackerState->valOfBonuses(BonusType::LIFE_DRAIN) / 100;
tmpHealInfo += attackerState->heal(toHeal, EHealLevel::RESURRECT, EHealPower::PERMANENT);
healInfo += attackerState->heal(toHeal, EHealLevel::RESURRECT, EHealPower::PERMANENT);
}
//soul steal handling
@ -1466,12 +1464,11 @@ void BattleActionProcessor::applyBattleEffects(const CBattleInfoCallback & battl
{
int64_t toHeal = bsa.killedAmount * attackerState->valOfBonuses(BonusType::SOUL_STEAL, subtype) * attackerState->getMaxHealth();
bool permanent = subtype == BonusCustomSubtype::soulStealPermanent;
tmpHealInfo += attackerState->heal(toHeal, EHealLevel::OVERHEAL, (permanent ? EHealPower::PERMANENT : EHealPower::ONE_BATTLE));
healInfo += attackerState->heal(toHeal, EHealLevel::OVERHEAL, (permanent ? EHealPower::PERMANENT : EHealPower::ONE_BATTLE));
break;
}
}
}
*healInfo += tmpHealInfo;
bat.bsa.push_back(bsa); //add this stack to the list of victims after drain life has been calculated
//fire shield handling

View File

@ -54,7 +54,7 @@ class BattleActionProcessor : boost::noncopyable
std::set<SpellID> getSpellsForAttackCasting(TConstBonusListPtr spells, const CStack *defender);
// damage, drain life & fire shield; returns amount of drained life
void applyBattleEffects(const CBattleInfoCallback & battle, BattleAttack & bat, std::shared_ptr<battle::CUnitState> attackerState, FireShieldInfo & fireShield, const CStack * def, battle::HealInfo * healInfo, int distance, bool secondary) const;
void applyBattleEffects(const CBattleInfoCallback & battle, BattleAttack & bat, std::shared_ptr<battle::CUnitState> attackerState, FireShieldInfo & fireShield, const CStack * def, battle::HealInfo & healInfo, 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) const;