mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-13 09:17:18 +00:00
feat(Core/ObjectAccessor): Helper to access creature/object by DB GUID (#14802)
This commit is contained in:
@@ -282,6 +282,58 @@ Player* ObjectAccessor::FindPlayerByName(std::string const& name, bool checkInWo
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get a spawned creature by DB `guid` column. MODULE USAGE ONLY - USE IT FOR CUSTOM CONTENT.
|
||||
*
|
||||
* @param uint32 mapId The map id where the creature is spawned.
|
||||
* @param uint64 guid Database guid of the creature we are accessing.
|
||||
*/
|
||||
Creature* ObjectAccessor::GetSpawnedCreatureByDBGUID(uint32 mapId, uint64 guid)
|
||||
{
|
||||
if (Map* map = sMapMgr->FindBaseMap(mapId))
|
||||
{
|
||||
auto bounds = map->GetCreatureBySpawnIdStore().equal_range(guid);
|
||||
|
||||
if (bounds.first == bounds.second)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (Creature* creature = bounds.first->second)
|
||||
{
|
||||
return creature;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get a spawned gameobject by DB `guid` column. MODULE USAGE ONLY - USE IT FOR CUSTOM CONTENT.
|
||||
*
|
||||
* @param uint32 mapId The map id where the gameobject is spawned.
|
||||
* @param uint64 guid Database guid of the gameobject we are accessing.
|
||||
*/
|
||||
GameObject* ObjectAccessor::GetSpawnedGameObjectByDBGUID(uint32 mapId, uint64 guid)
|
||||
{
|
||||
if (Map* map = sMapMgr->FindBaseMap(mapId))
|
||||
{
|
||||
auto bounds = map->GetGameObjectBySpawnIdStore().equal_range(guid);
|
||||
|
||||
if (bounds.first == bounds.second)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (GameObject* go = bounds.first->second)
|
||||
{
|
||||
return go;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template<>
|
||||
void ObjectAccessor::AddObject(Player* player)
|
||||
{
|
||||
|
||||
@@ -83,6 +83,8 @@ namespace ObjectAccessor
|
||||
Player* FindPlayerByLowGUID(ObjectGuid::LowType lowguid);
|
||||
Player* FindConnectedPlayer(ObjectGuid const guid);
|
||||
Player* FindPlayerByName(std::string const& name, bool checkInWorld = true);
|
||||
Creature* GetSpawnedCreatureByDBGUID(uint32 mapId, uint64 guid);
|
||||
GameObject* GetSpawnedGameObjectByDBGUID(uint32 mapId, uint64 guid);
|
||||
|
||||
// when using this, you must use the hashmapholder's lock
|
||||
HashMapHolder<Player>::MapType const& GetPlayers();
|
||||
|
||||
Reference in New Issue
Block a user