DjWarmonger 12 years ago
parent
commit
e2de926aec
2 changed files with 10 additions and 16 deletions
  1. 0 15
      lib/BattleState.cpp
  2. 10 1
      lib/CBattleCallback.cpp

+ 0 - 15
lib/BattleState.cpp

@@ -744,21 +744,6 @@ std::vector<ui32> BattleInfo::calculateResistedStacks(const CSpell * sp, const C
 
 	}
 
-	if(sp->id == SpellID::HYPNOTIZE) //hypnotize
-	{
-		for(auto & affectedCreature : affectedCreatures)
-		{
-			if( (affectedCreature)->hasBonusOfType(Bonus::SPELL_IMMUNITY, sp->id) //100% sure spell immunity
-				|| ( (affectedCreature)->count - 1 ) * (affectedCreature)->MaxHealth() + (affectedCreature)->firstHPleft
-		>
-		calculateSpellBonus (usedSpellPower * 25 + sp->powers[spellLevel], sp, caster, affectedCreature) //apply 'damage' bonus for hypnotize, including hero specialty
-			)
-			{
-				ret.push_back((affectedCreature)->ID);
-			}
-		}
-	}
-
 	return ret;
 }
 

+ 10 - 1
lib/CBattleCallback.cpp

@@ -1569,7 +1569,16 @@ ESpellCastProblem::ESpellCastProblem CBattleInfoCallback::battleIsImmune(const C
 					return ESpellCastProblem::STACK_IMMUNE_TO_SPELL;
 			}
 		}
-
+		else if(spell->id == SpellID::HYPNOTIZE && caster) //do not resist hypnotize casted after attack, for example
+		{
+			//TODO: what with other creatures casting hypnotize, Faerie Dragons style?
+			ui64 subjectHealth = (subject->count - 1) * subject->MaxHealth() + subject->firstHPleft;
+			//apply 'damage' bonus for hypnotize, including hero specialty
+			ui64 maxHealth = calculateSpellBonus (caster->getPrimSkillLevel(PrimarySkill::SPELL_POWER)
+				* spell->power + spell->powers[caster->getSpellSchoolLevel(spell)], spell, caster, subject);
+			if (subjectHealth > maxHealth)
+				return ESpellCastProblem::STACK_IMMUNE_TO_SPELL;
+		}
 	}
 	else //no target stack on this tile
 	{