mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-20 01:15:35 +01:00
Core/Objects: Method to get nearest GO of type X, FindNearestGameObjectOfType
Thanks Subv for the idea
This commit is contained in:
@@ -2537,6 +2537,15 @@ GameObject* WorldObject::FindNearestGameObject(uint32 entry, float range) const
|
||||
return go;
|
||||
}
|
||||
|
||||
GameObject* WorldObject::FindNearestGameObjectOfType(GameobjectTypes type, float range) const
|
||||
{
|
||||
GameObject* go = NULL;
|
||||
Trinity::NearestGameObjectTypeInObjectRangeCheck checker(*this, type, range);
|
||||
Trinity::GameObjectLastSearcher<Trinity::NearestGameObjectTypeInObjectRangeCheck> searcher(this, go, checker);
|
||||
VisitNearbyGridObject(range, searcher);
|
||||
return go;
|
||||
}
|
||||
|
||||
void WorldObject::GetGameObjectListWithEntryInGrid(std::list<GameObject*>& gameobjectList, uint32 entry, float maxSearchRange) const
|
||||
{
|
||||
CellCoord pair(Trinity::ComputeCellCoord(this->GetPositionX(), this->GetPositionY()));
|
||||
|
||||
@@ -799,6 +799,7 @@ class WorldObject : public Object, public WorldLocation
|
||||
|
||||
Creature* FindNearestCreature(uint32 entry, float range, bool alive = true) const;
|
||||
GameObject* FindNearestGameObject(uint32 entry, float range) const;
|
||||
GameObject* FindNearestGameObjectOfType(GameobjectTypes type, float range) const;
|
||||
|
||||
void GetGameObjectListWithEntryInGrid(std::list<GameObject*>& lList, uint32 uiEntry, float fMaxSearchRange) const;
|
||||
void GetCreatureListWithEntryInGrid(std::list<Creature*>& lList, uint32 uiEntry, float fMaxSearchRange) const;
|
||||
|
||||
@@ -694,6 +694,30 @@ namespace Trinity
|
||||
NearestGameObjectEntryInObjectRangeCheck(NearestGameObjectEntryInObjectRangeCheck const&);
|
||||
};
|
||||
|
||||
// Success at unit in range, range update for next check (this can be use with GameobjectLastSearcher to find nearest GO with a certain type)
|
||||
class NearestGameObjectTypeInObjectRangeCheck
|
||||
{
|
||||
public:
|
||||
NearestGameObjectTypeInObjectRangeCheck(WorldObject const& obj, GameobjectTypes type, float range) : i_obj(obj), i_type(type), i_range(range) {}
|
||||
bool operator()(GameObject* go)
|
||||
{
|
||||
if (go->GetGoType() == i_type && 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;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
float GetLastRange() const { return i_range; }
|
||||
private:
|
||||
WorldObject const& i_obj;
|
||||
GameobjectTypes i_type;
|
||||
float i_range;
|
||||
|
||||
// prevent clone this object
|
||||
NearestGameObjectTypeInObjectRangeCheck(NearestGameObjectTypeInObjectRangeCheck const&);
|
||||
};
|
||||
|
||||
class GameObjectWithDbGUIDCheck
|
||||
{
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user