From b7f85e9e43c215d098784fa26e4953f076223af5 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Mon, 27 Dec 2021 16:56:27 -0500 Subject: [PATCH] Entities/GO: FindNearestGameObject no longer incorrectly returns despawned gameobjects. Port From (https://github.com/TrinityCore/TrinityCore/commit/6de4c3cd72de1c7ae6e467b09ec181445b397338) --- Source/Game/Maps/GridNotifiers.cs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/Source/Game/Maps/GridNotifiers.cs b/Source/Game/Maps/GridNotifiers.cs index 376bb1987..524da4b60 100644 --- a/Source/Game/Maps/GridNotifiers.cs +++ b/Source/Game/Maps/GridNotifiers.cs @@ -2481,7 +2481,7 @@ namespace Game.Maps public class AllCreaturesOfEntryInRange : ICheck { - public AllCreaturesOfEntryInRange(WorldObject obj, uint entry, float maxRange) + public AllCreaturesOfEntryInRange(WorldObject obj, uint entry, float maxRange = 0f) { m_pObject = obj; m_uiEntry = entry; @@ -2490,10 +2490,20 @@ namespace Game.Maps public bool Invoke(Creature creature) { - if (m_uiEntry == 0 || creature.GetEntry() == m_uiEntry && m_pObject.IsWithinDist(creature, m_fRange, false)) - return true; + if (m_uiEntry != 0) + { + if (creature.GetEntry() != m_uiEntry) + return false; + } - return false; + if (m_fRange != 0f) + { + if (m_fRange > 0.0f && !m_pObject.IsWithinDist(creature, m_fRange, false)) + return false; + if (m_fRange < 0.0f && m_pObject.IsWithinDist(creature, m_fRange, false)) + return false; + } + return true; } WorldObject m_pObject; @@ -2740,7 +2750,7 @@ namespace Game.Maps public bool Invoke(GameObject go) { - if (go.GetEntry() == i_entry && go.GetGUID() != i_obj.GetGUID() && i_obj.IsWithinDistInMap(go, i_range)) + if (go.IsSpawned() && go.GetEntry() == i_entry && go.GetGUID() != i_obj.GetGUID() && i_obj.IsWithinDistInMap(go, i_range)) { i_range = i_obj.GetDistance(go); // use found GO range as new range limit for next check return true;