From 43a94b48972c2ddd6435b541b38290332d327993 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Sun, 1 Sep 2019 11:05:57 -0400 Subject: [PATCH] Core/Creature: Load template immunities into m_spellImmune container. Port From (https://github.com/TrinityCore/TrinityCore/commit/f4205b760eecce436af204d973f7876db8948407) --- Source/Game/Entities/Creature/Creature.cs | 34 +++++++++++++++-------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/Source/Game/Entities/Creature/Creature.cs b/Source/Game/Entities/Creature/Creature.cs index 4ce54e646..067e05325 100644 --- a/Source/Game/Entities/Creature/Creature.cs +++ b/Source/Game/Entities/Creature/Creature.cs @@ -355,6 +355,7 @@ namespace Game.Entities UpdateMovementFlags(); LoadCreaturesAddon(); + LoadMechanicTemplateImmunity(); return true; } @@ -1693,9 +1694,29 @@ namespace Game.Entities ForcedDespawn(msTimeToDespawn, forceRespawnTimer); } - bool HasMechanicTemplateImmunity(uint mask) + void LoadMechanicTemplateImmunity() { - return (!GetOwnerGUID().IsPlayer() || !IsHunterPet()) && GetCreatureTemplate().MechanicImmuneMask.HasAnyFlag(mask); + // uint32 max used for "spell id", the immunity system will not perform SpellInfo checks against invalid spells + // used so we know which immunities were loaded from template + uint placeholderSpellId = uint.MaxValue; + + // unapply template immunities (in case we're updating entry) + for (uint i = 1; i < (int)Mechanics.Max; ++i) + ApplySpellImmune(placeholderSpellId, SpellImmunity.Mechanic, i, false); + + // don't inherit immunities for hunter pets + if (GetOwnerGUID().IsPlayer() && IsHunterPet()) + return; + + uint mask = GetCreatureTemplate().MechanicImmuneMask; + if (mask != 0) + { + for (uint i = 0 + 1; i < (int)Mechanics.Max; ++i) + { + if ((mask & (1u << ((int)i - 1))) != 0) + ApplySpellImmune(placeholderSpellId, SpellImmunity.Mechanic, i, true); + } + } } public override bool IsImmunedToSpell(SpellInfo spellInfo, Unit caster) @@ -1703,12 +1724,6 @@ namespace Game.Entities if (spellInfo == null) return false; - // Creature is immune to main mechanic of the spell - if (spellInfo.Mechanic > Mechanics.None && HasMechanicTemplateImmunity(1u << ((int)spellInfo.Mechanic - 1))) - return true; - - // This check must be done instead of 'if (GetCreatureTemplate().MechanicImmuneMask & (1 << (spellInfo.Mechanic - 1)))' for not break - // the check of mechanic immunity on DB (tested) because GetCreatureTemplate().MechanicImmuneMask and m_spellImmune[IMMUNITY_MECHANIC] don't have same data. bool immunedToAllEffects = true; foreach (SpellEffectInfo effect in spellInfo.GetEffectsForDifficulty(GetMap().GetDifficultyID())) { @@ -1734,9 +1749,6 @@ namespace Game.Entities if (effect == null) return true; - if (effect.Mechanic > Mechanics.None && HasMechanicTemplateImmunity(1u << ((int)effect.Mechanic - 1))) - return true; - if (GetCreatureTemplate().CreatureType == CreatureType.Mechanical && effect.Effect == SpellEffectName.Heal) return true;