Core/Spells: Fixed spell with SPELL_AURA_MECHANIC_IMMUNITY_MASK failing to cast if they were supposed to purge effect they are granting immunity to (CreatureImmunities was not checked)

Port From (https://github.com/TrinityCore/TrinityCore/commit/e1e4aa7980a6e91a330d615467b2c25b60dcbcc1)
This commit is contained in:
Hondacrx
2024-08-26 16:24:24 -04:00
parent f908481bce
commit 7946aa1958
2 changed files with 65 additions and 75 deletions
+7 -7
View File
@@ -2772,6 +2772,13 @@ namespace Game.Spells
targets.Add(target, targetPair.Value);
}
// skip area update if owner is not in world!
if (!GetUnitOwner().IsInWorld)
return;
if (GetUnitOwner().HasAuraState(AuraStateType.Banished, GetSpellInfo(), caster))
return;
foreach (var spellEffectInfo in GetSpellInfo().GetEffects())
{
if (!HasEffect(spellEffectInfo.EffectIndex))
@@ -2781,13 +2788,6 @@ namespace Game.Spells
if (spellEffectInfo.Effect == SpellEffectName.ApplyAura)
continue;
// skip area update if owner is not in world!
if (!GetUnitOwner().IsInWorld)
continue;
if (GetUnitOwner().HasAuraState(AuraStateType.Banished, GetSpellInfo(), caster))
continue;
List<WorldObject> units = new();
var condList = spellEffectInfo.ImplicitTargetConditions;
+58 -68
View File
@@ -2435,49 +2435,29 @@ namespace Game.Spells
bool immuneToAllEffects = true;
foreach (var auraSpellEffectInfo in auraSpellInfo.GetEffects())
{
if (!auraSpellEffectInfo.IsEffect())
if (!auraSpellEffectInfo.IsAura())
continue;
if (!immuneInfo.SpellEffectImmune.Contains(auraSpellEffectInfo.Effect))
{
immuneToAllEffects = false;
break;
}
if (mechanicImmunity != 0)
if ((mechanicImmunity & (1ul << (int)auraSpellEffectInfo.Mechanic)) != 0)
continue;
uint mechanic = (uint)auraSpellEffectInfo.Mechanic;
if (mechanic != 0)
AuraType auraName = auraSpellEffectInfo.ApplyAuraName;
if (auraName != 0)
{
if (!Convert.ToBoolean(immuneInfo.MechanicImmuneMask & (1ul << (int)mechanic)))
if (immuneInfo.AuraTypeImmune.Contains(auraName))
continue;
if (!auraSpellInfo.HasAttribute(SpellAttr2.NoSchoolImmunities) && !auraSpellInfo.IsPositiveEffect(auraSpellEffectInfo.EffectIndex))
{
immuneToAllEffects = false;
break;
uint applyHarmfulAuraImmunityMask = immuneInfo.ApplyHarmfulAuraImmuneMask;
if (applyHarmfulAuraImmunityMask != 0)
if (((uint)auraSpellInfo.GetSchoolMask() & applyHarmfulAuraImmunityMask) != 0)
continue;
}
}
if (!auraSpellInfo.HasAttribute(SpellAttr3.AlwaysHit))
{
AuraType auraName = auraSpellEffectInfo.ApplyAuraName;
if (auraName != 0)
{
bool isImmuneToAuraEffectApply = false;
if (!immuneInfo.AuraTypeImmune.Contains(auraName))
isImmuneToAuraEffectApply = true;
if (!isImmuneToAuraEffectApply && !auraSpellInfo.IsPositiveEffect(auraSpellEffectInfo.EffectIndex) && !auraSpellInfo.HasAttribute(SpellAttr2.NoSchoolImmunities))
{
uint applyHarmfulAuraImmunityMask = immuneInfo.ApplyHarmfulAuraImmuneMask;
if (applyHarmfulAuraImmunityMask != 0)
if (((uint)auraSpellInfo.GetSchoolMask() & applyHarmfulAuraImmunityMask) != 0)
isImmuneToAuraEffectApply = true;
}
if (!isImmuneToAuraEffectApply)
{
immuneToAllEffects = false;
break;
}
}
}
immuneToAllEffects = false;
}
if (immuneToAllEffects)
@@ -2487,6 +2467,44 @@ namespace Game.Spells
return false;
}
bool CanSpellEffectProvideImmunityAgainstAuraEffect(SpellEffectInfo immunityEffectInfo, SpellInfo auraSpellInfo, SpellEffectInfo auraEffectInfo)
{
ImmunityInfo immuneInfo = immunityEffectInfo.GetImmunityInfo();
if (immuneInfo == null)
return false;
if (!auraSpellInfo.HasAttribute(SpellAttr2.NoSchoolImmunities))
{
uint schoolImmunity = immuneInfo.SchoolImmuneMask;
if (schoolImmunity != 0)
if (((uint)auraSpellInfo.SchoolMask & schoolImmunity) != 0)
return true;
uint applyHarmfulAuraImmunityMask = immuneInfo.ApplyHarmfulAuraImmuneMask;
if (applyHarmfulAuraImmunityMask != 0)
if (((uint)auraSpellInfo.GetSchoolMask() & applyHarmfulAuraImmunityMask) != 0)
return true;
}
ulong mechanicImmunity = immuneInfo.MechanicImmuneMask;
if (mechanicImmunity != 0)
{
if ((mechanicImmunity & (1ul << (int)auraSpellInfo.Mechanic)) != 0)
return true;
if ((mechanicImmunity & (1ul << (int)auraEffectInfo.Mechanic)) != 0)
return true;
}
uint dispelImmunity = immuneInfo.DispelImmuneMask;
if (dispelImmunity != 0 && (uint)auraSpellInfo.Dispel == dispelImmunity)
return true;
if (immuneInfo.AuraTypeImmune.Contains(auraEffectInfo.ApplyAuraName))
return true;
return false;
}
public bool SpellCancelsAuraEffect(AuraEffect aurEff)
{
if (!HasAttribute(SpellAttr1.ImmunityPurgesEffect))
@@ -2495,40 +2513,12 @@ namespace Game.Spells
if (aurEff.GetSpellInfo().HasAttribute(SpellAttr0.NoImmunities))
return false;
foreach (var effectInfo in GetEffects())
{
if (!effectInfo.IsEffect(SpellEffectName.ApplyAura))
continue;
if (aurEff.GetSpellEffectInfo().EffectAttributes.HasFlag(SpellEffectAttributes.NoImmunity))
return false;
uint miscValue = (uint)effectInfo.MiscValue;
switch (effectInfo.ApplyAuraName)
{
case AuraType.StateImmunity:
if (miscValue != (uint)aurEff.GetAuraType())
continue;
break;
case AuraType.SchoolImmunity:
case AuraType.ModImmuneAuraApplySchool:
if (aurEff.GetSpellInfo().HasAttribute(SpellAttr2.NoSchoolImmunities) || !Convert.ToBoolean((uint)aurEff.GetSpellInfo().SchoolMask & miscValue))
continue;
break;
case AuraType.DispelImmunity:
if (miscValue != (uint)aurEff.GetSpellInfo().Dispel)
continue;
break;
case AuraType.MechanicImmunity:
if (miscValue != (uint)aurEff.GetSpellInfo().Mechanic)
{
if (miscValue != (uint)aurEff.GetSpellEffectInfo().Mechanic)
continue;
}
break;
default:
continue;
}
return true;
}
foreach (SpellEffectInfo effect in GetEffects())
if (CanSpellEffectProvideImmunityAgainstAuraEffect(effect, aurEff.GetSpellInfo(), aurEff.GetSpellEffectInfo()))
return true;
return false;
}