From 5fa9d64d782bd53b6bb6e80171b92a62af7e1ff2 Mon Sep 17 00:00:00 2001 From: AlexVinS Date: Sun, 2 Oct 2016 16:38:30 +0300 Subject: [PATCH] Do not allow cast if it affects only "wrong" targets --- lib/spells/CDefaultSpellMechanics.cpp | 29 ++++++++++++++++++++++++++- lib/spells/CDefaultSpellMechanics.h | 1 + lib/spells/CSpellHandler.cpp | 5 +++-- 3 files changed, 32 insertions(+), 3 deletions(-) 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; }