DjWarmonger hace 12 años
padre
commit
aa6626bc35
Se han modificado 1 ficheros con 8 adiciones y 9 borrados
  1. 8 9
      lib/CBattleCallback.cpp

+ 8 - 9
lib/CBattleCallback.cpp

@@ -1617,22 +1617,21 @@ ESpellCastProblem::ESpellCastProblem CBattleInfoCallback::battleCanCastThisSpell
 	if(!spell->combatSpell)
 		return ESpellCastProblem::ADVMAP_SPELL_INSTEAD_OF_BATTLE_SPELL;
 
-	//TODO?
-	//if(NBonus::hasOfType(heroes[1-cside], Bonus::SPELL_IMMUNITY, spell->id)) //non - casting hero provides immunity for this spell
-	//	return ESpellCastProblem::SECOND_HEROS_SPELL_IMMUNITY;
-	if(spell->isNegative())
+	if(spell->isNegative() || spell->hasEffects())
 	{
-		bool allEnemiesImmune = true;
-		for(auto enemyStack : battleAliveStacks(!side))
+		bool allStacksImmune = true;
+		//we are interested only in enemy stacks when casting offensive spells
+		auto stacks = spell->isNegative() ? battleAliveStacks(!side) : battleAliveStacks();
+		for(auto stack : stacks) 
 		{
-			if(!enemyStack->hasBonusOfType(Bonus::SPELL_IMMUNITY, spell->id))
+			if(!battleIsImmune(castingHero, spell, mode, stack->position))
 			{
-				allEnemiesImmune = false;
+				allStacksImmune = false;
 				break;
 			}
 		}
 
-		if(allEnemiesImmune)
+		if(allStacksImmune)
 			return ESpellCastProblem::NO_APPROPRIATE_TARGET;
 	}