diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/server/game/Entities/Creature/Creature.cpp | 33 | ||||
-rw-r--r-- | src/server/game/Entities/Creature/Creature.h | 2 |
2 files changed, 23 insertions, 12 deletions
diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index 5742404926f..46993d92e09 100644 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -555,6 +555,7 @@ bool Creature::UpdateEntry(uint32 entry, CreatureData const* data /*= nullptr*/, UpdateMovementFlags(); LoadCreaturesAddon(); + LoadMechanicTemplateImmunity(); return true; } @@ -1905,9 +1906,28 @@ void Creature::DespawnOrUnsummon(uint32 msTimeToDespawn /*= 0*/, Seconds const& ForcedDespawn(msTimeToDespawn, forceRespawnTimer); } -bool Creature::HasMechanicTemplateImmunity(uint32 mask) const +void Creature::LoadMechanicTemplateImmunity() { - return (!GetOwnerGUID().IsPlayer() || !IsHunterPet()) && (GetCreatureTemplate()->MechanicImmuneMask & 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 + static uint32 const placeholderSpellId = std::numeric_limits<uint32>::max(); + + // unapply template immunities (in case we're updating entry) + for (uint32 i = MECHANIC_NONE + 1; i < MAX_MECHANIC; ++i) + ApplySpellImmune(placeholderSpellId, IMMUNITY_MECHANIC, i, false); + + // don't inherit immunities for hunter pets + if (GetOwnerGUID().IsPlayer() && IsHunterPet()) + return; + + if (uint32 mask = GetCreatureTemplate()->MechanicImmuneMask) + { + for (uint32 i = MECHANIC_NONE + 1; i < MAX_MECHANIC; ++i) + { + if (mask & (1 << (i - 1))) + ApplySpellImmune(placeholderSpellId, IMMUNITY_MECHANIC, i, true); + } + } } bool Creature::IsImmunedToSpell(SpellInfo const* spellInfo, Unit* caster) const @@ -1915,12 +1935,6 @@ bool Creature::IsImmunedToSpell(SpellInfo const* spellInfo, Unit* caster) const if (!spellInfo) return false; - // Creature is immune to main mechanic of the spell - if (spellInfo->Mechanic > MECHANIC_NONE && HasMechanicTemplateImmunity(1 << (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; for (uint8 i = 0; i < MAX_SPELL_EFFECTS; ++i) { @@ -1939,9 +1953,6 @@ bool Creature::IsImmunedToSpell(SpellInfo const* spellInfo, Unit* caster) const bool Creature::IsImmunedToSpellEffect(SpellInfo const* spellInfo, uint32 index, Unit* caster) const { - if (spellInfo->Effects[index].Mechanic > MECHANIC_NONE && HasMechanicTemplateImmunity(1 << (spellInfo->Effects[index].Mechanic - 1))) - return true; - if (GetCreatureTemplate()->type == CREATURE_TYPE_MECHANICAL && spellInfo->Effects[index].Effect == SPELL_EFFECT_HEAL) return true; diff --git a/src/server/game/Entities/Creature/Creature.h b/src/server/game/Entities/Creature/Creature.h index fd00f63635f..1fc9833e376 100644 --- a/src/server/game/Entities/Creature/Creature.h +++ b/src/server/game/Entities/Creature/Creature.h @@ -478,7 +478,7 @@ class TC_GAME_API Creature : public Unit, public GridObject<Creature>, public Ma bool isCanInteractWithBattleMaster(Player* player, bool msg) const; bool isCanTrainingAndResetTalentsOf(Player* player) const; bool CanCreatureAttack(Unit const* victim, bool force = true) const; - bool HasMechanicTemplateImmunity(uint32 mask) const; + void LoadMechanicTemplateImmunity(); bool IsImmunedToSpell(SpellInfo const* spellInfo, Unit* caster) const override; bool IsImmunedToSpellEffect(SpellInfo const* spellInfo, uint32 index, Unit* caster) const override; bool isElite() const; |