diff options
author | Seyden <saiifii@live.de> | 2022-12-26 20:13:13 +0100 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2024-10-05 17:11:15 +0200 |
commit | da7367208ca5967ee48310643243cdd66f36f248 (patch) | |
tree | a5dedc0f09555b325239aa7639ceb48669235e8d /src | |
parent | 762a32cb65ea7cd9d802f9621e701afce9709303 (diff) |
Core/Objects: Implement FindNearestCreatureWithOptions helper function (#28488)
Co-authored-by: Shauren <shauren.trinity@gmail.com>
(cherry picked from commit 9ab0679781ba65bc278203ee01d1169114c64033)
Diffstat (limited to 'src')
-rw-r--r-- | src/server/game/Entities/Object/Object.cpp | 9 | ||||
-rw-r--r-- | src/server/game/Entities/Object/Object.h | 45 | ||||
-rw-r--r-- | src/server/game/Grids/Notifiers/GridNotifiers.h | 67 |
3 files changed, 94 insertions, 27 deletions
diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp index b944d94a666..fa78ef07700 100644 --- a/src/server/game/Entities/Object/Object.cpp +++ b/src/server/game/Entities/Object/Object.cpp @@ -2126,11 +2126,14 @@ Creature* WorldObject::FindNearestCreature(uint32 entry, float range, bool alive return creature; } -Creature* WorldObject::FindNearestCreatureWithAura(uint32 entry, uint32 spellId, float range, bool alive) const +Creature* WorldObject::FindNearestCreatureWithOptions(float range, FindCreatureOptions const& options) const { Creature* creature = nullptr; - Trinity::NearestCreatureEntryWithLiveStateAndAuraInObjectRangeCheck checker(*this, entry, spellId, alive, range); - Trinity::CreatureLastSearcher<Trinity::NearestCreatureEntryWithLiveStateAndAuraInObjectRangeCheck> searcher(this, creature, checker); + Trinity::NearestCreatureEntryWithOptionsInObjectRangeCheck checker(*this, range, options); + Trinity::CreatureLastSearcher<Trinity::NearestCreatureEntryWithOptionsInObjectRangeCheck> searcher(this, creature, checker); + if (options.IgnorePhases) + searcher.i_phaseMask = PHASEMASK_ANYWHERE; + Cell::VisitAllObjects(this, searcher, range); return creature; } diff --git a/src/server/game/Entities/Object/Object.h b/src/server/game/Entities/Object/Object.h index ac9a4dae5ee..0974aab5fa0 100644 --- a/src/server/game/Entities/Object/Object.h +++ b/src/server/game/Entities/Object/Object.h @@ -296,6 +296,49 @@ class FlaggedValuesArray32 T_FLAGS m_flags; }; +struct FindCreatureOptions +{ + FindCreatureOptions() = default; + + FindCreatureOptions& SetCreatureId(uint32 creatureId) { CreatureId = creatureId; return *this; } + + FindCreatureOptions& SetIsAlive(bool isAlive) { IsAlive = isAlive; return *this; } + FindCreatureOptions& SetIsInCombat(bool isInCombat) { IsInCombat = isInCombat; return *this; } + FindCreatureOptions& SetIsSummon(bool isSummon) { IsSummon = isSummon; return *this; } + + FindCreatureOptions& SetIgnorePhases(bool ignorePhases) { IgnorePhases = ignorePhases; return *this; } + FindCreatureOptions& SetIgnoreNotOwnedPrivateObjects(bool ignoreNotOwnedPrivateObjects) { IgnoreNotOwnedPrivateObjects = ignoreNotOwnedPrivateObjects; return *this; } + FindCreatureOptions& SetIgnorePrivateObjects(bool ignorePrivateObjects) { IgnorePrivateObjects = ignorePrivateObjects; return *this; } + + FindCreatureOptions& SetHasAura(uint32 spellId) { AuraSpellId = spellId; return *this; } + FindCreatureOptions& SetOwner(ObjectGuid ownerGuid) { OwnerGuid = ownerGuid; return *this; } + FindCreatureOptions& SetCharmer(ObjectGuid charmerGuid) { CharmerGuid = charmerGuid; return *this; } + FindCreatureOptions& SetCreator(ObjectGuid creatorGuid) { CreatorGuid = creatorGuid; return *this; } + FindCreatureOptions& SetPrivateObjectOwner(ObjectGuid privateObjectOwnerGuid) { PrivateObjectOwnerGuid = privateObjectOwnerGuid; return *this; } + + Optional<uint32> CreatureId; + + Optional<bool> IsAlive; + Optional<bool> IsInCombat; + Optional<bool> IsSummon; + + bool IgnorePhases; + bool IgnoreNotOwnedPrivateObjects; + bool IgnorePrivateObjects; + + Optional<uint32> AuraSpellId; + Optional<ObjectGuid> OwnerGuid; + Optional<ObjectGuid> CharmerGuid; + Optional<ObjectGuid> CreatorGuid; + Optional<ObjectGuid> PrivateObjectOwnerGuid; + + FindCreatureOptions(FindCreatureOptions const&) = delete; + FindCreatureOptions(FindCreatureOptions&&) = delete; + + FindCreatureOptions& operator=(FindCreatureOptions const&) = delete; + FindCreatureOptions& operator=(FindCreatureOptions&&) = delete; +}; + class TC_GAME_API WorldObject : public Object, public WorldLocation { protected: @@ -426,7 +469,7 @@ class TC_GAME_API WorldObject : public Object, public WorldLocation void SummonCreatureGroup(uint8 group, std::list<TempSummon*>* list = nullptr); Creature* FindNearestCreature(uint32 entry, float range, bool alive = true) const; - Creature* FindNearestCreatureWithAura(uint32 entry, uint32 spellId, float range, bool alive = true) const; + Creature* FindNearestCreatureWithOptions(float range, FindCreatureOptions const& options) 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 ef473e63e9d..1f676016b3c 100644 --- a/src/server/game/Grids/Notifiers/GridNotifiers.h +++ b/src/server/game/Grids/Notifiers/GridNotifiers.h @@ -1398,37 +1398,58 @@ namespace Trinity NearestCreatureEntryWithLiveStateInObjectRangeCheck(NearestCreatureEntryWithLiveStateInObjectRangeCheck const&) = delete; }; - class NearestCreatureEntryWithLiveStateAndAuraInObjectRangeCheck + class NearestCreatureEntryWithOptionsInObjectRangeCheck { 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) { } + NearestCreatureEntryWithOptionsInObjectRangeCheck(WorldObject const& obj, float range, FindCreatureOptions const& args) + : i_obj(obj), i_args(args), 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)) + bool operator()(Creature* u) { + if (u->getDeathState() == DEAD) // Despawned + return false; + + if (u->GetGUID() == i_obj.GetGUID()) + return false; + + if (!i_obj.IsWithinDistInMap(u, i_range)) + return false; + + if (i_args.CreatureId && u->GetEntry() != i_args.CreatureId) + return false; + + if (i_args.IsAlive.has_value() && u->IsAlive() != i_args.IsAlive) + return false; + + if (i_args.IsSummon.has_value() && u->IsSummon() != i_args.IsSummon) + return false; + + if (i_args.IsInCombat.has_value() && u->IsInCombat() != i_args.IsInCombat) + return false; + + if ((i_args.OwnerGuid && u->GetOwnerGUID() != i_args.OwnerGuid) + || (i_args.CharmerGuid && u->GetCharmerGUID() != i_args.CharmerGuid) + || (i_args.CreatorGuid && u->GetCreatorGUID() != i_args.CreatorGuid) + || (i_args.PrivateObjectOwnerGuid && u->GetPrivateObjectOwner() != i_args.PrivateObjectOwnerGuid)) + return false; + + if (i_args.IgnorePrivateObjects && u->IsPrivateObject()) + return false; + + if (i_args.IgnoreNotOwnedPrivateObjects && !u->CheckPrivateObjectOwnerVisibility(&i_obj)) + return false; + + if (i_args.AuraSpellId && !u->HasAura(*i_args.AuraSpellId)) + return false; + 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; + private: + WorldObject const& i_obj; + FindCreatureOptions const& i_args; + float i_range; }; class AnyPlayerInObjectRangeCheck |