Browse Source

Do not allow cast if it affects only "wrong" targets

AlexVinS 9 years ago
parent
commit
5fa9d64d78

+ 28 - 1
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<const CStack *> 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;
 	}
 

+ 1 - 0
lib/spells/CDefaultSpellMechanics.h

@@ -66,6 +66,7 @@ public:
 		const std::vector<const CStack *> & attacked) const;
 
 	bool requiresCreatureTarget() const	override;
+
 protected:
 	virtual void applyBattleEffects(const SpellCastEnvironment * env, const BattleSpellCastParameters & parameters, SpellCastContext & ctx) const;
 

+ 3 - 2
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;
 						}