Core/Object: Implement FindNearestCreatureWithAura (#28410)

* Game/Object: Implement NearestCreatureEntryWithLiveStateAndAuraInObjectRangeCheck class and FindNearestCreatureWithAura method

* moved arguments

(cherry picked from commit 9a3e29d416)
This commit is contained in:
Teleqraph
2022-10-30 22:29:03 +01:00
committed by Shauren
parent b502bc4683
commit 762a32cb65
3 changed files with 43 additions and 0 deletions

View File

@@ -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<Trinity::NearestCreatureEntryWithLiveStateAndAuraInObjectRangeCheck> searcher(this, creature, checker);
Cell::VisitAllObjects(this, searcher, range);
return creature;
}
GameObject* WorldObject::FindNearestGameObject(uint32 entry, float range, bool spawnedOnly) const
{
GameObject* go = nullptr;

View File

@@ -426,6 +426,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;
GameObject* FindNearestGameObject(uint32 entry, float range, bool spawnedOnly = true) const;
GameObject* FindNearestUnspawnedGameObject(uint32 entry, float range) const;
GameObject* FindNearestGameObjectOfType(GameobjectTypes type, float range) const;

View File

@@ -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: