feat(Core/ObjectAccessor): Helper to access creature/object by DB GUID (#14802)
This commit is contained in:
parent
7338fc22e0
commit
c12d56f2d1
2 changed files with 54 additions and 0 deletions
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue