TrinityCore
ObjectAccessor.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef TRINITY_OBJECTACCESSOR_H
19#define TRINITY_OBJECTACCESSOR_H
20
21#include "ObjectGuid.h"
22#include <shared_mutex>
23#include <unordered_map>
24
25class AreaTrigger;
26class Conversation;
27class Corpse;
28class Creature;
29class DynamicObject;
30class GameObject;
31class Map;
32class Object;
33class Pet;
34class Player;
35class SceneObject;
36class Transport;
37class Unit;
38class WorldObject;
39
40template <class T>
42{
43 //Non instanceable only static
45
46public:
47
48 typedef std::unordered_map<ObjectGuid, T*> MapType;
49
50 static void Insert(T* o);
51
52 static void Remove(T* o);
53
54 static T* Find(ObjectGuid guid);
55
56 static MapType& GetContainer();
57
58 static std::shared_mutex* GetLock();
59};
60
62{
63 // these functions return objects only if in map of specified object
66 TC_GAME_API Corpse* GetCorpse(WorldObject const& u, ObjectGuid const& guid);
73 TC_GAME_API Unit* GetUnit(WorldObject const&, ObjectGuid const& guid);
75 TC_GAME_API Pet* GetPet(WorldObject const&, ObjectGuid const& guid);
76 TC_GAME_API Player* GetPlayer(Map const*, ObjectGuid const& guid);
79
80 // these functions return objects if found in whole world
81 // ACCESS LIKE THAT IS NOT THREAD SAFE
83 TC_GAME_API Player* FindPlayerByName(std::string_view name);
85
86 // this returns Player even if he is not in world, for example teleporting
88 TC_GAME_API Player* FindConnectedPlayerByName(std::string_view name);
89
90 // when using this, you must use the hashmapholder's lock
92
93 template<class T>
94 void AddObject(T* object)
95 {
97 }
98
99 template<class T>
100 void RemoveObject(T* object)
101 {
103 }
104
105 template<>
106 void AddObject(Player* player);
107
108 template<>
109 void RemoveObject(Player* player);
110
112};
113
114#endif
#define TC_GAME_API
Definition: Define.h:123
uint32_t uint32
Definition: Define.h:142
Definition: Corpse.h:53
static void Remove(T *o)
std::unordered_map< ObjectGuid, T * > MapType
static void Insert(T *o)
Definition: Map.h:189
uint64 LowType
Definition: ObjectGuid.h:278
Definition: Object.h:150
Definition: Pet.h:40
Definition: Unit.h:627
TC_GAME_API WorldObject * GetWorldObject(WorldObject const &, ObjectGuid const &)
TC_GAME_API Player * FindPlayerByName(std::string_view name)
TC_GAME_API void SaveAllPlayers()
TC_GAME_API Player * FindPlayerByLowGUID(ObjectGuid::LowType lowguid)
TC_GAME_API Unit * GetUnit(WorldObject const &, ObjectGuid const &guid)
TC_GAME_API Player * FindConnectedPlayerByName(std::string_view name)
void AddObject(T *object)
TC_GAME_API GameObject * GetGameObject(WorldObject const &u, ObjectGuid const &guid)
TC_GAME_API Transport * GetTransport(WorldObject const &u, ObjectGuid const &guid)
TC_GAME_API Object * GetObjectByTypeMask(WorldObject const &, ObjectGuid const &, uint32 typemask)
TC_GAME_API AreaTrigger * GetAreaTrigger(WorldObject const &u, ObjectGuid const &guid)
TC_GAME_API Player * FindPlayer(ObjectGuid const &)
TC_GAME_API Player * GetPlayer(Map const *, ObjectGuid const &guid)
TC_GAME_API HashMapHolder< Player >::MapType const & GetPlayers()
TC_GAME_API Creature * GetCreature(WorldObject const &u, ObjectGuid const &guid)
TC_GAME_API DynamicObject * GetDynamicObject(WorldObject const &u, ObjectGuid const &guid)
TC_GAME_API Player * FindConnectedPlayer(ObjectGuid const &)
TC_GAME_API Pet * GetPet(WorldObject const &, ObjectGuid const &guid)
void RemoveObject(T *object)
TC_GAME_API Corpse * GetCorpse(WorldObject const &u, ObjectGuid const &guid)
TC_GAME_API Creature * GetCreatureOrPetOrVehicle(WorldObject const &, ObjectGuid const &)
TC_GAME_API Conversation * GetConversation(WorldObject const &u, ObjectGuid const &guid)
TC_GAME_API SceneObject * GetSceneObject(WorldObject const &u, ObjectGuid const &guid)
void Insert(Player *p)
Player * Find(std::string_view name)
void Remove(VignetteData &vignette, WorldObject const *owner)
Definition: Vignette.cpp:100