OregonCore  revision 3611e8a-git
Your Favourite TBC server
ObjectAccessor Class Reference

#include <ObjectAccessor.h>

+ Inheritance diagram for ObjectAccessor:

Public Types

typedef UNORDERED_MAP< uint64, Corpse * > Player2CorpsesMapType
 
typedef UNORDERED_MAP< Player *, UpdateData >::value_type UpdateDataValueType
 
typedef ACE_Thread_Mutex LockType
 
typedef Oregon::GeneralLock< LockTypeGuard
 

Public Member Functions

PlayerFindPlayerByName (const char *name, bool force=false)
 
PlayerFindPlayerByAccountId (uint64 Id, bool force=false)
 
HashMapHolder< Player >::MapType & GetPlayers ()
 
template<class T >
void AddObject (T *object)
 
template<class T >
void RemoveObject (T *object)
 
void RemoveObject (Player *pl)
 
void SaveAllPlayers ()
 
void AddUpdateObject (Object *obj)
 
void RemoveUpdateObject (Object *obj)
 
void Update (uint32 diff)
 
CorpseGetCorpseForPlayerGUID (uint64 guid)
 
void RemoveCorpse (Corpse *corpse)
 
void AddCorpse (Corpse *corpse)
 
void AddCorpsesToGrid (GridCoord const &gridpair, GridType &grid, Map *map)
 
CorpseConvertCorpseForPlayer (uint64 player_guid, bool insignia=false)
 
void RemoveOldCorpses ()
 

Static Public Member Functions

template<class T >
static T * GetObjectInWorld (uint64 guid, T *)
 
static PlayerGetObjectInWorld (uint64 guid, Player *)
 
static UnitGetObjectInWorld (uint64 guid, Unit *)
 
template<class T >
static T * GetObjectInMap (uint64 guid, Map *map, T *)
 
template<class T >
static T * GetObjectInWorld (uint32 mapid, float x, float y, uint64 guid, T *)
 
static WorldObjectGetWorldObject (WorldObject const &, uint64)
 
static ObjectGetObjectByTypeMask (WorldObject const &, uint64, uint32 typemask)
 
static CorpseGetCorpse (WorldObject const &u, uint64 guid)
 
static GameObjectGetGameObject (WorldObject const &u, uint64 guid)
 
static DynamicObjectGetDynamicObject (WorldObject const &u, uint64 guid)
 
static UnitGetUnit (WorldObject const &, uint64 guid)
 
static CreatureGetCreature (WorldObject const &u, uint64 guid)
 
static PetGetPet (WorldObject const &, uint64 guid)
 
static PlayerGetPlayer (WorldObject const &, uint64 guid)
 
static CreatureGetCreatureOrPet (WorldObject const &, uint64)
 
static PetFindPet (uint64)
 
static PlayerFindPlayer (uint64, bool force=false)
 
static UnitFindUnit (uint64)
 
static HashMapHolder< Creature >::MapType const & GetCreatures ()
 
static HashMapHolder< GameObject >::MapType const & GetGameObjects ()
 
- Static Public Member Functions inherited from Oregon::Singleton< ObjectAccessor, Oregon::ClassLevelLockable< ObjectAccessor, ACE_Thread_Mutex > >
static ObjectAccessorInstance ()
 

Private Member Functions

 ObjectAccessor ()
 
 ~ObjectAccessor ()
 
 ObjectAccessor (const ObjectAccessor &)
 
ObjectAccessoroperator= (const ObjectAccessor &)
 
void _update ()
 

Static Private Member Functions

static void _buildChangeObjectForPlayer (WorldObject *, UpdateDataMapType &)
 
static void _buildPacket (Player *, Object *, UpdateDataMapType &)
 

Private Attributes

Player2CorpsesMapType i_player2corpse
 
std::set< Object * > i_objects
 
LockType i_updateGuard
 
LockType i_corpseGuard
 

Friends

class Oregon::OperatorNew< ObjectAccessor >
 

Additional Inherited Members

- Protected Member Functions inherited from Oregon::Singleton< ObjectAccessor, Oregon::ClassLevelLockable< ObjectAccessor, ACE_Thread_Mutex > >
 Singleton ()
 

Detailed Description

Definition at line 90 of file ObjectAccessor.h.

Member Typedef Documentation

typedef ACE_Thread_Mutex ObjectAccessor::LockType

Definition at line 245 of file ObjectAccessor.h.

Definition at line 101 of file ObjectAccessor.h.

Constructor & Destructor Documentation

ObjectAccessor::ObjectAccessor ( )
private

Definition at line 37 of file ObjectAccessor.cpp.

38 {
39 }
ObjectAccessor::~ObjectAccessor ( )
private

Definition at line 41 of file ObjectAccessor.cpp.

References i_player2corpse.

42 {
43  for (Player2CorpsesMapType::const_iterator itr = i_player2corpse.begin(); itr != i_player2corpse.end(); ++itr)
44  {
45  itr->second->RemoveFromWorld();
46  delete itr->second;
47  }
48 }
Player2CorpsesMapType i_player2corpse
ObjectAccessor::ObjectAccessor ( const ObjectAccessor )
private

Member Function Documentation

static void ObjectAccessor::_buildChangeObjectForPlayer ( WorldObject ,
UpdateDataMapType  
)
staticprivate
static void ObjectAccessor::_buildPacket ( Player ,
Object ,
UpdateDataMapType  
)
staticprivate
void ObjectAccessor::_update ( )
private
void ObjectAccessor::AddCorpse ( Corpse corpse)

