Core/Creature: implement school immunity for creatures in creature_template

Port From (https://github.com/TrinityCore/TrinityCore/commit/ed3b34e33f019d9200a3d003c467e0ffa351187a)
This commit is contained in:
hondacrx
2021-04-16 14:49:12 -04:00
parent 144ecb8817
commit 9714010ab3
5 changed files with 29 additions and 3 deletions
+22
View File
@@ -420,6 +420,7 @@ namespace Game.Entities
UpdateMovementFlags();
LoadCreaturesAddon();
LoadMechanicTemplateImmunity();
LoadSpellTemplateImmunity();
return true;
}
@@ -1892,6 +1893,27 @@ namespace Game.Entities
}
}
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;
if (mask != 0)
for (var i = (int)SpellSchoolMask.Normal; i <= (int)SpellSchoolMask.Arcane; ++i)
if ((mask & (1 << i)) != 0)
ApplySpellImmune(placeholderSpellId, SpellImmunity.School, 1u << i, true);
}
public override bool IsImmunedToSpell(SpellInfo spellInfo, Unit caster)
{
if (spellInfo == null)
@@ -89,6 +89,7 @@ namespace Game.Entities
public int WidgetSetUnitConditionID;
public bool RegenHealth;
public uint MechanicImmuneMask;
public byte SpellSchoolImmuneMask;
public CreatureFlagsExtra FlagsExtra;
public uint ScriptID;
+3 -2
View File
@@ -1870,8 +1870,9 @@ namespace Game
creature.WidgetSetUnitConditionID = fields.Read<int>(72);
creature.RegenHealth = fields.Read<bool>(73);
creature.MechanicImmuneMask = fields.Read<uint>(74);
creature.FlagsExtra = (CreatureFlagsExtra)fields.Read<uint>(75);
creature.ScriptID = GetScriptId(fields.Read<string>(76));
creature.SpellSchoolImmuneMask = fields.Read<byte>(75);
creature.FlagsExtra = (CreatureFlagsExtra)fields.Read<uint>(76);
creature.ScriptID = GetScriptId(fields.Read<string>(77));
_creatureTemplateStorage[entry] = creature;
}