diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index de208f8970..f4bf568610 100644 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -1873,7 +1873,7 @@ void Creature::LoadMechanicTemplateImmunity() } } -bool Creature::IsImmunedToSpell(SpellInfo const* spellInfo) const +bool Creature::IsImmunedToSpell(SpellInfo const* spellInfo, Unit* caster) const { if (!spellInfo) return false; @@ -1883,7 +1883,7 @@ bool Creature::IsImmunedToSpell(SpellInfo const* spellInfo) const { if (!spellInfo->Effects[i].IsEffect()) continue; - if (!IsImmunedToSpellEffect(spellInfo, i)) + if (!IsImmunedToSpellEffect(spellInfo, i, caster)) { immunedToAllEffects = false; break; @@ -1892,15 +1892,15 @@ bool Creature::IsImmunedToSpell(SpellInfo const* spellInfo) const if (immunedToAllEffects) return true; - return Unit::IsImmunedToSpell(spellInfo); + return Unit::IsImmunedToSpell(spellInfo, caster); } -bool Creature::IsImmunedToSpellEffect(SpellInfo const* spellInfo, uint32 index) const +bool Creature::IsImmunedToSpellEffect(SpellInfo const* spellInfo, uint32 index, Unit* caster) const { if (GetCreatureTemplate()->type == CREATURE_TYPE_MECHANICAL && spellInfo->Effects[index].Effect == SPELL_EFFECT_HEAL) return true; - return Unit::IsImmunedToSpellEffect(spellInfo, index); + return Unit::IsImmunedToSpellEffect(spellInfo, index, caster); } bool Creature::isElite() const diff --git a/src/server/game/Entities/Creature/Creature.h b/src/server/game/Entities/Creature/Creature.h index b71437de47..6eb8f15c74 100644 --- a/src/server/game/Entities/Creature/Creature.h +++ b/src/server/game/Entities/Creature/Creature.h @@ -497,8 +497,8 @@ class TC_GAME_API Creature : public Unit, public GridObject, public Ma bool isCanTrainingAndResetTalentsOf(Player* player) const; bool CanCreatureAttack(Unit const* victim, bool force = true) const; void LoadMechanicTemplateImmunity(); - bool IsImmunedToSpell(SpellInfo const* spellInfo) const override; // override Unit::IsImmunedToSpell - bool IsImmunedToSpellEffect(SpellInfo const* spellInfo, uint32 index) const override; // override Unit::IsImmunedToSpellEffect + bool IsImmunedToSpell(SpellInfo const* spellInfo, Unit* caster) const override; + bool IsImmunedToSpellEffect(SpellInfo const* spellInfo, uint32 index, Unit* caster) const override; bool isElite() const; bool isWorldBoss() const; diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index 7d3def9079..a1139d9cba 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -2225,7 +2225,7 @@ void Player::SetObjectScale(float scale) SendMovementSetCollisionHeight(scale * GetCollisionHeight(IsMounted())); } -bool Player::IsImmunedToSpellEffect(SpellInfo const* spellInfo, uint32 index) const +bool Player::IsImmunedToSpellEffect(SpellInfo const* spellInfo, uint32 index, Unit* caster) const { // players are immune to taunt (the aura and the spell effect) if (spellInfo->Effects[index].IsAura(SPELL_AURA_MOD_TAUNT)) @@ -2233,7 +2233,7 @@ bool Player::IsImmunedToSpellEffect(SpellInfo const* spellInfo, uint32 index) co if (spellInfo->Effects[index].IsEffect(SPELL_EFFECT_ATTACK_ME)) return true; - return Unit::IsImmunedToSpellEffect(spellInfo, index); + return Unit::IsImmunedToSpellEffect(spellInfo, index, caster); } void Player::RegenerateAll() diff --git a/src/server/game/Entities/Player/Player.h b/src/server/game/Entities/Player/Player.h index 2384bed559..61ff993127 100644 --- a/src/server/game/Entities/Player/Player.h +++ b/src/server/game/Entities/Player/Player.h @@ -1243,7 +1243,7 @@ class TC_GAME_API Player : public Unit, public GridObject static bool BuildEnumData(PreparedQueryResult result, ByteBuffer* dataBuffer, ByteBuffer* bitBuffer); - bool IsImmunedToSpellEffect(SpellInfo const* spellInfo, uint32 index) const override; + bool IsImmunedToSpellEffect(SpellInfo const* spellInfo, uint32 index, Unit* caster) const override; void SetInWater(bool apply); diff --git a/src/server/game/Entities/Totem/Totem.cpp b/src/server/game/Entities/Totem/Totem.cpp index 9bb78f95b6..14a0ca1f19 100644 --- a/src/server/game/Entities/Totem/Totem.cpp +++ b/src/server/game/Entities/Totem/Totem.cpp @@ -143,7 +143,7 @@ void Totem::UnSummon(uint32 msTime) AddObjectToRemoveList(); } -bool Totem::IsImmunedToSpellEffect(SpellInfo const* spellInfo, uint32 index) const +bool Totem::IsImmunedToSpellEffect(SpellInfo const* spellInfo, uint32 index, Unit* caster) const { /// @todo possibly all negative auras immune? if (GetEntry() == 5925) @@ -160,5 +160,5 @@ bool Totem::IsImmunedToSpellEffect(SpellInfo const* spellInfo, uint32 index) con break; } - return Creature::IsImmunedToSpellEffect(spellInfo, index); + return Creature::IsImmunedToSpellEffect(spellInfo, index, caster); } diff --git a/src/server/game/Entities/Totem/Totem.h b/src/server/game/Entities/Totem/Totem.h index f8283a97e8..8a0edb1943 100644 --- a/src/server/game/Entities/Totem/Totem.h +++ b/src/server/game/Entities/Totem/Totem.h @@ -58,7 +58,7 @@ class TC_GAME_API Totem : public Minion void UpdateAttackPowerAndDamage(bool /*ranged*/) override { } void UpdateDamagePhysical(WeaponAttackType /*attType*/) override { } - bool IsImmunedToSpellEffect(SpellInfo const* spellInfo, uint32 index) const override; + bool IsImmunedToSpellEffect(SpellInfo const* spellInfo, uint32 index, Unit* caster) const override; protected: TotemType m_type; diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index bdc9d6a941..61ccecdcee 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -2589,13 +2589,13 @@ SpellMissInfo Unit::MagicSpellHitResult(Unit* victim, SpellInfo const* spellInfo // Parry // For spells // Resist -SpellMissInfo Unit::SpellHitResult(Unit* victim, SpellInfo const* spellInfo, bool CanReflect) +SpellMissInfo Unit::SpellHitResult(Unit* victim, SpellInfo const* spellInfo, bool canReflect /*= false*/) { if (spellInfo->HasAttribute(SPELL_ATTR3_IGNORE_HIT_RESULT)) return SPELL_MISS_NONE; // Check for immune - if (victim->IsImmunedToSpell(spellInfo)) + if (victim->IsImmunedToSpell(spellInfo, this)) return SPELL_MISS_IMMUNE; // Damage immunity is only checked if the spell has damage effects, this immunity must not prevent aura apply @@ -2616,7 +2616,7 @@ SpellMissInfo Unit::SpellHitResult(Unit* victim, SpellInfo const* spellInfo, boo return SPELL_MISS_EVADE; // Try victim reflect spell - if (CanReflect) + if (canReflect) { int32 reflectchance = victim->GetTotalAuraModifier(SPELL_AURA_REFLECT_SPELLS); Unit::AuraEffectList const& mReflectSpellsSchool = victim->GetAuraEffectsByType(SPELL_AURA_REFLECT_SPELLS_SCHOOL); @@ -7665,7 +7665,7 @@ bool Unit::IsImmunedToDamage(SpellInfo const* spellInfo) const return false; } -bool Unit::IsImmunedToSpell(SpellInfo const* spellInfo) const +bool Unit::IsImmunedToSpell(SpellInfo const* spellInfo, Unit* caster) const { if (!spellInfo) return false; @@ -7698,7 +7698,7 @@ bool Unit::IsImmunedToSpell(SpellInfo const* spellInfo) const { // State/effect immunities applied by aura expect full spell immunity // Ignore effects with mechanic, they are supposed to be checked separately - if (!IsImmunedToSpellEffect(spellInfo, i)) + if (!IsImmunedToSpellEffect(spellInfo, i, caster)) { immuneToAllEffects = false; break; @@ -7715,7 +7715,7 @@ bool Unit::IsImmunedToSpell(SpellInfo const* spellInfo) const { SpellInfo const* immuneSpellInfo = sSpellMgr->GetSpellInfo(itr->second); if ((itr->first & spellInfo->GetSchoolMask()) - && !(immuneSpellInfo && immuneSpellInfo->IsPositive() && spellInfo->IsPositive()) + && !(immuneSpellInfo && immuneSpellInfo->IsPositive() && spellInfo->IsPositive() && IsFriendlyTo(caster)) && !spellInfo->CanPierceImmuneAura(immuneSpellInfo)) return true; } @@ -7744,7 +7744,7 @@ uint32 Unit::GetMechanicImmunityMask() const return mask; } -bool Unit::IsImmunedToSpellEffect(SpellInfo const* spellInfo, uint32 index) const +bool Unit::IsImmunedToSpellEffect(SpellInfo const* spellInfo, uint32 index, Unit* caster) const { if (!spellInfo || !spellInfo->Effects[index].IsEffect()) return false; @@ -7754,13 +7754,13 @@ bool Unit::IsImmunedToSpellEffect(SpellInfo const* spellInfo, uint32 index) cons // If m_immuneToEffect type contain this effect type, IMMUNE effect. uint32 effect = spellInfo->Effects[index].Effect; - auto const& effectList = m_spellImmune[IMMUNITY_EFFECT]; + SpellImmuneContainer const& effectList = m_spellImmune[IMMUNITY_EFFECT]; if (effectList.count(effect) > 0) return true; if (uint32 mechanic = spellInfo->Effects[index].Mechanic) { - auto const& mechanicList = m_spellImmune[IMMUNITY_MECHANIC]; + SpellImmuneContainer const& mechanicList = m_spellImmune[IMMUNITY_MECHANIC]; if (mechanicList.count(mechanic) > 0) return true; } @@ -7778,8 +7778,8 @@ bool Unit::IsImmunedToSpellEffect(SpellInfo const* spellInfo, uint32 index) cons // Check for immune to application of harmful magical effects AuraEffectList const& immuneAuraApply = GetAuraEffectsByType(SPELL_AURA_MOD_IMMUNE_AURA_APPLY_SCHOOL); for (AuraEffectList::const_iterator iter = immuneAuraApply.begin(); iter != immuneAuraApply.end(); ++iter) - if (((*iter)->GetMiscValue() & spellInfo->GetSchoolMask()) && // Check school - !spellInfo->IsPositiveEffect(index)) // Harmful + if (((*iter)->GetMiscValue() & spellInfo->GetSchoolMask()) && // Check school + (!IsFriendlyTo(caster) || !spellInfo->IsPositiveEffect(index))) // Harmful return true; } } @@ -12353,15 +12353,15 @@ Aura* Unit::AddAura(SpellInfo const* spellInfo, uint8 effMask, Unit* target) if (!spellInfo) return NULL; - if (target->IsImmunedToSpell(spellInfo)) + if (target->IsImmunedToSpell(spellInfo, this)) return NULL; for (uint32 i = 0; i < MAX_SPELL_EFFECTS; ++i) { - if (!(effMask & (1<IsImmunedToSpellEffect(spellInfo, i)) - effMask &= ~(1<IsImmunedToSpellEffect(spellInfo, i, this)) + effMask &= ~(1 << i); } if (Aura* aura = Aura::TryRefreshStackOrCreate(spellInfo, effMask, target, this)) diff --git a/src/server/game/Entities/Unit/Unit.h b/src/server/game/Entities/Unit/Unit.h index 921f69ee4f..0158a27778 100644 --- a/src/server/game/Entities/Unit/Unit.h +++ b/src/server/game/Entities/Unit/Unit.h @@ -2054,13 +2054,13 @@ class TC_GAME_API Unit : public WorldObject uint32 GetRemainingPeriodicAmount(ObjectGuid caster, uint32 spellId, AuraType auraType, uint8 effectIndex = 0) const; void ApplySpellImmune(uint32 spellId, uint32 op, uint32 type, bool apply); - virtual bool IsImmunedToSpell(SpellInfo const* spellInfo) const; // redefined in Creature + virtual bool IsImmunedToSpell(SpellInfo const* spellInfo, Unit* caster) const; // redefined in Creature uint32 GetSchoolImmunityMask() const; uint32 GetMechanicImmunityMask() const; bool IsImmunedToDamage(SpellSchoolMask meleeSchoolMask) const; bool IsImmunedToDamage(SpellInfo const* spellInfo) const; - virtual bool IsImmunedToSpellEffect(SpellInfo const* spellInfo, uint32 index) const; // redefined in Creature + virtual bool IsImmunedToSpellEffect(SpellInfo const* spellInfo, uint32 index, Unit* caster) const; // redefined in Creature static bool IsDamageReducedByArmor(SpellSchoolMask damageSchoolMask, SpellInfo const* spellInfo = NULL, uint8 effIndex = MAX_SPELL_EFFECTS); uint32 CalcArmorReducedDamage(Unit* victim, const uint32 damage, SpellInfo const* spellInfo, WeaponAttackType attackType = MAX_ATTACK); diff --git a/src/server/game/Spells/Auras/SpellAuras.cpp b/src/server/game/Spells/Auras/SpellAuras.cpp index c8c2897a48..88f5313381 100644 --- a/src/server/game/Spells/Auras/SpellAuras.cpp +++ b/src/server/game/Spells/Auras/SpellAuras.cpp @@ -550,11 +550,11 @@ void Aura::UpdateTargetMap(Unit* caster, bool apply) // check target immunities for (uint8 effIndex = 0; effIndex < MAX_SPELL_EFFECTS; ++effIndex) { - if (itr->first->IsImmunedToSpellEffect(GetSpellInfo(), effIndex)) + if (itr->first->IsImmunedToSpellEffect(GetSpellInfo(), effIndex, caster)) itr->second &= ~(1 << effIndex); } if (!itr->second - || itr->first->IsImmunedToSpell(GetSpellInfo()) + || itr->first->IsImmunedToSpell(GetSpellInfo(), caster) || !CanBeAppliedOn(itr->first)) addUnit = false; diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp index 97375defb3..70ded10536 100644 --- a/src/server/game/Spells/Spell.cpp +++ b/src/server/game/Spells/Spell.cpp @@ -1178,7 +1178,7 @@ void Spell::SelectImplicitAreaTargets(SpellEffIndex effIndex, SpellImplicitTarge // find last added target for this effect for (std::list::reverse_iterator ihit = m_UniqueTargetInfo.rbegin(); ihit != m_UniqueTargetInfo.rend(); ++ihit) { - if (ihit->effectMask & (1<effectMask & (1 << effIndex)) { referer = ObjectAccessor::GetUnit(*m_caster, ihit->targetGUID); break; @@ -2077,7 +2077,7 @@ void Spell::AddUnitTarget(Unit* target, uint32 effectMask, bool checkIfValid /*= // Check for effect immune skip if immuned for (uint32 effIndex = 0; effIndex < MAX_SPELL_EFFECTS; ++effIndex) - if (target->IsImmunedToSpellEffect(m_spellInfo, effIndex)) + if (target->IsImmunedToSpellEffect(m_spellInfo, effIndex, m_caster)) effectMask &= ~(1 << effIndex); ObjectGuid targetGUID = target->GetGUID(); @@ -2557,14 +2557,14 @@ SpellMissInfo Spell::DoSpellHitOnUnit(Unit* unit, uint32 effectMask, bool scaleA return SPELL_MISS_EVADE; // For delayed spells immunity may be applied between missile launch and hit - check immunity for that case - if (m_spellInfo->Speed && unit->IsImmunedToSpell(m_spellInfo)) + if (m_spellInfo->Speed && unit->IsImmunedToSpell(m_spellInfo, m_caster)) return SPELL_MISS_IMMUNE; // disable effects to which unit is immune SpellMissInfo returnVal = SPELL_MISS_IMMUNE; for (uint32 effectNumber = 0; effectNumber < MAX_SPELL_EFFECTS; ++effectNumber) if (effectMask & (1 << effectNumber)) - if (unit->IsImmunedToSpellEffect(m_spellInfo, effectNumber)) + if (unit->IsImmunedToSpellEffect(m_spellInfo, effectNumber, m_caster)) effectMask &= ~(1 << effectNumber); if (!effectMask)