Definition at line 246 of file ObjectAccessor.cpp.

References ASSERT, Oregon::ComputeCellCoord(), CORPSE_BONES, CoordPair< LIMIT >::GetId(), WorldObject::GetInstanceId(), WorldLocation::GetMapId(), Corpse::GetOwnerGUID(), Position::GetPositionX(), Position::GetPositionY(), Corpse::GetType(), GUID_LOPART, i_corpseGuard, i_player2corpse, and sObjectMgr.

Referenced by Player::CreateCorpse(), and ObjectMgr::LoadCorpses().

247 {
248  ASSERT(corpse && corpse->GetType() != CORPSE_BONES);
249 
250  // Critical section
251  {
252  Guard guard(i_corpseGuard);
253 
254  ASSERT(i_player2corpse.find(corpse->GetOwnerGUID()) == i_player2corpse.end());
255  i_player2corpse[corpse->GetOwnerGUID()] = corpse;
256 
257  // build mapid*cellid -> guid_set map
258  CellCoord cellCoord = Oregon::ComputeCellCoord(corpse->GetPositionX(), corpse->GetPositionY());
259  sObjectMgr.AddCorpseCellData(corpse->GetMapId(), cellCoord.GetId(), GUID_LOPART(corpse->GetOwnerGUID()), corpse->GetInstanceId());
260  }
261 }
#define GUID_LOPART(x)
Definition: ObjectGuid.h:110
#define sObjectMgr
Definition: ObjectMgr.h:1285
Player2CorpsesMapType i_player2corpse
CorpseType GetType() const
Definition: Corpse.h:79
float GetPositionY() const
Definition: Position.h:98
uint32 GetInstanceId() const
Definition: Object.h:682
uint32 GetMapId() const
Definition: Object.h:585
CellCoord ComputeCellCoord(float x, float y)
Definition: GridDefines.h:167
LockType i_corpseGuard
uint64 const & GetOwnerGUID() const
Definition: Corpse.h:66
Oregon::GeneralLock< LockType > Guard
#define ASSERT
Definition: Errors.h:33
float GetPositionX() const
Definition: Position.h:97
uint32 GetId() const
Definition: GridDefines.h:136
void ObjectAccessor::AddCorpsesToGrid ( GridCoord const &  gridpair,
GridType grid,
Map map 
)

Definition at line 263 of file ObjectAccessor.cpp.

References Grid< ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES >::AddWorldObject(), Map::GetInstanceId(), i_corpseGuard, i_player2corpse, and Map::Instanceable().

Referenced by Map::EnsureGridLoaded().

264 {
265  Guard guard(i_corpseGuard);
266 
267  for (Player2CorpsesMapType::iterator iter = i_player2corpse.begin(); iter != i_player2corpse.end(); ++iter)
268  {
269  if (iter->second->IsInGrid())
270  {
271  //TODO: add this assert later
272  //ASSERT(iter->second->GetGridCoord() == gridpair);
273  continue;
274  }
275 
276  if (iter->second->GetGridCoord() == gridpair)
277  {
278  // verify, if the corpse in our instance (add only corpses which are)
279  if (map->Instanceable())
280  {
281  if (iter->second->GetInstanceId() == map->GetInstanceId())
282  grid.AddWorldObject(iter->second);
283  }
284  else
285  grid.AddWorldObject(iter->second);
286  }
287  }
288 }
Player2CorpsesMapType i_player2corpse
LockType i_corpseGuard
Oregon::GeneralLock< LockType > Guard
bool Instanceable() const
Definition: Map.h:422
uint32 GetInstanceId() const
Definition: Map.h:390
void AddWorldObject(SPECIFIC_OBJECT *obj)
Definition: Grid.h:58
template<class T >
void ObjectAccessor::AddObject ( T *  object)
inline
Corpse * ObjectAccessor::ConvertCorpseForPlayer ( uint64  player_guid,
bool  insignia = false 
)
Todo:
: Units die in various ways, for example blood elf woman lies left (-90°) but undead woman lies to the front - so we need to gather some info in order to modify corpseO properly to fit the model.

Definition at line 290 of file ObjectAccessor.cpp.

References Map::AddToMap(), CONFIG_DEATH_BONES_BG_OR_ARENA, CONFIG_DEATH_BONES_WORLD, CORPSE_END, CORPSE_FIELD_FLAGS, CORPSE_FIELD_ITEM, CORPSE_FIELD_OWNER, CORPSE_FLAG_BONES, CORPSE_FLAG_UNK2, Corpse::Create(), DEBUG_LOG, Corpse::DeleteFromDB(), EQUIPMENT_SLOT_END, WorldObject::FindMap(), GetCorpseForPlayerGUID(), Corpse::GetGridCoord(), Object::GetGUIDLow(), Position::GetOrientation(), Position::GetPositionX(), Position::GetPositionY(), Position::GetPositionZ(), Object::GetUInt32Value(), Map::IsBattlegroundOrArena(), Map::IsRemovalGrid(), Position::Relocate(), RemoveCorpse(), Corpse::SetGridCoord(), Object::SetUInt32Value(), Object::SetUInt64Value(), and sWorld.

Referenced by Player::DeleteFromDB(), ChatHandler::HandleReviveCommand(), Player::LoadCorpse(), Player::RemovedInsignia(), RemoveOldCorpses(), Battleground::RemovePlayerAtLeave(), and Battleground::Update().

