From 1c3ba180fcdc5e6eae58541ed92942d0112e87aa Mon Sep 17 00:00:00 2001 From: hondacrx Date: Fri, 16 Apr 2021 14:54:03 -0400 Subject: [PATCH] Core/Creatures: fixed school immunity unapply when updating entry and unified code Port From (https://github.com/TrinityCore/TrinityCore/commit/e4ca95983b1dc55e5b656d934d99b92cee30b444) --- Source/Game/Entities/Creature/Creature.cs | 29 +++++-------------- Source/Game/Entities/Creature/CreatureData.cs | 2 +- Source/Game/Entities/Pet.cs | 2 +- Source/Game/Globals/ObjectManager.cs | 2 +- 4 files changed, 11 insertions(+), 24 deletions(-) diff --git a/Source/Game/Entities/Creature/Creature.cs b/Source/Game/Entities/Creature/Creature.cs index 8becba0b0..a7938e3d6 100644 --- a/Source/Game/Entities/Creature/Creature.cs +++ b/Source/Game/Entities/Creature/Creature.cs @@ -419,8 +419,7 @@ namespace Game.Entities UpdateMovementFlags(); LoadCreaturesAddon(); - LoadMechanicTemplateImmunity(); - LoadSpellTemplateImmunity(); + LoadTemplateImmunities(); return true; } @@ -1868,16 +1867,19 @@ namespace Game.Entities ForcedDespawn(msTimeToDespawn, forceRespawnTimer); } - public void LoadMechanicTemplateImmunity() + public void LoadTemplateImmunities() { // 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) + for (uint i = 0; i < (int)Mechanics.Max; ++i) ApplySpellImmune(placeholderSpellId, SpellImmunity.Mechanic, i, false); + for (var i = (int)SpellSchools.Normal; i < (int)SpellSchools.Max; ++i) + ApplySpellImmune(placeholderSpellId, SpellImmunity.School, 1u << i, false); + // don't inherit immunities for hunter pets if (GetOwnerGUID().IsPlayer() && IsHunterPet()) return; @@ -1891,25 +1893,10 @@ namespace Game.Entities ApplySpellImmune(placeholderSpellId, SpellImmunity.Mechanic, i, true); } } - } - void LoadSpellTemplateImmunity() - { - // 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 (var i = SpellSchoolMask.Normal; i <= SpellSchoolMask.Arcane; ++i) - ApplySpellImmune(placeholderSpellId, SpellImmunity.School, i, false); - - // don't inherit immunities for hunter pets - if (GetOwnerGUID().IsPlayer() && IsHunterPet()) - return; - - byte mask = GetCreatureTemplate().SpellSchoolImmuneMask; + mask = GetCreatureTemplate().SpellSchoolImmuneMask; if (mask != 0) - for (var i = (int)SpellSchoolMask.Normal; i <= (int)SpellSchoolMask.Arcane; ++i) + for (var i = (int)SpellSchools.Normal; i <= (int)SpellSchools.Max; ++i) if ((mask & (1 << i)) != 0) ApplySpellImmune(placeholderSpellId, SpellImmunity.School, 1u << i, true); } diff --git a/Source/Game/Entities/Creature/CreatureData.cs b/Source/Game/Entities/Creature/CreatureData.cs index e85cf11e0..9c7ea580b 100644 --- a/Source/Game/Entities/Creature/CreatureData.cs +++ b/Source/Game/Entities/Creature/CreatureData.cs @@ -89,7 +89,7 @@ namespace Game.Entities public int WidgetSetUnitConditionID; public bool RegenHealth; public uint MechanicImmuneMask; - public byte SpellSchoolImmuneMask; + public uint SpellSchoolImmuneMask; public CreatureFlagsExtra FlagsExtra; public uint ScriptID; diff --git a/Source/Game/Entities/Pet.cs b/Source/Game/Entities/Pet.cs index ed1c570ac..6169617b4 100644 --- a/Source/Game/Entities/Pet.cs +++ b/Source/Game/Entities/Pet.cs @@ -357,7 +357,7 @@ namespace Game.Entities owner.ToPlayer().SetLastPetNumber(petId); // must be after SetMinion (owner guid check) - LoadMechanicTemplateImmunity(); + LoadTemplateImmunities(); m_loading = false; return true; diff --git a/Source/Game/Globals/ObjectManager.cs b/Source/Game/Globals/ObjectManager.cs index 45f34897e..e16a9ab8e 100644 --- a/Source/Game/Globals/ObjectManager.cs +++ b/Source/Game/Globals/ObjectManager.cs @@ -1870,7 +1870,7 @@ namespace Game creature.WidgetSetUnitConditionID = fields.Read(72); creature.RegenHealth = fields.Read(73); creature.MechanicImmuneMask = fields.Read(74); - creature.SpellSchoolImmuneMask = fields.Read(75); + creature.SpellSchoolImmuneMask = fields.Read(75); creature.FlagsExtra = (CreatureFlagsExtra)fields.Read(76); creature.ScriptID = GetScriptId(fields.Read(77));