Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool Unit::IsImmunedToSpell(SpellInfo const* spellInfo)
- {
- if (!spellInfo)
- return false;
- // Single spell immunity.
- SpellImmuneList const& idList = m_spellImmune[IMMUNITY_ID];
- for (SpellImmuneList::const_iterator itr = idList.begin(); itr != idList.end(); ++itr)
- if (itr->type == spellInfo->Id)
- return true;
- if (spellInfo->Attributes & SPELL_ATTR0_UNAFFECTED_BY_INVULNERABILITY)
- return false;
- if (spellInfo->Dispel)
- {
- SpellImmuneList const& dispelList = m_spellImmune[IMMUNITY_DISPEL];
- for (SpellImmuneList::const_iterator itr = dispelList.begin(); itr != dispelList.end(); ++itr)
- if (itr->type == spellInfo->Dispel)
- return true;
- }
- // Spells that don't have effectMechanics.
- if (!spellInfo->HasAnyEffectMechanic() && spellInfo->Mechanic)
- {
- SpellImmuneList const& mechanicList = m_spellImmune[IMMUNITY_MECHANIC];
- for (SpellImmuneList::const_iterator itr = mechanicList.begin(); itr != mechanicList.end(); ++itr)
- if (itr->type == spellInfo->Mechanic)
- return true;
- }
- bool immuneToAllEffects = true;
- for (uint8 i = 0; i < MAX_SPELL_EFFECTS; ++i)
- {
- // State/effect immunities applied by aura expect full spell immunity
- // Ignore effects with mechanic, they are supposed to be checked separately
- if (spellInfo->Effects[i].Mechanic || !IsImmunedToSpellEffect(spellInfo, i))
- {
- immuneToAllEffects = false;
- break;
- }
- }
- if (immuneToAllEffects) //Return immune only if the target is immune to all spell effects.
- return true;
- if (spellInfo->Id != 42292 && spellInfo->Id !=59752)
- {
- SpellImmuneList const& schoolList = m_spellImmune[IMMUNITY_SCHOOL];
- for (SpellImmuneList::const_iterator itr = schoolList.begin(); itr != schoolList.end(); ++itr)
- {
- SpellInfo const* immuneSpellInfo = sSpellMgr->GetSpellInfo(itr->spellId);
- if ((itr->type & spellInfo->GetSchoolMask())
- && !(immuneSpellInfo && immuneSpellInfo->IsPositive() && spellInfo->IsPositive())
- && !spellInfo->CanPierceImmuneAura(immuneSpellInfo))
- return true;
- }
- }
- return false;
- }
- bool Unit::IsImmunedToSpellEffect(SpellInfo const* spellInfo, uint32 index) const
- {
- if (!spellInfo)
- return false;
- // If m_immuneToEffect type contain this effect type, IMMUNE effect.
- uint32 effect = spellInfo->Effects[index].Effect;
- SpellImmuneList const& effectList = m_spellImmune[IMMUNITY_EFFECT];
- for (SpellImmuneList::const_iterator itr = effectList.begin(); itr != effectList.end(); ++itr)
- if (itr->type == effect)
- return true;
- if (uint32 mechanic = spellInfo->Effects[index].Mechanic)
- {
- SpellImmuneList const& mechanicList = m_spellImmune[IMMUNITY_MECHANIC];
- for (SpellImmuneList::const_iterator itr = mechanicList.begin(); itr != mechanicList.end(); ++itr)
- if (itr->type == mechanic)
- return true;
- }
- if (uint32 aura = spellInfo->Effects[index].ApplyAuraName)
- {
- SpellImmuneList const& list = m_spellImmune[IMMUNITY_STATE];
- for (SpellImmuneList::const_iterator itr = list.begin(); itr != list.end(); ++itr)
- if (itr->type == aura)
- return true;
- // Check for immune to application of harmful magical effects
- AuraEffectList const& immuneAuraApply = GetAuraEffectsByType(SPELL_AURA_MOD_IMMUNE_AURA_APPLY_SCHOOL);
- for (AuraEffectList::const_iterator iter = immuneAuraApply.begin(); iter != immuneAuraApply.end(); ++iter)
- if ((spellInfo->Dispel == DISPEL_MAGIC || spellInfo->Dispel == DISPEL_CURSE || spellInfo->Dispel == DISPEL_POISON || spellInfo->Dispel == DISPEL_DISEASE || spellInfo->Mechanic == MECHANIC_BANISH) && // Magic debuff
- ((*iter)->GetMiscValue() & spellInfo->GetSchoolMask()) && // Check school
- !spellInfo->IsPositiveEffect(index)) // Harmful
- return true;
- }
- return false;
- }
Add Comment
Please, Sign In to add comment