291 {
292  Corpse* corpse = GetCorpseForPlayerGUID(player_guid);
293  if (!corpse)
294  {
295  //in fact this function is called from several places
296  //even when player doesn't have a corpse, not an error
297  //sLog.outError("Try remove corpse that not in map for GUID %ul", player_guid);
298  return NULL;
299  }
300 
301  float corpseX = corpse->GetPositionX();
302  float corpseY = corpse->GetPositionY();
303  float corpseZ = corpse->GetPositionZ();
304  float corpseO = corpse->GetOrientation();
305 
309 
310  DEBUG_LOG("Deleting Corpse and spawned bones.");
311 
312  Map* map = corpse->FindMap();
313 
314  // remove corpse from player_guid -> corpse map
315  RemoveCorpse(corpse);
316 
317  // remove corpse from DB
318  corpse->DeleteFromDB();
319 
320  Corpse* bones = NULL;
321  // create the bones only if the map and the grid is loaded at the corpse's location
322  // ignore bones creating option in case insignia
323  if (map && (insignia ||
325  !map->IsRemovalGrid(corpse->GetPositionX(), corpse->GetPositionY()))
326  {
327  // Create bones, don't change Corpse
328  bones = new Corpse;
329  bones->Create(corpse->GetGUIDLow(), map);
330 
331  for (int i = 3; i < CORPSE_END; ++i) // don't overwrite guid and object type
332  bones->SetUInt32Value(i, corpse->GetUInt32Value(i));
333 
334  bones->SetGridCoord(corpse->GetGridCoord());
335  // bones->m_time = m_time; // don't overwrite time
336  // bones->m_inWorld = m_inWorld; // don't overwrite in-world state
337  // bones->m_type = m_type; // don't overwrite type
338  bones->Relocate(corpseX, corpseY, corpseZ, corpseO);
339 
342 
343  for (int i = 0; i < EQUIPMENT_SLOT_END; ++i)
344  {
345  if (corpse->GetUInt32Value(CORPSE_FIELD_ITEM + i))
346  bones->SetUInt32Value(CORPSE_FIELD_ITEM + i, 0);
347  }
348 
349  // add bones in grid store if grid loaded where corpse placed
350  map->AddToMap(bones);
351  }
352 
353  // all references to the corpse should be removed at this point
354  delete corpse;
355 
356  return bones;
357 }
bool IsBattlegroundOrArena() const
Definition: Map.h:447
bool AddToMap(T *)
Definition: Map.cpp:424
Definition: Corpse.h:48
void RemoveCorpse(Corpse *corpse)
void DeleteFromDB()
Definition: Corpse.cpp:148
const uint32 & GetUInt32Value(uint16 index) const
Definition: Object.h:228
void SetUInt32Value(uint16 index, uint32 value)
Definition: Object.cpp:779
uint32 GetGUIDLow() const
Definition: Object.h:160
float GetOrientation() const
Definition: Position.h:100
void Relocate(float x, float y)
Definition: Position.h:65
bool Create(uint32 guidlow, Map *map)
Definition: Corpse.cpp:64
Map * FindMap() const
Definition: Object.h:830
float GetPositionY() const
Definition: Position.h:98
float GetPositionZ() const
Definition: Position.h:99
#define DEBUG_LOG(...)
Definition: Log.h:194
Definition: Map.h:266
void SetUInt64Value(uint16 index, const uint64 &value)
Definition: Object.cpp:798
Corpse * GetCorpseForPlayerGUID(uint64 guid)
GridCoord const & GetGridCoord() const
Definition: Corpse.h:84
#define sWorld
Definition: World.h:860
bool IsRemovalGrid(float x, float y) const
Definition: Map.h:301
float GetPositionX() const
Definition: Position.h:97
void SetGridCoord(GridCoord const &grid)
Definition: Corpse.h:88
Pet * ObjectAccessor::FindPet ( uint64  guid)
static

Definition at line 149 of file ObjectAccessor.cpp.

References GetObjectInWorld().

Referenced by WorldSession::HandlePetRename().

150 {
151  return GetObjectInWorld(guid, (Pet*)NULL);
152 }
static T * GetObjectInWorld(uint64 guid, T *)
Definition: Pet.h:146
Player * ObjectAccessor::FindPlayer ( uint64  guid,
bool  force = false 
)
static

Definition at line 154 of file ObjectAccessor.cpp.

References HashMapHolder< T >::GetContainer(), and GetObjectInWorld().

Referenced by Battleground::_CheckSafePositions(), Guild::BroadcastPacket(), Guild::BroadcastPacketToRank(), SocialMgr::BroadcastToFriendListers(), Guild::BroadcastToGuild(), Guild::BroadcastToOfficers(), Battleground::BroadcastWorker(), Player::DeleteFromDB(), Guild::DisplayGuildBankContentUpdate(), Spell::FillTargetMap(), SocialMgr::GetFriendInfo(), Creature::GetLootRecipient(), ObjectMgr::GetPlayer(), ChatHandler::getSelectedPlayerOrSelf(), WorldSession::HandleAddFriendOpcodeCallBack(), WorldSession::HandleArenaTeamRemoveFromTeamOpcode(), WorldSession::HandleInitiateTradeOpcode(), WorldSession::HandleInspectArenaStatsOpcode(), WorldSession::HandleLootMasterGiveOpcode(), WorldSession::HandleOfferPetitionOpcode(), WorldSession::HandlePetSpellAutocastOpcode(), WorldSession::HandleQuestConfirmAccept(), WorldSession::HandleQuestgiverAcceptQuestOpcode(), WorldSession::HandleQuestPushResult(), Unit::Kill(), Guild::LoadPlayerStatsByGuid(), Loot::NotifyItemRemoved(), Loot::NotifyMoneyRemoved(), Loot::NotifyQuestItemRemoved(), Oregon::CannibalizeObjectCheck::operator()(), Guild::Roster(), Oregon::VisibleNotifier::SendToSelf(), Group::UpdateLooterGuid(), GameObject::Use(), and WorldObjectChangeAccumulator::Visit().

155 {
156  if (!force)
157  return GetObjectInWorld(guid, (Player*)NULL);
158 
160 
162  for (HashMapHolder<Player>::MapType::iterator iter = m.begin(); iter != m.end(); ++iter)
163  if (iter->second->GetGUID() == guid)
164  return iter->second;
165 
166  return NULL;
167 }
static MapType & GetContainer()
UNORDERED_MAP< uint64, T * > MapType
static T * GetObjectInWorld(uint64 guid, T *)
Oregon::GeneralLock< LockType > Guard
Definition: Player.h:922
Player * ObjectAccessor::FindPlayerByAccountId ( uint64  Id,
bool  force = false 
)

Definition at line 186 of file ObjectAccessor.cpp.

References HashMapHolder< T >::GetContainer().

Referenced by ObjectMgr::GetRAFLinkedBuddyForPlayer().

187 {
190  for (HashMapHolder<Player>::MapType::iterator iter = m.begin(); iter != m.end(); ++iter)
191  if (iter->second->GetSession()->GetAccountId() == Id && (iter->second->IsInWorld() || force))
192  return iter->second;
193 
194  return NULL;
195 }
static MapType & GetContainer()
UNORDERED_MAP< uint64, T * > MapType
Oregon::GeneralLock< LockType > Guard
Player * ObjectAccessor::FindPlayerByName ( const char *  name,
bool  force = false 
)

Definition at line 174 of file ObjectAccessor.cpp.

References HashMapHolder< T >::GetContainer().

Referenced by ObjectMgr::GetPlayer(), WorldSession::HandleArenaTeamAddMemberOpcode(), ChatHandler::HandleGuildCreateCommand(), and WorldSession::HandleGuildInviteOpcode().

175 {
177 
179  for (HashMapHolder<Player>::MapType::iterator iter = m.begin(); iter != m.end(); ++iter)
180  if (!strcmp(name, iter->second->GetName()) && (iter->second->IsInWorld() || force))
181  return iter->second;
182 
183  return NULL;
184 }
static MapType & GetContainer()
UNORDERED_MAP< uint64, T * > MapType
Oregon::GeneralLock< LockType > Guard
Unit * ObjectAccessor::FindUnit ( uint64  guid)
static

Definition at line 169 of file ObjectAccessor.cpp.

References GetObjectInWorld().

Referenced by Spell::DoAllEffectOnTarget(), and SmartScript::GetLastInvoker().

170 {
171  return GetObjectInWorld(guid, (Unit*)NULL);
172 }
static T * GetObjectInWorld(uint64 guid, T *)
Definition: Unit.h:884
Corpse * ObjectAccessor::GetCorpse ( WorldObject const &  u,
uint64  guid 
)
static
Corpse * ObjectAccessor::GetCorpseForPlayerGUID ( uint64  guid)

Definition at line 205 of file ObjectAccessor.cpp.

References ASSERT, CORPSE_BONES, i_corpseGuard, and i_player2corpse.

Referenced by ConvertCorpseForPlayer(), Player::GetCorpse(), and LoadHelper().

206 {
207  Guard guard(i_corpseGuard);
208 
209  Player2CorpsesMapType::iterator iter = i_player2corpse.find(guid);
210  if (iter == i_player2corpse.end())
211  return NULL;
212 
213  ASSERT(iter->second->GetType() != CORPSE_BONES);
214 
215  return iter->second;
216 }
Player2CorpsesMapType i_player2corpse
LockType i_corpseGuard
Oregon::GeneralLock< LockType > Guard
#define ASSERT
Definition: Errors.h:33
Creature * ObjectAccessor::GetCreature ( WorldObject const &  u,
uint64  guid 
)
static

Definition at line 123 of file ObjectAccessor.cpp.

References WorldObject::GetMap(), and GetObjectInMap().

Referenced by Spell::cast(), GetCreatureOrPet(), GetObjectByTypeMask(), and GetWorldObject().

124 {
125  return GetObjectInMap(guid, u.GetMap(), (Creature*)NULL);
126 }
static T * GetObjectInMap(uint64 guid, Map *map, T *)
Creature * ObjectAccessor::GetCreatureOrPet ( WorldObject const &  u,
uint64  guid 
)
static

Definition at line 138 of file ObjectAccessor.cpp.

References GetCreature(), GetPet(), IS_CREATURE_GUID, and IS_PET_GUID.

Referenced by Spell::EffectSummonType(), Unit::GetFirstMinion(), Unit::GetGuardianPet(), ChatHandler::getSelectedCreature(), WorldSession::HandlePetAbandon(), WorldSession::HandlePetCancelAuraOpcode(), WorldSession::HandlePetSpellAutocastOpcode(), WorldSession::HandleSpellClick(), and WorldSession::SendPetNameQuery().

139 {
140  if (IS_PET_GUID(guid))
141  return GetPet(u, guid);
142 
143  if (IS_CREATURE_GUID(guid))
144  return GetCreature(u, guid);
145 
146  return NULL;
147 }
#define IS_PET_GUID(Guid)
Definition: ObjectGuid.h:67
#define IS_CREATURE_GUID(Guid)
Definition: ObjectGuid.h:66
static Creature * GetCreature(WorldObject const &u, uint64 guid)
static Pet * GetPet(WorldObject const &, uint64 guid)
static HashMapHolder<Creature>::MapType const& ObjectAccessor::GetCreatures ( )
inlinestatic

Definition at line 195 of file ObjectAccessor.h.

References HashMapHolder< T >::GetContainer().

Referenced by GameEventMgr::RunSmartAIScripts().

196  {
198  }
static MapType & GetContainer()
DynamicObject * ObjectAccessor::GetDynamicObject ( WorldObject const &  u,
uint64  guid 
)
static

Definition at line 113 of file ObjectAccessor.cpp.

References WorldObject::GetMap(), and GetObjectInMap().

Referenced by GetObjectByTypeMask(), and GetWorldObject().

114 {
115  return GetObjectInMap(guid, u.GetMap(), (DynamicObject*)NULL);
116 }
static T * GetObjectInMap(uint64 guid, Map *map, T *)
GameObject * ObjectAccessor::GetGameObject ( WorldObject const &  u,
uint64  guid 
)
static

Definition at line 108 of file ObjectAccessor.cpp.

References WorldObject::GetMap(), and GetObjectInMap().

Referenced by GetObjectByTypeMask(), and GetWorldObject().

109 {
110  return GetObjectInMap(guid, u.GetMap(), (GameObject*)NULL);
111 }
static T * GetObjectInMap(uint64 guid, Map *map, T *)
static HashMapHolder<GameObject>::MapType const& ObjectAccessor::GetGameObjects ( )
inlinestatic

Definition at line 201 of file ObjectAccessor.h.

References HashMapHolder< T >::GetContainer().

Referenced by GameEventMgr::RunSmartAIScripts().

202  {
204  }
static MapType & GetContainer()
Object * ObjectAccessor::GetObjectByTypeMask ( WorldObject const &  p,
uint64  guid,
uint32  typemask 
)
static

Definition at line 66 of file ObjectAccessor.cpp.

References GetCreature(), GetDynamicObject(), GetGameObject(), GetPet(), GetPlayer(), Object::GetTypeId(), GUID_HIPART, HIGHGUID_CORPSE, HIGHGUID_DYNAMICOBJECT, HIGHGUID_GAMEOBJECT, HIGHGUID_ITEM, HIGHGUID_MO_TRANSPORT, HIGHGUID_PET, HIGHGUID_PLAYER, HIGHGUID_TRANSPORT, HIGHGUID_UNIT, TYPEID_PLAYER, TYPEMASK_DYNAMICOBJECT, TYPEMASK_GAMEOBJECT, TYPEMASK_ITEM, TYPEMASK_PLAYER, and TYPEMASK_UNIT.

Referenced by Player::GetViewpoint(), WorldSession::HandleQuestgiverAcceptQuestOpcode(), WorldSession::HandleQuestgiverChooseRewardOpcode(), WorldSession::HandleQuestgiverQuestQueryOpcode(), WorldSession::HandleQuestgiverRequestRewardOpcode(), and WorldSession::HandleQuestgiverStatusQueryOpcode().

67 {
68  switch (GUID_HIPART(guid))
69  {
70  case HIGHGUID_ITEM:
71  if (typemask & TYPEMASK_ITEM && p.GetTypeId() == TYPEID_PLAYER)
72  return ((Player const&)p).GetItemByGuid(guid);
73  break;
74  case HIGHGUID_PLAYER:
75  if (typemask & TYPEMASK_PLAYER)
76  return GetPlayer(p, guid);
77  break;
79  if (typemask & TYPEMASK_GAMEOBJECT)
80  return GetGameObject(p, guid);
81  break;
82  case HIGHGUID_UNIT:
83  if (typemask & TYPEMASK_UNIT)
84  return GetCreature(p, guid);
85  break;
86  case HIGHGUID_PET:
87  if (typemask & TYPEMASK_UNIT)
88  return GetPet(p, guid);
89  break;
91  if (typemask & TYPEMASK_DYNAMICOBJECT)
92  return GetDynamicObject(p, guid);
93  break;
94  case HIGHGUID_TRANSPORT:
95  case HIGHGUID_CORPSE:
97  break;
98  }
99 
100  return NULL;
101 }
static DynamicObject * GetDynamicObject(WorldObject const &u, uint64 guid)
#define GUID_HIPART(x)
Definition: ObjectGuid.h:82
static Player * GetPlayer(WorldObject const &, uint64 guid)
static Creature * GetCreature(WorldObject const &u, uint64 guid)
static Pet * GetPet(WorldObject const &, uint64 guid)
static GameObject * GetGameObject(WorldObject const &u, uint64 guid)
Definition: Player.h:922
template<class T >
static T* ObjectAccessor::GetObjectInMap ( uint64  guid,
Map map,
T *   
)
inlinestatic

Definition at line 130 of file ObjectAccessor.h.

Referenced by GetCorpse(), GetCreature(), Map::GetCreature(), GetDynamicObject(), Map::GetDynamicObject(), GetGameObject(), Map::GetGameObject(), GetPet(), GetPlayer(), and GetUnit().

131  {
132  assert(map);
133  if (T* obj = GetObjectInWorld(guid, (T*)NULL))
134  if (obj->GetMap() == map)
135  return obj;
136  return NULL;
137  }
static T * GetObjectInWorld(uint64 guid, T *)
template<class T >
static T* ObjectAccessor::GetObjectInWorld ( uint64  guid,
T *   
)
inlinestatic
static Player* ObjectAccessor::GetObjectInWorld ( uint64  guid,
Player  
)
inlinestatic

Definition at line 110 of file ObjectAccessor.h.

References HashMapHolder< T >::Find(), and Object::IsInWorld().

111  {
112  Player* player = HashMapHolder<Player>::Find(guid);
113  if (player && player->IsInWorld())
114  return player;
115  return NULL;
116  }
static T * Find(uint64 guid)
const bool & IsInWorld() const
Definition: Object.h:129
Definition: Player.h:922
static Unit* ObjectAccessor::GetObjectInWorld ( uint64  guid,
Unit  
)
inlinestatic

Definition at line 118 of file ObjectAccessor.h.

References IS_PET_GUID, and IS_PLAYER_GUID.

119  {
120  if (IS_PLAYER_GUID(guid))
121  return (Unit*)GetObjectInWorld(guid, (Player*)NULL);
122 
123  if (IS_PET_GUID(guid))
124  return (Unit*)GetObjectInWorld(guid, (Pet*)NULL);
125 
126  return (Unit*)GetObjectInWorld(guid, (Creature*)NULL);
127  }
#define IS_PET_GUID(Guid)
Definition: ObjectGuid.h:67
#define IS_PLAYER_GUID(Guid)
Definition: ObjectGuid.h:69
static T * GetObjectInWorld(uint64 guid, T *)
Definition: Unit.h:884
Definition: Player.h:922
Definition: Pet.h:146
template<class T >
static T* ObjectAccessor::GetObjectInWorld ( uint32  mapid,
float  x,
float  y,
uint64  guid,
T *   
)
inlinestatic

Definition at line 139 of file ObjectAccessor.h.

References Oregon::ComputeCellCoord(), HashMapHolder< T >::Find(), sLog, TOTAL_NUMBER_OF_CELLS_PER_MAP, CoordPair< LIMIT >::x_coord, and CoordPair< LIMIT >::y_coord.

140  {
141  T* obj = HashMapHolder<T>::Find(guid);
142  if (!obj || obj->GetMapId() != mapid)
143  return NULL;
144 
147  {
148  sLog.outError("ObjectAccessor::GetObjectInWorld: invalid coordinates supplied X:%f Y:%f grid cell [%u:%u]", x, y, p.x_coord, p.y_coord);
149  return NULL;
150  }
151 
152  CellCoord q = Oregon::ComputeCellCoord(obj->GetPositionX(), obj->GetPositionY());
154  {
155  sLog.outError("ObjectAccessor::GetObjecInWorld: object (GUID: %u TypeId: %u) has invalid coordinates X:%f Y:%f grid cell [%u:%u]", obj->GetGUIDLow(), obj->GetTypeId(), obj->GetPositionX(), obj->GetPositionY(), q.x_coord, q.y_coord);
156  return NULL;
157  }
158 
159  int32 dx = int32(p.x_coord) - int32(q.x_coord);
160  int32 dy = int32(p.y_coord) - int32(q.y_coord);
161 
162  if (dx > -2 && dx < 2 && dy > -2 && dy < 2)
163  return obj;
164  else
165  return NULL;
166  }
#define sLog
Log class singleton.
Definition: Log.h:187
ACE_INT32 int32
Definition: Define.h:67
static T * Find(uint64 guid)
uint32 y_coord
Definition: GridDefines.h:142
uint32 x_coord
Definition: GridDefines.h:141
#define TOTAL_NUMBER_OF_CELLS_PER_MAP
Definition: GridDefines.h:49
CellCoord ComputeCellCoord(float x, float y)
Definition: GridDefines.h:167
Pet * ObjectAccessor::GetPet ( WorldObject const &  u,
uint64  guid 
)
static

Definition at line 128 of file ObjectAccessor.cpp.

References WorldObject::GetMap(), and GetObjectInMap().

Referenced by GetCreatureOrPet(), GetObjectByTypeMask(), Player::GetPet(), and GetWorldObject().

129 {
130  return GetObjectInMap(guid, u.GetMap(), (Pet*)NULL);
131 }
static T * GetObjectInMap(uint64 guid, Map *map, T *)
Definition: Pet.h:146
Player * ObjectAccessor::GetPlayer ( WorldObject const &  u,
uint64  guid 
)
static

Definition at line 133 of file ObjectAccessor.cpp.

References WorldObject::GetMap(), and GetObjectInMap().

Referenced by Unit::GetCharmerOrOwnerPlayerOrPlayerItself(), GetObjectByTypeMask(), Unit::GetPlayer(), Player::GetSelectedPlayer(), GetWorldObject(), SmartAI::StopFollow(), and GameObject::Update().

134 {
135  return GetObjectInMap(guid, u.GetMap(), (Player*)NULL);
136 }
static T * GetObjectInMap(uint64 guid, Map *map, T *)
Definition: Player.h:922
HashMapHolder<Player>::MapType& ObjectAccessor::GetPlayers ( )
inline
Unit * ObjectAccessor::GetUnit ( WorldObject const &  u,
uint64  guid 
)
static

Definition at line 118 of file ObjectAccessor.cpp.

References WorldObject::GetMap(), and GetObjectInMap().

Referenced by FleeingMovementGenerator< T >::_getPoint(), Player::AddComboPoints(), Spell::AddUnitTarget(), Spell::CalculateDamageDoneForAllTargets(), Spell::CalculateHitResults(), Spell::cancel(), GameObject::CleanupsBeforeDelete(), Player::ClearComboPoints(), Spell::DelayedChannel(), Spell::DoAllEffectOnTarget(), GuardAI::EnterEvadeMode(), SmartAI::EnterEvadeMode(), Spell::FillTargetMap(), DynamicObject::GetCaster(), Unit::GetCharm(), Unit::GetCharmer(), Unit::GetFirstControlled(), GameObject::GetOwner(), Unit::GetOwner(), ChatHandler::getSelectedUnit(), Player::GetSelectedUnit(), TempSummon::GetSummoner(), SmartScript::GetTargets(), Aura::GetTriggerTarget(), Unit::GetUnit(), WorldSession::HandleAttackSwingOpcode(), Aura::HandleAuraRetainComboPoints(), ChatHandler::HandleDelObjectCommand(), WorldSession::HandlePetAction(), WorldSession::HandlePetActionHelper(), WorldSession::HandlePetCastSpellOpcode(), WorldSession::HandlePetSetAction(), WorldSession::HandleSetActiveMoverOpcode(), WorldSession::HandleSetTargetOpcode(), WorldSession::HandleTextEmoteOpcode(), Spell::HandleThreatSpells(), Spell::IsAliveUnitPresentInTargetList(), SmartAI::OnCharmed(), SmartScript::ProcessAction(), Player::SendComboPoints(), Unit::SetFeared(), Spell::SetTargetMap(), Spell::Spell(), SpellCastTargets::Update(), Spell::update(), Creature::Update(), PetAI::UpdateAI(), TotemAI::UpdateAI(), HostileReference::updateOnlineStatus(), and Spell::UpdatePointers().

119 {
120  return GetObjectInMap(guid, u.GetMap(), (Unit*)NULL);
121 }
static T * GetObjectInMap(uint64 guid, Map *map, T *)
Definition: Unit.h:884
WorldObject * ObjectAccessor::GetWorldObject ( WorldObject const &  p,
uint64  guid 
)
static

Definition at line 50 of file ObjectAccessor.cpp.

References GetCorpse(), GetCreature(), GetDynamicObject(), GetGameObject(), GetPet(), GetPlayer(), GUID_HIPART, HIGHGUID_CORPSE, HIGHGUID_DYNAMICOBJECT, HIGHGUID_GAMEOBJECT, HIGHGUID_MO_TRANSPORT, HIGHGUID_PET, HIGHGUID_PLAYER, HIGHGUID_TRANSPORT, and HIGHGUID_UNIT.

Referenced by ObjectGuidList::GetObjectList().

51 {
52  switch (GUID_HIPART(guid))
53  {
54  case HIGHGUID_PLAYER: return GetPlayer(p, guid);
55  case HIGHGUID_TRANSPORT:
57  case HIGHGUID_GAMEOBJECT: return GetGameObject(p, guid);
58  case HIGHGUID_UNIT: return GetCreature(p, guid);
59  case HIGHGUID_PET: return GetPet(p, guid);
60  case HIGHGUID_DYNAMICOBJECT: return GetDynamicObject(p, guid);
61  case HIGHGUID_CORPSE: return GetCorpse(p, guid);
62  default: return NULL;
63  }
64 }
static DynamicObject * GetDynamicObject(WorldObject const &u, uint64 guid)
#define GUID_HIPART(x)
Definition: ObjectGuid.h:82
static Player * GetPlayer(WorldObject const &, uint64 guid)
static Creature * GetCreature(WorldObject const &u, uint64 guid)
static Pet * GetPet(WorldObject const &, uint64 guid)
static GameObject * GetGameObject(WorldObject const &u, uint64 guid)
static Corpse * GetCorpse(WorldObject const &u, uint64 guid)
ObjectAccessor& ObjectAccessor::operator= ( const ObjectAccessor )
private
void ObjectAccessor::RemoveCorpse ( Corpse corpse)

Definition at line 218 of file ObjectAccessor.cpp.

References ASSERT, Oregon::ComputeCellCoord(), CORPSE_BONES, WorldObject::DestroyForNearbyPlayers(), WorldObject::FindMap(), CoordPair< LIMIT >::GetId(), WorldLocation::GetMapId(), Corpse::GetOwnerGUID(), Position::GetPositionX(), Position::GetPositionY(), Corpse::GetType(), GUID_LOPART, i_corpseGuard, i_player2corpse, Map::RemoveFromMap(), Corpse::RemoveFromWorld(), and sObjectMgr.

Referenced by ConvertCorpseForPlayer().

219 {
220  ASSERT(corpse && corpse->GetType() != CORPSE_BONES);
221 
222  if (corpse->FindMap())
223  {
224  corpse->DestroyForNearbyPlayers();
225  corpse->FindMap()->RemoveFromMap(corpse, false);
226  }
227  else
228  corpse->RemoveFromWorld();
229 
230  // Critical section
231  {
232  Guard guard(i_corpseGuard);
233 
234  Player2CorpsesMapType::iterator iter = i_player2corpse.find(corpse->GetOwnerGUID());
235  if (iter == i_player2corpse.end())
236  return;
237 
238  // build mapid*cellid -> guid_set map
239  CellCoord cellCoord = Oregon::ComputeCellCoord(corpse->GetPositionX(), corpse->GetPositionY());
240  sObjectMgr.DeleteCorpseCellData(corpse->GetMapId(), cellCoord.GetId(), GUID_LOPART(corpse->GetOwnerGUID()));
241 
242  i_player2corpse.erase(iter);
243  }
244 }
#define GUID_LOPART(x)
Definition: ObjectGuid.h:110
void RemoveFromWorld() override
Definition: Corpse.cpp:55
void RemoveFromMap(T *, bool)
Definition: Map.cpp:688
#define sObjectMgr
Definition: ObjectMgr.h:1285
Player2CorpsesMapType i_player2corpse
CorpseType GetType() const
Definition: Corpse.h:79
Map * FindMap() const
Definition: Object.h:830
float GetPositionY() const
Definition: Position.h:98
uint32 GetMapId() const
Definition: Object.h:585
CellCoord ComputeCellCoord(float x, float y)
Definition: GridDefines.h:167
LockType i_corpseGuard
uint64 const & GetOwnerGUID() const
Definition: Corpse.h:66
Oregon::GeneralLock< LockType > Guard
#define ASSERT
Definition: Errors.h:33
void DestroyForNearbyPlayers()
Definition: Object.cpp:2554
float GetPositionX() const
Definition: Position.h:97
uint32 GetId() const
Definition: GridDefines.h:136
void ObjectAccessor::RemoveObject ( Player pl)
inline

Definition at line 216 of file ObjectAccessor.h.

References HashMapHolder< T >::Remove().

217  {
220  }
Definition: Object.h:124
void RemoveUpdateObject(Object *obj)
static void Remove(T *o)
void ObjectAccessor::RemoveOldCorpses ( )

Definition at line 359 of file ObjectAccessor.cpp.

References ConvertCorpseForPlayer(), and i_player2corpse.

Referenced by ChatHandler::HandleServerCorpsesCommand(), and World::Update().

360 {
361  time_t now = time(NULL);
362  Player2CorpsesMapType::iterator next;
363  for (Player2CorpsesMapType::iterator itr = i_player2corpse.begin(); itr != i_player2corpse.end(); itr = next)
364  {
365  next = itr;
366  ++next;
367 
368  if (!itr->second->IsExpired(now))
369  continue;
370 
371  ConvertCorpseForPlayer(itr->first);
372  }
373 }
Player2CorpsesMapType i_player2corpse
Corpse * ConvertCorpseForPlayer(uint64 player_guid, bool insignia=false)
void ObjectAccessor::RemoveUpdateObject ( Object obj)
inline

Definition at line 230 of file ObjectAccessor.h.

Referenced by Object::ClearUpdateMask().

231  {
232  Guard guard(i_updateGuard);
233  i_objects.erase(obj);
234  }
std::set< Object * > i_objects
Oregon::GeneralLock< LockType > Guard
LockType i_updateGuard
void ObjectAccessor::SaveAllPlayers ( )

Definition at line 197 of file ObjectAccessor.cpp.

References HashMapHolder< T >::GetContainer().

Referenced by World::_UpdateGameTime(), ChatHandler::HandleSaveAllCommand(), and Master::Run().

198 {
201  for (HashMapHolder<Player>::MapType::iterator itr = m.begin(); itr != m.end(); ++itr)
202  itr->second->SaveToDB();
203 }
static MapType & GetContainer()
UNORDERED_MAP< uint64, T * > MapType
Oregon::GeneralLock< LockType > Guard
void ObjectAccessor::Update ( uint32  diff)

Definition at line 375 of file ObjectAccessor.cpp.

References ASSERT, Object::BuildUpdate(), ByteBuffer::clear(), i_objects, i_updateGuard, and Object::IsInWorld().

Referenced by MapManager::Update().

376 {
377  UpdateDataMapType update_players;
378 
379  // Critical section
380  {
381  Guard guard(i_updateGuard);
382 
383  while (!i_objects.empty())
384  {
385  Object* obj = *i_objects.begin();
386  ASSERT(obj && obj->IsInWorld());
387  i_objects.erase(i_objects.begin());
388  obj->BuildUpdate(update_players);
389  }
390  }
391 
392  WorldPacket packet; // here we allocate a std::vector with a size of 0x10000
393  for (UpdateDataMapType::iterator iter = update_players.begin(); iter != update_players.end(); ++iter)
394  {
395  iter->second.BuildPacket(&packet);
396  iter->first->GetSession()->SendPacket(&packet);
397  packet.clear(); // clean the string
398  }
399 }
Definition: Object.h:124
std::set< Object * > i_objects
virtual void BuildUpdate(UpdateDataMapType &)
Definition: Object.h:380
const bool & IsInWorld() const
Definition: Object.h:129
UNORDERED_MAP< Player *, UpdateData > UpdateDataMapType
Definition: Object.h:120
Oregon::GeneralLock< LockType > Guard
LockType i_updateGuard
#define ASSERT
Definition: Errors.h:33
void clear()
Definition: ByteBuffer.h:73

Friends And Related Function Documentation

friend class Oregon::OperatorNew< ObjectAccessor >
friend

Definition at line 92 of file ObjectAccessor.h.

Member Data Documentation

LockType ObjectAccessor::i_corpseGuard
private
std::set<Object*> ObjectAccessor::i_objects
private

Definition at line 256 of file ObjectAccessor.h.

Referenced by Update().

Player2CorpsesMapType ObjectAccessor::i_player2corpse
private
LockType ObjectAccessor::i_updateGuard
private

Definition at line 258 of file ObjectAccessor.h.

Referenced by Update().


The documentation for this class was generated from the following files: