diff --git a/lib/spells/CDefaultSpellMechanics.cpp b/lib/spells/CDefaultSpellMechanics.cpp index 86e070f91..45937c012 100644 --- a/lib/spells/CDefaultSpellMechanics.cpp +++ b/lib/spells/CDefaultSpellMechanics.cpp @@ -136,6 +136,26 @@ void SpellCastContext::prepareBattleCast(const BattleSpellCastParameters & param sc.manaGained = 0; } +void SpellCastContext::addDamageToDisplay(const si32 value) +{ + sc.dmgToDisplay += value; +} + +void SpellCastContext::setDamageToDisplay(const si32 value) +{ + sc.dmgToDisplay = value; +} + +void SpellCastContext::sendCastPacket(const SpellCastEnvironment * env) +{ + for(auto sta : attackedCres) + { + sc.affectedCres.insert(sta->ID); + } + + env->sendAndApply(&sc); +} + ///DefaultSpellMechanics void DefaultSpellMechanics::applyBattle(BattleInfo * battle, const BattleSpellCast * packet) const { @@ -234,13 +254,9 @@ void DefaultSpellMechanics::battleCast(const SpellCastEnvironment * env, BattleS } } - for(auto cre : ctx.attackedCres) - { - ctx.sc.affectedCres.insert(cre->ID); - } - applyBattleEffects(env, parameters, ctx); - env->sendAndApply(&ctx.sc); + + ctx.sendCastPacket(env); if(parameters.mode == ECastingMode::HERO_CASTING) { @@ -421,7 +437,7 @@ void DefaultSpellMechanics::applyBattleEffects(const SpellCastEnvironment * env, else bsa.damageAmount = owner->calculateDamage(parameters.caster, attackedCre, parameters.effectLevel, parameters.effectPower) >> chainLightningModifier; - ctx.sc.dmgToDisplay += bsa.damageAmount; + ctx.addDamageToDisplay(bsa.damageAmount); bsa.stackAttacked = (attackedCre)->ID; if(parameters.mode == ECastingMode::ENCHANTER_CASTING) //multiple damage spells cast @@ -720,14 +736,10 @@ void DefaultSpellMechanics::castMagicMirror(const SpellCastEnvironment* env, Bat handleResistance(env, ctx.attackedCres, ctx.sc); - for(auto cre : ctx.attackedCres) - { - ctx.sc.affectedCres.insert(cre->ID); - } - applyBattleEffects(env, parameters, ctx); - env->sendAndApply(&ctx.sc); + ctx.sendCastPacket(env); + if(!ctx.si.stacks.empty()) //after spellcast info shows env->sendAndApply(&ctx.si); diff --git a/lib/spells/CDefaultSpellMechanics.h b/lib/spells/CDefaultSpellMechanics.h index 63b03ace9..d56cb530d 100644 --- a/lib/spells/CDefaultSpellMechanics.h +++ b/lib/spells/CDefaultSpellMechanics.h @@ -20,10 +20,15 @@ class SpellCastContext public: const DefaultSpellMechanics * mechanics; std::vector attackedCres;//must be vector, as in Chain Lightning order matters - BattleSpellCast sc; + BattleSpellCast sc;//todo: make private StacksInjured si; SpellCastContext(const DefaultSpellMechanics * mechanics_, const BattleSpellCastParameters & parameters); + + void addDamageToDisplay(const si32 value); + void setDamageToDisplay(const si32 value); + + void sendCastPacket(const SpellCastEnvironment * env); private: void prepareBattleCast(const BattleSpellCastParameters & parameters); }; diff --git a/lib/spells/CreatureSpellMechanics.cpp b/lib/spells/CreatureSpellMechanics.cpp index 0879a0c2a..142fabb1f 100644 --- a/lib/spells/CreatureSpellMechanics.cpp +++ b/lib/spells/CreatureSpellMechanics.cpp @@ -20,7 +20,7 @@ void AcidBreathDamageMechanics::applyBattleEffects(const SpellCastEnvironment * { //todo: this should be effectValue //calculating dmg to display - ctx.sc.dmgToDisplay = parameters.effectPower; + ctx.setDamageToDisplay(parameters.effectPower); for(auto & attackedCre : ctx.attackedCres) //no immunities { @@ -39,9 +39,12 @@ void AcidBreathDamageMechanics::applyBattleEffects(const SpellCastEnvironment * void DeathStareMechanics::applyBattleEffects(const SpellCastEnvironment * env, const BattleSpellCastParameters & parameters, SpellCastContext & ctx) const { //calculating dmg to display - ctx.sc.dmgToDisplay = parameters.effectPower; + si32 dmgToDisplay = parameters.effectPower; + if(!ctx.attackedCres.empty()) - vstd::amin(ctx.sc.dmgToDisplay, (*ctx.attackedCres.begin())->count); //stack is already reduced after attack + vstd::amin(dmgToDisplay, (*ctx.attackedCres.begin())->count); //stack is already reduced after attack + + ctx.setDamageToDisplay(dmgToDisplay); for(auto & attackedCre : ctx.attackedCres) {