From 3fa62beb6d3fde2b63f1fa5d0ebcb38bb2672043 Mon Sep 17 00:00:00 2001 From: AlexVinS Date: Sun, 11 Sep 2016 13:48:14 +0300 Subject: [PATCH] Do not allow to cast Cure if there is nothing to cure. --- lib/spells/BattleSpellMechanics.cpp | 30 ++++++++++++++++++++--------- lib/spells/BattleSpellMechanics.h | 3 +++ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/lib/spells/BattleSpellMechanics.cpp b/lib/spells/BattleSpellMechanics.cpp index dbf0b7419..778735920 100644 --- a/lib/spells/BattleSpellMechanics.cpp +++ b/lib/spells/BattleSpellMechanics.cpp @@ -172,15 +172,8 @@ ESpellCastProblem::ESpellCastProblem CloneMechanics::isImmuneByStack(const ISpel void CureMechanics::applyBattle(BattleInfo * battle, const BattleSpellCast * packet) const { DefaultSpellMechanics::applyBattle(battle, packet); - doDispell(battle, packet, [](const Bonus * b) -> bool - { - if(b->source == Bonus::SPELL_EFFECT) - { - CSpell * sp = SpellID(b->sid).toSpell(); - return sp->isNegative(); - } - return false; //not a spell effect - }); + + doDispell(battle, packet, dispellSelector); } HealingSpellMechanics::EHealLevel CureMechanics::getHealLevel(int effectLevel) const @@ -188,6 +181,25 @@ HealingSpellMechanics::EHealLevel CureMechanics::getHealLevel(int effectLevel) c return EHealLevel::HEAL; } +bool CureMechanics::dispellSelector(const Bonus * b) +{ + if(b->source == Bonus::SPELL_EFFECT) + { + CSpell * sp = SpellID(b->sid).toSpell(); + return sp->isNegative(); + } + return false; //not a spell effect +} + +ESpellCastProblem::ESpellCastProblem CureMechanics::isImmuneByStack(const ISpellCaster * caster, const CStack * obj) const +{ + //Selector method name is ok as cashing string. --AVS + if(!obj->canBeHealed() && !obj->hasBonus(dispellSelector, "CureMechanics::dispellSelector")) + return ESpellCastProblem::STACK_IMMUNE_TO_SPELL; + + return DefaultSpellMechanics::isImmuneByStack(caster, obj); +} + ///DispellMechanics void DispellMechanics::applyBattle(BattleInfo * battle, const BattleSpellCast * packet) const { diff --git a/lib/spells/BattleSpellMechanics.h b/lib/spells/BattleSpellMechanics.h index dadfa36b4..8c2064f42 100644 --- a/lib/spells/BattleSpellMechanics.h +++ b/lib/spells/BattleSpellMechanics.h @@ -63,8 +63,11 @@ public: CureMechanics(CSpell * s): HealingSpellMechanics(s){}; void applyBattle(BattleInfo * battle, const BattleSpellCast * packet) const override final; + ESpellCastProblem::ESpellCastProblem isImmuneByStack(const ISpellCaster * caster, const CStack * obj) const override; EHealLevel getHealLevel(int effectLevel) const override final; +private: + static bool dispellSelector(const Bonus * b); }; class DLL_LINKAGE DispellMechanics : public DefaultSpellMechanics