Core/Creatures: fixed school immunity unapply when updating entry and unified code

Port From (https://github.com/TrinityCore/TrinityCore/commit/e4ca95983b1dc55e5b656d934d99b92cee30b444)
This commit is contained in:
hondacrx
2021-04-16 14:54:03 -04:00
parent 9714010ab3
commit 1c3ba180fc
4 changed files with 11 additions and 24 deletions
+8 -21
View File
@@ -419,8 +419,7 @@ namespace Game.Entities
UpdateMovementFlags(); UpdateMovementFlags();
LoadCreaturesAddon(); LoadCreaturesAddon();
LoadMechanicTemplateImmunity(); LoadTemplateImmunities();
LoadSpellTemplateImmunity();
return true; return true;
} }
@@ -1868,16 +1867,19 @@ namespace Game.Entities
ForcedDespawn(msTimeToDespawn, forceRespawnTimer); 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 // 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 // used so we know which immunities were loaded from template
uint placeholderSpellId = uint.MaxValue; uint placeholderSpellId = uint.MaxValue;
// unapply template immunities (in case we're updating entry) // 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); 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 // don't inherit immunities for hunter pets
if (GetOwnerGUID().IsPlayer() && IsHunterPet()) if (GetOwnerGUID().IsPlayer() && IsHunterPet())
return; return;
@@ -1891,25 +1893,10 @@ namespace Game.Entities
ApplySpellImmune(placeholderSpellId, SpellImmunity.Mechanic, i, true); ApplySpellImmune(placeholderSpellId, SpellImmunity.Mechanic, i, true);
} }
} }
}
void LoadSpellTemplateImmunity() mask = GetCreatureTemplate().SpellSchoolImmuneMask;
{
// 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;
if (mask != 0) 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) if ((mask & (1 << i)) != 0)
ApplySpellImmune(placeholderSpellId, SpellImmunity.School, 1u << i, true); ApplySpellImmune(placeholderSpellId, SpellImmunity.School, 1u << i, true);
} }
@@ -89,7 +89,7 @@ namespace Game.Entities
public int WidgetSetUnitConditionID; public int WidgetSetUnitConditionID;
public bool RegenHealth; public bool RegenHealth;
public uint MechanicImmuneMask; public uint MechanicImmuneMask;
public byte SpellSchoolImmuneMask; public uint SpellSchoolImmuneMask;
public CreatureFlagsExtra FlagsExtra; public CreatureFlagsExtra FlagsExtra;
public uint ScriptID; public uint ScriptID;
+1 -1
View File
@@ -357,7 +357,7 @@ namespace Game.Entities
owner.ToPlayer().SetLastPetNumber(petId); owner.ToPlayer().SetLastPetNumber(petId);
// must be after SetMinion (owner guid check) // must be after SetMinion (owner guid check)
LoadMechanicTemplateImmunity(); LoadTemplateImmunities();
m_loading = false; m_loading = false;
return true; return true;
+1 -1
View File
@@ -1870,7 +1870,7 @@ namespace Game
creature.WidgetSetUnitConditionID = fields.Read<int>(72); creature.WidgetSetUnitConditionID = fields.Read<int>(72);
creature.RegenHealth = fields.Read<bool>(73); creature.RegenHealth = fields.Read<bool>(73);
creature.MechanicImmuneMask = fields.Read<uint>(74); creature.MechanicImmuneMask = fields.Read<uint>(74);
creature.SpellSchoolImmuneMask = fields.Read<byte>(75); creature.SpellSchoolImmuneMask = fields.Read<uint>(75);
creature.FlagsExtra = (CreatureFlagsExtra)fields.Read<uint>(76); creature.FlagsExtra = (CreatureFlagsExtra)fields.Read<uint>(76);
creature.ScriptID = GetScriptId(fields.Read<string>(77)); creature.ScriptID = GetScriptId(fields.Read<string>(77));