mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-03-15 21:45:12 +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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user