From 762a32cb65ea7cd9d802f9621e701afce9709303 Mon Sep 17 00:00:00 2001 From: Teleqraph Date: Sun, 30 Oct 2022 22:29:03 +0100 Subject: Core/Object: Implement FindNearestCreatureWithAura (#28410) * Game/Object: Implement NearestCreatureEntryWithLiveStateAndAuraInObjectRangeCheck class and FindNearestCreatureWithAura method * moved arguments (cherry picked from commit 9a3e29d416162a84dd6a11c5e248f5f65e98a604) --- src/server/game/Entities/Object/Object.cpp | 9 +++++++ src/server/game/Entities/Object/Object.h | 1 + src/server/game/Grids/Notifiers/GridNotifiers.h | 33 +++++++++++++++++++++++++ 3 files changed, 43 insertions(+) (limited to 'src') diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp index 31ba39d5a23..b944d94a666 100644 --- a/src/server/game/Entities/Object/Object.cpp +++ b/src/server/game/Entities/Object/Object.cpp @@ -2126,6 +2126,15 @@ Creature* WorldObject::FindNearestCreature(uint32 entry, float range, bool alive return creature; } +Creature* WorldObject::FindNearestCreatureWithAura(uint32 entry, uint32 spellId, float range, bool alive) const +{ + Creature* creature = nullptr; + Trinity::NearestCreatureEntryWithLiveStateAndAuraInObjectRangeCheck checker(*this, entry, spellId, alive, range); + Trinity::CreatureLastSearcher searcher(this, creature, checker); + Cell::VisitAllObjects(this, searcher, range); + return creature; +} + GameObject* WorldObject::FindNearestGameObject(uint32 entry, float range, bool spawnedOnly) const { GameObject* go = nullptr; diff --git a/src/server/game/Entities/Object/Object.h b/src/server/game/Entities/Object/Object.h index b3cd579df89..ac9a4dae5ee 100644 --- a/src/server/game/Entities/Object/Object.h +++ b/src/server/game/Entities/Object/Object.h @@ -426,6 +426,7 @@ class TC_GAME_API WorldObject : public Object, public WorldLocation void SummonCreatureGroup(uint8 group, std::list* list = nullptr); Creature* FindNearestCreature(uint32 entry, float range, bool alive = true) const; + Creature* FindNearestCreatureWithAura(uint32 entry, uint32 spellId, float range, bool alive = true) const; GameObject* FindNearestGameObject(uint32 entry, float range, bool spawnedOnly = true) const; GameObject* FindNearestUnspawnedGameObject(uint32 entry, float range) const; GameObject* FindNearestGameObjectOfType(GameobjectTypes type, float range) const; diff --git a/src/server/game/Grids/Notifiers/GridNotifiers.h b/src/server/game/Grids/Notifiers/GridNotifiers.h index 3603c2667e2..ef473e63e9d 100644 --- a/src/server/game/Grids/Notifiers/GridNotifiers.h +++ b/src/server/game/Grids/Notifiers/GridNotifiers.h @@ -1398,6 +1398,39 @@ namespace Trinity NearestCreatureEntryWithLiveStateInObjectRangeCheck(NearestCreatureEntryWithLiveStateInObjectRangeCheck const&) = delete; }; + class NearestCreatureEntryWithLiveStateAndAuraInObjectRangeCheck + { + public: + NearestCreatureEntryWithLiveStateAndAuraInObjectRangeCheck(WorldObject const& obj, uint32 entry, uint32 spellId, bool alive, float range) + : i_obj(obj), i_entry(entry), i_spellId(spellId), i_alive(alive), i_range(range) { } + + bool operator()(Creature* u) + { + if (u->getDeathState() != 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; + } + + private: + WorldObject const& i_obj; + uint32 i_entry; + uint32 i_spellId; + bool i_alive; + float i_range; + + // prevent clone this object + NearestCreatureEntryWithLiveStateAndAuraInObjectRangeCheck(NearestCreatureEntryWithLiveStateAndAuraInObjectRangeCheck const&) = delete; + }; + class AnyPlayerInObjectRangeCheck { public: -- cgit v1.2.3