diff --git a/lib/spells/CDefaultSpellMechanics.cpp b/lib/spells/CDefaultSpellMechanics.cpp index fba1c8ef3..9d1e1a420 100644 --- a/lib/spells/CDefaultSpellMechanics.cpp +++ b/lib/spells/CDefaultSpellMechanics.cpp @@ -710,7 +710,34 @@ ESpellCastProblem::ESpellCastProblem DefaultSpellMechanics::canBeCast(const CBat if(ctx.mode == ECastingMode::CREATURE_ACTIVE_CASTING || ctx.mode == ECastingMode::HERO_CASTING) { std::vector affected = getAffectedStacks(cb, ctx); - if(affected.empty()) + + //allow to cast spell if affects is at least one smart target + bool targetExists = false; + + for(const CStack * stack : affected) + { + bool casterStack = stack->owner == ctx.caster->getOwner(); + + switch (owner->positiveness) + { + case CSpell::POSITIVE: + if(casterStack) + targetExists = true; + break; + case CSpell::NEUTRAL: + targetExists = true; + break; + case CSpell::NEGATIVE: + if(!casterStack) + targetExists = true; + break; + } + + if(targetExists) + break; + } + + if(!targetExists) return ESpellCastProblem::NO_APPROPRIATE_TARGET; } diff --git a/lib/spells/CDefaultSpellMechanics.h b/lib/spells/CDefaultSpellMechanics.h index 330ad85b3..f3b303374 100644 --- a/lib/spells/CDefaultSpellMechanics.h +++ b/lib/spells/CDefaultSpellMechanics.h @@ -66,6 +66,7 @@ public: const std::vector & attacked) const; bool requiresCreatureTarget() const override; + protected: virtual void applyBattleEffects(const SpellCastEnvironment * env, const BattleSpellCastParameters & parameters, SpellCastContext & ctx) const; diff --git a/lib/spells/CSpellHandler.cpp b/lib/spells/CSpellHandler.cpp index e60707fc7..8df5cf07b 100644 --- a/lib/spells/CSpellHandler.cpp +++ b/lib/spells/CSpellHandler.cpp @@ -157,6 +157,7 @@ ESpellCastProblem::ESpellCastProblem CSpell::canBeCast(const CBattleInfoCallback return generalProblem; //check for creature target existence + //allow to cast spell if there is at least one smart target if(mechanics->requiresCreatureTarget()) { switch(mode) @@ -180,14 +181,14 @@ ESpellCastProblem::ESpellCastProblem CSpell::canBeCast(const CBattleInfoCallback switch (positiveness) { case CSpell::POSITIVE: - if(casterStack || !tinfo.smart) + if(casterStack) targetExists = true; break; case CSpell::NEUTRAL: targetExists = true; break; case CSpell::NEGATIVE: - if(!casterStack || !tinfo.smart) + if(!casterStack) targetExists = true; break; }