Guest User

Untitled

a guest
May 17th, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.21 KB | None | 0 0
  1. bool Unit::IsImmunedToSpell(SpellInfo const* spellInfo)
  2. {
  3.     if (!spellInfo)
  4.         return false;
  5.  
  6.     // Single spell immunity.
  7.     SpellImmuneList const& idList = m_spellImmune[IMMUNITY_ID];
  8.     for (SpellImmuneList::const_iterator itr = idList.begin(); itr != idList.end(); ++itr)
  9.         if (itr->type == spellInfo->Id)
  10.             return true;
  11.  
  12.     if (spellInfo->Attributes & SPELL_ATTR0_UNAFFECTED_BY_INVULNERABILITY)
  13.         return false;
  14.  
  15.     if (spellInfo->Dispel)
  16.     {
  17.         SpellImmuneList const& dispelList = m_spellImmune[IMMUNITY_DISPEL];
  18.         for (SpellImmuneList::const_iterator itr = dispelList.begin(); itr != dispelList.end(); ++itr)
  19.             if (itr->type == spellInfo->Dispel)
  20.                 return true;
  21.     }
  22.  
  23.     // Spells that don't have effectMechanics.
  24.     if (!spellInfo->HasAnyEffectMechanic() && spellInfo->Mechanic)
  25.     {
  26.         SpellImmuneList const& mechanicList = m_spellImmune[IMMUNITY_MECHANIC];
  27.         for (SpellImmuneList::const_iterator itr = mechanicList.begin(); itr != mechanicList.end(); ++itr)
  28.             if (itr->type == spellInfo->Mechanic)
  29.                 return true;
  30.     }
  31.  
  32.     bool immuneToAllEffects = true;
  33.     for (uint8 i = 0; i < MAX_SPELL_EFFECTS; ++i)
  34.     {
  35.         // State/effect immunities applied by aura expect full spell immunity
  36.         // Ignore effects with mechanic, they are supposed to be checked separately
  37.         if (spellInfo->Effects[i].Mechanic || !IsImmunedToSpellEffect(spellInfo, i))
  38.         {
  39.             immuneToAllEffects = false;
  40.             break;
  41.         }
  42.     }
  43.     if (immuneToAllEffects) //Return immune only if the target is immune to all spell effects.
  44.         return true;
  45.  
  46.     if (spellInfo->Id != 42292 && spellInfo->Id !=59752)
  47.     {
  48.         SpellImmuneList const& schoolList = m_spellImmune[IMMUNITY_SCHOOL];
  49.         for (SpellImmuneList::const_iterator itr = schoolList.begin(); itr != schoolList.end(); ++itr)
  50.         {
  51.             SpellInfo const* immuneSpellInfo = sSpellMgr->GetSpellInfo(itr->spellId);
  52.             if ((itr->type & spellInfo->GetSchoolMask())
  53.                 && !(immuneSpellInfo && immuneSpellInfo->IsPositive() && spellInfo->IsPositive())
  54.                 && !spellInfo->CanPierceImmuneAura(immuneSpellInfo))
  55.                 return true;
  56.         }
  57.     }
  58.  
  59.     return false;
  60. }
  61.  
  62. bool Unit::IsImmunedToSpellEffect(SpellInfo const* spellInfo, uint32 index) const
  63. {
  64.     if (!spellInfo)
  65.         return false;
  66.     // If m_immuneToEffect type contain this effect type, IMMUNE effect.
  67.     uint32 effect = spellInfo->Effects[index].Effect;
  68.     SpellImmuneList const& effectList = m_spellImmune[IMMUNITY_EFFECT];
  69.     for (SpellImmuneList::const_iterator itr = effectList.begin(); itr != effectList.end(); ++itr)
  70.         if (itr->type == effect)
  71.             return true;
  72.  
  73.     if (uint32 mechanic = spellInfo->Effects[index].Mechanic)
  74.     {
  75.         SpellImmuneList const& mechanicList = m_spellImmune[IMMUNITY_MECHANIC];
  76.         for (SpellImmuneList::const_iterator itr = mechanicList.begin(); itr != mechanicList.end(); ++itr)
  77.             if (itr->type == mechanic)
  78.                 return true;
  79.     }
  80.  
  81.     if (uint32 aura = spellInfo->Effects[index].ApplyAuraName)
  82.     {
  83.         SpellImmuneList const& list = m_spellImmune[IMMUNITY_STATE];
  84.         for (SpellImmuneList::const_iterator itr = list.begin(); itr != list.end(); ++itr)
  85.             if (itr->type == aura)
  86.                 return true;
  87.         // Check for immune to application of harmful magical effects
  88.         AuraEffectList const& immuneAuraApply = GetAuraEffectsByType(SPELL_AURA_MOD_IMMUNE_AURA_APPLY_SCHOOL);
  89.         for (AuraEffectList::const_iterator iter = immuneAuraApply.begin(); iter != immuneAuraApply.end(); ++iter)
  90.             if ((spellInfo->Dispel == DISPEL_MAGIC || spellInfo->Dispel == DISPEL_CURSE || spellInfo->Dispel == DISPEL_POISON || spellInfo->Dispel == DISPEL_DISEASE || spellInfo->Mechanic == MECHANIC_BANISH) &&                                      // Magic debuff
  91.                 ((*iter)->GetMiscValue() & spellInfo->GetSchoolMask()) &&  // Check school
  92.                 !spellInfo->IsPositiveEffect(index))                                  // Harmful
  93.                 return true;
  94.     }
  95.  
  96.     return false;
  97. }
Add Comment
Please, Sign In to add comment