From 1f774369f2327bf1dff520ceed2fbe67c2489e52 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Mon, 31 Oct 2022 13:56:14 -0400 Subject: [PATCH] Core/Object: Implement FindNearestCreatureWithAura Port From (https://github.com/TrinityCore/TrinityCore/commit/9a3e29d416162a84dd6a11c5e248f5f65e98a604) --- Source/Game/Entities/Object/WorldObject.cs | 8 +++++ Source/Game/Maps/GridNotifiers.cs | 34 ++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/Source/Game/Entities/Object/WorldObject.cs b/Source/Game/Entities/Object/WorldObject.cs index ff1f4fe37..23aff289f 100644 --- a/Source/Game/Entities/Object/WorldObject.cs +++ b/Source/Game/Entities/Object/WorldObject.cs @@ -1619,6 +1619,14 @@ namespace Game.Entities return searcher.GetTarget(); } + public Creature FindNearestCreatureWithAura(uint entry, uint spellId, float range, bool alive = true) + { + var checker = new NearestCreatureEntryWithLiveStateAndAuraInObjectRangeCheck(this, entry, spellId, alive, range); + var searcher = new CreatureLastSearcher(this, checker); + Cell.VisitAllObjects(this, searcher, range); + return searcher.GetTarget(); + } + public GameObject FindNearestGameObject(uint entry, float range, bool spawnedOnly = true) { var checker = new NearestGameObjectEntryInObjectRangeCheck(this, entry, range, spawnedOnly); diff --git a/Source/Game/Maps/GridNotifiers.cs b/Source/Game/Maps/GridNotifiers.cs index 474726c43..d3a1d7a7f 100644 --- a/Source/Game/Maps/GridNotifiers.cs +++ b/Source/Game/Maps/GridNotifiers.cs @@ -2414,6 +2414,40 @@ namespace Game.Maps float i_range; } + public class NearestCreatureEntryWithLiveStateAndAuraInObjectRangeCheck : ICheck + { + WorldObject i_obj; + uint i_entry; + uint i_spellId; + bool i_alive; + float i_range; + + public NearestCreatureEntryWithLiveStateAndAuraInObjectRangeCheck(WorldObject obj, uint entry, uint spellId, bool alive, float range) + { + i_obj = obj; + i_entry = entry; + i_spellId = spellId; + i_alive = alive; + i_range = range; + } + + public bool Invoke(Creature u) + { + if (u.GetDeathState() != DeathState.Dead + && u.GetEntry() == i_entry + && u.HasAura(i_spellId) + && u.IsAlive() == i_alive + && u.GetGUID() != i_obj.GetGUID() + && i_obj.IsWithinDistInMap(u, i_range) + && u.CheckPrivateObjectOwnerVisibility(i_obj)) + { + i_range = i_obj.GetDistance(u); // use found unit range as new range limit for next check + return true; + } + return false; + } + } + public class AnyPlayerInObjectRangeCheck : ICheck { public AnyPlayerInObjectRangeCheck(WorldObject obj, float range, bool reqAlive = true)