From 430157f71d8a90da0a376efa33fc0cc53c327d21 Mon Sep 17 00:00:00 2001 From: acidmanifesto Date: Wed, 13 Oct 2021 10:32:01 -0400 Subject: feat(Core): GetDeadCreatureListInGrid helper added, for aoe loot (#8445) --- src/server/game/AI/ScriptedAI/ScriptedCreature.cpp | 5 +++++ src/server/game/AI/ScriptedAI/ScriptedCreature.h | 1 + src/server/game/Entities/Object/Object.cpp | 7 +++++++ src/server/game/Entities/Object/Object.h | 1 + src/server/game/Grids/Notifiers/GridNotifiers.h | 24 ++++++++++++++++++++++ 5 files changed, 38 insertions(+) (limited to 'src') diff --git a/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp b/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp index fa77c2fa9b..277f91bc50 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp +++ b/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp @@ -714,3 +714,8 @@ void GetGameObjectListWithEntryInGrid(std::list& list, WorldObject* { source->GetGameObjectListWithEntryInGrid(list, entry, maxSearchRange); } + + void GetDeadCreatureListInGrid(std::list& list, WorldObject* source, float maxSearchRange, bool alive /*= false*/) +{ + source->GetDeadCreatureListInGrid(list, maxSearchRange, alive); +} diff --git a/src/server/game/AI/ScriptedAI/ScriptedCreature.h b/src/server/game/AI/ScriptedAI/ScriptedCreature.h index 2b1fe9ae64..6e12ea01a7 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedCreature.h +++ b/src/server/game/AI/ScriptedAI/ScriptedCreature.h @@ -505,5 +505,6 @@ Creature* GetClosestCreatureWithEntry(WorldObject* source, uint32 entry, float m GameObject* GetClosestGameObjectWithEntry(WorldObject* source, uint32 entry, float maxSearchRange); void GetCreatureListWithEntryInGrid(std::list& list, WorldObject* source, uint32 entry, float maxSearchRange); void GetGameObjectListWithEntryInGrid(std::list& list, WorldObject* source, uint32 entry, float maxSearchRange); +void GetDeadCreatureListInGrid(std::list& list, WorldObject* source, float maxSearchRange, bool alive = false); #endif // SCRIPTEDCREATURE_H_ diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp index d20cce0fd4..a53d9618bf 100644 --- a/src/server/game/Entities/Object/Object.cpp +++ b/src/server/game/Entities/Object/Object.cpp @@ -2503,6 +2503,13 @@ void WorldObject::GetCreatureListWithEntryInGrid(std::list& creatureL Cell::VisitGridObjects(this, searcher, maxSearchRange); } +void WorldObject::GetDeadCreatureListInGrid(std::list& creaturedeadList, float maxSearchRange, bool alive /*= false*/) const +{ + Acore::AllDeadCreaturesInRange check(this, maxSearchRange, alive); + Acore::CreatureListSearcher searcher(this, creaturedeadList, check); + Cell::VisitGridObjects(this, searcher, maxSearchRange); +} + /* namespace Acore { diff --git a/src/server/game/Entities/Object/Object.h b/src/server/game/Entities/Object/Object.h index 881820a0b2..a620651f95 100644 --- a/src/server/game/Entities/Object/Object.h +++ b/src/server/game/Entities/Object/Object.h @@ -1007,6 +1007,7 @@ public: [[nodiscard]] Player* SelectNearestPlayer(float distance = 0) const; void GetGameObjectListWithEntryInGrid(std::list& lList, uint32 uiEntry, float fMaxSearchRange) const; void GetCreatureListWithEntryInGrid(std::list& lList, uint32 uiEntry, float fMaxSearchRange) const; + void GetDeadCreatureListInGrid(std::list& lList, float maxSearchRange, bool alive = false) const; void DestroyForNearbyPlayers(); virtual void UpdateObjectVisibility(bool forced = true, bool fromUpdate = false); diff --git a/src/server/game/Grids/Notifiers/GridNotifiers.h b/src/server/game/Grids/Notifiers/GridNotifiers.h index 384d380472..44cdee243b 100644 --- a/src/server/game/Grids/Notifiers/GridNotifiers.h +++ b/src/server/game/Grids/Notifiers/GridNotifiers.h @@ -1327,6 +1327,30 @@ namespace Acore float m_fRange; }; + class AllDeadCreaturesInRange + { + public: + AllDeadCreaturesInRange(WorldObject const* obj, float range, bool reqAlive = true) : _obj(obj), _range(range), _reqAlive(reqAlive) {} + + bool operator()(Unit* unit) const + { + if (_reqAlive && unit->IsAlive()) + { + return false; + } + if (!_obj->IsWithinDistInMap(unit, _range)) + { + return false; + } + return true; + } + + private: + WorldObject const* _obj; + float _range; + bool _reqAlive; + }; + class PlayerAtMinimumRangeAway { public: -- cgit v1.2.3