mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-24 08:32:34 +02:00
More usage of OOP in HealingSpellMechanics::applyBattleEffects
This commit is contained in:
parent
0fecb40039
commit
16f0714474
@ -19,6 +19,7 @@ void HealingSpellMechanics::applyBattleEffects(const SpellCastEnvironment* env,
|
||||
{
|
||||
int effectLevel = calculateEffectLevel(parameters);
|
||||
int hpGained = 0;
|
||||
EHealLevel healLevel = getHealLevel(effectLevel);
|
||||
|
||||
if(owner->id == SpellID::SACRIFICE)
|
||||
{
|
||||
@ -46,7 +47,7 @@ void HealingSpellMechanics::applyBattleEffects(const SpellCastEnvironment* env,
|
||||
shr.lifeDrain = false;
|
||||
shr.tentHealing = false;
|
||||
|
||||
const bool resurrect = owner->isRisingSpell();
|
||||
const bool resurrect = (healLevel != EHealLevel::HEAL);
|
||||
for(auto & attackedCre : ctx.attackedCres)
|
||||
{
|
||||
StacksHealedOrResurrected::HealInfo hi;
|
||||
@ -61,7 +62,7 @@ void HealingSpellMechanics::applyBattleEffects(const SpellCastEnvironment* env,
|
||||
hi.healedHP = attackedCre->calculateHealedHealthPoints(stackHPgained, resurrect);
|
||||
}
|
||||
|
||||
hi.lowLevelResurrection = (effectLevel <= 1) && (owner->id == SpellID::RESURRECTION);
|
||||
hi.lowLevelResurrection = (healLevel == EHealLevel::RESURRECT);
|
||||
shr.healedStacks.push_back(hi);
|
||||
}
|
||||
if(!shr.healedStacks.empty())
|
||||
@ -200,6 +201,11 @@ void CureMechanics::applyBattle(BattleInfo * battle, const BattleSpellCast * pac
|
||||
});
|
||||
}
|
||||
|
||||
HealingSpellMechanics::EHealLevel CureMechanics::getHealLevel(int effectLevel) const
|
||||
{
|
||||
return EHealLevel::HEAL;
|
||||
}
|
||||
|
||||
///DispellMechanics
|
||||
void DispellMechanics::applyBattle(BattleInfo * battle, const BattleSpellCast * packet) const
|
||||
{
|
||||
@ -508,7 +514,16 @@ void RemoveObstacleMechanics::applyBattleEffects(const SpellCastEnvironment * en
|
||||
env->complain("There's no obstacle to remove!");
|
||||
}
|
||||
|
||||
///SpecialRisingSpellMechanics
|
||||
HealingSpellMechanics::EHealLevel RisingSpellMechanics::getHealLevel(int effectLevel) const
|
||||
{
|
||||
//this may be even distinct class
|
||||
if((effectLevel <= 1) && (owner->id == SpellID::RESURRECTION))
|
||||
return EHealLevel::RESURRECT;
|
||||
|
||||
return EHealLevel::TRUE_RESURRECT;
|
||||
}
|
||||
|
||||
///SacrificeMechanics
|
||||
ESpellCastProblem::ESpellCastProblem SacrificeMechanics::canBeCasted(const CBattleInfoCallback * cb, PlayerColor player) const
|
||||
{
|
||||
// for sacrifice we have to check for 2 targets (one dead to resurrect and one living to destroy)
|
||||
|
@ -15,9 +15,18 @@
|
||||
class DLL_LINKAGE HealingSpellMechanics : public DefaultSpellMechanics
|
||||
{
|
||||
public:
|
||||
enum class EHealLevel
|
||||
{
|
||||
HEAL,
|
||||
RESURRECT,
|
||||
TRUE_RESURRECT
|
||||
};
|
||||
|
||||
HealingSpellMechanics(CSpell * s): DefaultSpellMechanics(s){};
|
||||
protected:
|
||||
void applyBattleEffects(const SpellCastEnvironment * env, BattleSpellCastParameters & parameters, SpellCastContext & ctx) const override;
|
||||
|
||||
virtual EHealLevel getHealLevel(int effectLevel) const = 0;
|
||||
};
|
||||
|
||||
class DLL_LINKAGE AntimagicMechanics : public DefaultSpellMechanics
|
||||
@ -50,6 +59,8 @@ public:
|
||||
CureMechanics(CSpell * s): HealingSpellMechanics(s){};
|
||||
|
||||
void applyBattle(BattleInfo * battle, const BattleSpellCast * packet) const override final;
|
||||
|
||||
EHealLevel getHealLevel(int effectLevel) const override final;
|
||||
};
|
||||
|
||||
class DLL_LINKAGE DispellMechanics : public DefaultSpellMechanics
|
||||
@ -108,7 +119,7 @@ class DLL_LINKAGE RisingSpellMechanics : public HealingSpellMechanics
|
||||
{
|
||||
public:
|
||||
RisingSpellMechanics(CSpell * s): HealingSpellMechanics(s){};
|
||||
|
||||
EHealLevel getHealLevel(int effectLevel) const override;
|
||||
};
|
||||
|
||||
class DLL_LINKAGE SacrificeMechanics : public RisingSpellMechanics
|
||||
|
Loading…
Reference in New Issue
Block a user