Core/Auras: make area and dynauras condition compliant by using the spellarea searcher instead of script searchers

Port From (https://github.com/TrinityCore/TrinityCore/commit/1f3e365ff6c010424746f34104d1228fb6a96b8a)
This commit is contained in:
hondacrx
2021-06-23 23:23:48 -04:00
parent fdd904225c
commit 5bbd708070
2 changed files with 45 additions and 49 deletions
-7
View File
@@ -2077,13 +2077,6 @@ namespace Game.Maps
i_range = range; i_range = range;
i_incOwnRadius = incOwnRadius; i_incOwnRadius = incOwnRadius;
i_incTargetRadius = incTargetRadius; i_incTargetRadius = incTargetRadius;
if (_spellInfo == null)
{
DynamicObject dynObj = i_obj.ToDynamicObject();
if (dynObj)
_spellInfo = dynObj.GetSpellInfo();
}
} }
public bool Invoke(Unit u) public bool Invoke(Unit u)
+37 -34
View File
@@ -2546,9 +2546,11 @@ namespace Game.Spells
continue; continue;
List<Unit> targetList = new(); List<Unit> targetList = new();
var condList = effect.ImplicitTargetConditions;
// non-area aura // non-area aura
if (effect.Effect == SpellEffectName.ApplyAura) if (effect.Effect == SpellEffectName.ApplyAura)
{ {
if (condList == null || Global.ConditionMgr.IsObjectMeetToConditions(GetUnitOwner(), GetUnitOwner(), condList))
targetList.Add(GetUnitOwner()); targetList.Add(GetUnitOwner());
} }
else else
@@ -2557,34 +2559,24 @@ namespace Game.Spells
if (!GetUnitOwner().HasUnitState(UnitState.Isolated)) if (!GetUnitOwner().HasUnitState(UnitState.Isolated))
{ {
SpellTargetCheckTypes selectionType = SpellTargetCheckTypes.Default;
switch (effect.Effect) switch (effect.Effect)
{ {
case SpellEffectName.ApplyAreaAuraParty: case SpellEffectName.ApplyAreaAuraParty:
case SpellEffectName.ApplyAreaAuraRaid:
case SpellEffectName.ApplyAreaAuraPartyNonrandom: case SpellEffectName.ApplyAreaAuraPartyNonrandom:
{ selectionType = SpellTargetCheckTypes.Party;
targetList.Add(GetUnitOwner()); break;
var u_check = new AnyGroupedUnitInObjectRangeCheck(GetUnitOwner(), GetUnitOwner(), radius, effect.Effect == SpellEffectName.ApplyAreaAuraRaid, GetSpellInfo().HasAttribute(SpellAttr3.OnlyTargetPlayers), false, true); case SpellEffectName.ApplyAreaAuraRaid:
var searcher = new UnitListSearcher(GetUnitOwner(), targetList, u_check); selectionType = SpellTargetCheckTypes.Raid;
Cell.VisitAllObjects(GetUnitOwner(), searcher, radius);
break; break;
}
case SpellEffectName.ApplyAreaAuraFriend: case SpellEffectName.ApplyAreaAuraFriend:
{ selectionType = SpellTargetCheckTypes.Ally;
targetList.Add(GetUnitOwner());
var u_check = new AnyFriendlyUnitInObjectRangeCheck(GetUnitOwner(), GetUnitOwner(), radius, GetSpellInfo().HasAttribute(SpellAttr3.OnlyTargetPlayers), false, true);
var searcher = new UnitListSearcher(GetUnitOwner(), targetList, u_check);
Cell.VisitAllObjects(GetUnitOwner(), searcher, radius);
break; break;
}
case SpellEffectName.ApplyAreaAuraEnemy: case SpellEffectName.ApplyAreaAuraEnemy:
{ selectionType = SpellTargetCheckTypes.Enemy;
var u_check = new AnyAoETargetUnitInObjectRangeCheck(GetUnitOwner(), GetUnitOwner(), radius, GetSpellInfo(), false, true);
var searcher = new UnitListSearcher(GetUnitOwner(), targetList, u_check);
Cell.VisitAllObjects(GetUnitOwner(), searcher, radius);
break; break;
}
case SpellEffectName.ApplyAreaAuraPet: case SpellEffectName.ApplyAreaAuraPet:
if (condList == null || Global.ConditionMgr.IsObjectMeetToConditions(GetUnitOwner(), GetUnitOwner(), condList))
targetList.Add(GetUnitOwner()); targetList.Add(GetUnitOwner());
goto case SpellEffectName.ApplyAreaAuraOwner; goto case SpellEffectName.ApplyAreaAuraOwner;
case SpellEffectName.ApplyAreaAuraOwner: case SpellEffectName.ApplyAreaAuraOwner:
@@ -2592,6 +2584,7 @@ namespace Game.Spells
Unit owner = GetUnitOwner().GetCharmerOrOwner(); Unit owner = GetUnitOwner().GetCharmerOrOwner();
if (owner != null) if (owner != null)
if (GetUnitOwner().IsWithinDistInMap(owner, radius)) if (GetUnitOwner().IsWithinDistInMap(owner, radius))
if (condList == null || Global.ConditionMgr.IsObjectMeetToConditions(owner, GetUnitOwner(), condList))
targetList.Add(owner); targetList.Add(owner);
break; break;
} }
@@ -2599,20 +2592,29 @@ namespace Game.Spells
{ {
Unit pet = Global.ObjAccessor.GetUnit(GetUnitOwner(), GetUnitOwner().GetPetGUID()); Unit pet = Global.ObjAccessor.GetUnit(GetUnitOwner(), GetUnitOwner().GetPetGUID());
if (pet != null) if (pet != null)
if (condList == null || Global.ConditionMgr.IsObjectMeetToConditions(pet, GetUnitOwner(), condList))
targetList.Add(pet); targetList.Add(pet);
break; break;
} }
case SpellEffectName.ApplyAreaAuraSummons: case SpellEffectName.ApplyAreaAuraSummons:
{ {
if (condList == null || Global.ConditionMgr.IsObjectMeetToConditions(GetUnitOwner(), GetUnitOwner(), condList))
targetList.Add(GetUnitOwner()); targetList.Add(GetUnitOwner());
WorldObjectSpellAreaTargetCheck check = new(radius, GetUnitOwner(), caster, GetUnitOwner(), GetSpellInfo(), SpellTargetCheckTypes.Summoned, effect.ImplicitTargetConditions, SpellTargetObjectTypes.Unit);
UnitListSearcher searcher = new(GetUnitOwner(), targetList, check); selectionType = SpellTargetCheckTypes.Summoned;
Cell.VisitAllObjects(GetUnitOwner(), searcher, radius);
// by design WorldObjectSpellAreaTargetCheck allows not-in-world units (for spells) but for auras it is not acceptable
targetList.RemoveAll(unit => !unit.IsSelfOrInSameMap(GetUnitOwner()));
break; break;
} }
} }
if (selectionType != SpellTargetCheckTypes.Default)
{
WorldObjectSpellAreaTargetCheck check = new(radius, GetUnitOwner(), caster, GetUnitOwner(), GetSpellInfo(), selectionType, condList, SpellTargetObjectTypes.Unit);
UnitListSearcher searcher = new(GetUnitOwner(), targetList, check);
Cell.VisitAllObjects(GetUnitOwner(), searcher, radius);
// by design WorldObjectSpellAreaTargetCheck allows not-in-world units (for spells) but for auras it is not acceptable
targetList.RemoveAll(unit => !unit.IsSelfOrInSameMap(GetUnitOwner()));
}
} }
} }
@@ -2664,19 +2666,20 @@ namespace Game.Spells
if (effect == null || !HasEffect(effect.EffectIndex)) if (effect == null || !HasEffect(effect.EffectIndex))
continue; continue;
// we can't use effect type like area auras to determine check type, check targets
SpellTargetCheckTypes selectionType = effect.TargetA.GetCheckType();
if (effect.TargetB.GetReferenceType() == SpellTargetReferenceTypes.Dest)
selectionType = effect.TargetB.GetCheckType();
List<Unit> targetList = new(); List<Unit> targetList = new();
if (effect.TargetB.GetTarget() == Targets.DestDynobjAlly || effect.TargetB.GetTarget() == Targets.UnitDestAreaAlly) var condList = effect.ImplicitTargetConditions;
{
var u_check = new AnyFriendlyUnitInObjectRangeCheck(GetDynobjOwner(), dynObjOwnerCaster, radius, GetSpellInfo().HasAttribute(SpellAttr3.OnlyTargetPlayers), false, true); WorldObjectSpellAreaTargetCheck check = new(radius, GetDynobjOwner(), dynObjOwnerCaster, dynObjOwnerCaster, GetSpellInfo(), selectionType, condList, SpellTargetObjectTypes.Unit);
var searcher = new UnitListSearcher(GetDynobjOwner(), targetList, u_check); UnitListSearcher searcher = new(GetDynobjOwner(), targetList, check);
Cell.VisitAllObjects(GetDynobjOwner(), searcher, radius); Cell.VisitAllObjects(GetDynobjOwner(), searcher, radius);
}
else // by design WorldObjectSpellAreaTargetCheck allows not-in-world units (for spells) but for auras it is not acceptable
{ targetList.RemoveAll(unit => !unit.IsSelfOrInSameMap(GetUnitOwner()));
var u_check = new AnyAoETargetUnitInObjectRangeCheck(GetDynobjOwner(), dynObjOwnerCaster, radius, null, false, true);
var searcher = new UnitListSearcher(GetDynobjOwner(), targetList, u_check);
Cell.VisitAllObjects(GetDynobjOwner(), searcher, radius);
}
foreach (var unit in targetList) foreach (var unit in targetList)
{ {