ObjectAccessor rewrite

- ObjectAccessor now hides it's inner locks
  - Introduced C++11 lambdas; from now on, VS2012 and any non C++11 compiler are not supported anymore
This commit is contained in:
H0zen 2018-03-29 14:39:32 +03:00
parent 04e1b8b7d4
commit d014ca2599
39 changed files with 206 additions and 224 deletions

View File

@ -199,7 +199,7 @@ template<class Do>
void BattleGround::BroadcastWorker(Do& _do)
{
for (BattleGroundPlayerMap::const_iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
if (Player* plr = ObjectAccessor::FindPlayer(itr->first))
if (Player* plr = sObjectAccessor.FindPlayer(itr->first))
{ _do(plr); }
}

View File

@ -169,19 +169,12 @@ bool ChatHandler::HandleSaveCommand(char* /*args*/)
bool ChatHandler::HandleGMListIngameCommand(char* /*args*/)
{
std::list< std::pair<std::string, bool> > names;
{
ACE_READ_GUARD_RETURN(HashMapHolder<Player>::LockType, g, HashMapHolder<Player>::GetLock(), true)
HashMapHolder<Player>::MapType& m = sObjectAccessor.GetPlayers();
for (HashMapHolder<Player>::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr)
{
Player* player = itr->second;
sObjectAccessor.DoForAllPlayers([&names, this](Player *player){
AccountTypes security = player->GetSession()->GetSecurity();
if ((player->isGameMaster() || (security > SEC_PLAYER && security <= (AccountTypes)sWorld.getConfig(CONFIG_UINT32_GM_LEVEL_IN_GM_LIST))) &&
(!m_session || player->IsVisibleGloballyFor(m_session->GetPlayer())))
{ names.push_back(std::make_pair<std::string, bool>(GetNameLink(player), player->isAcceptWhispers())); }
}
}
});
if (!names.empty())
{

View File

@ -897,7 +897,7 @@ bool ChatHandler::HandleGameObjectDeleteCommand(char* args)
if (ObjectGuid ownerGuid = obj->GetOwnerGuid())
{
Unit* owner = ObjectAccessor::GetUnit(*m_session->GetPlayer(), ownerGuid);
Unit* owner = sObjectAccessor.GetUnit(*m_session->GetPlayer(), ownerGuid);
if (!owner || !ownerGuid.IsPlayer())
{
PSendSysMessage(LANG_COMMAND_DELOBJREFERCREATURE, obj->GetGUIDLow(), ownerGuid.GetString().c_str());
@ -2157,7 +2157,7 @@ bool ChatHandler::HandleNpcNameCommand(char* /*args*/)
return true;
}
Creature* pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid);
Creature* pCreature = sObjectAccessor.GetCreature(*m_session->GetPlayer(), guid);
if (!pCreature)
{
@ -2204,7 +2204,7 @@ bool ChatHandler::HandleNpcSubNameCommand(char* /*args*/)
return true;
}
Creature* pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid);
Creature* pCreature = sObjectAccessor.GetCreature(*m_session->GetPlayer(), guid);
if (!pCreature)
{

View File

@ -3803,7 +3803,7 @@ bool ChatHandler::HandleNpcAddWeaponCommand(char* /*args*/)
return true;
}
Creature *pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid);
Creature *pCreature = sObjectAccessor.GetCreature(*m_session->GetPlayer(), guid);
if(!pCreature)
{
@ -4609,10 +4609,7 @@ bool ChatHandler::HandleResetAllCommand(char* args)
}
CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE (at_login & '%u') = '0'", atLogin, atLogin);
HashMapHolder<Player>::MapType const& plist = sObjectAccessor.GetPlayers();
for (HashMapHolder<Player>::MapType::const_iterator itr = plist.begin(); itr != plist.end(); ++itr)
{ itr->second->SetAtLoginFlag(atLogin); }
sObjectAccessor.DoForAllPlayers([&atLogin](Player* plr){ plr->SetAtLoginFlag(atLogin); });
return true;
}

View File

@ -71,7 +71,7 @@ template<class T>
bool FleeingMovementGenerator<T>::_getPoint(T& owner, float& x, float& y, float& z)
{
float dist_from_caster, angle_to_caster;
if (Unit* fright = ObjectAccessor::GetUnit(owner, i_frightGuid))
if (Unit* fright = sObjectAccessor.GetUnit(owner, i_frightGuid))
{
dist_from_caster = fright->GetDistance(&owner);
if (dist_from_caster > 0.2f)

View File

@ -1040,7 +1040,7 @@ void Creature::PrepareBodyLootState()
*/
Player* Creature::GetOriginalLootRecipient() const
{
return m_lootRecipientGuid ? ObjectAccessor::FindPlayer(m_lootRecipientGuid) : NULL;
return m_lootRecipientGuid ? sObjectAccessor.FindPlayer(m_lootRecipientGuid) : NULL;
}
/**

View File

@ -116,7 +116,7 @@ bool DynamicObject::Create(uint32 guidlow, Unit* caster, uint32 spellId, SpellEf
Unit* DynamicObject::GetCaster() const
{
// can be not found in some cases
return ObjectAccessor::GetUnit(*this, GetCasterGuid());
return sObjectAccessor.GetUnit(*this, GetCasterGuid());
}
void DynamicObject::Update(uint32 /*update_diff*/, uint32 p_time)

View File

@ -122,7 +122,7 @@ void GameObject::RemoveFromWorld()
// Remove GO from owner
if (ObjectGuid owner_guid = GetOwnerGuid())
{
if (Unit* owner = ObjectAccessor::GetUnit(*this, owner_guid))
if (Unit* owner = sObjectAccessor.GetUnit(*this, owner_guid))
{ owner->RemoveGameObject(this, false); }
else
{
@ -777,7 +777,7 @@ bool GameObject::IsTransport() const
Unit* GameObject::GetOwner() const
{
return ObjectAccessor::GetUnit(*this, GetOwnerGuid());
return sObjectAccessor.GetUnit(*this, GetOwnerGuid());
}
void GameObject::SaveRespawnTime()
@ -1945,7 +1945,7 @@ void GameObject::StopGroupLoot()
Player* GameObject::GetOriginalLootRecipient() const
{
return m_lootRecipientGuid ? ObjectAccessor::FindPlayer(m_lootRecipientGuid) : NULL;
return m_lootRecipientGuid ? sObjectAccessor.FindPlayer(m_lootRecipientGuid) : NULL;
}
Group* GameObject::GetGroupLootRecipient() const

View File

@ -604,7 +604,7 @@ void Guild::BroadcastToGuild(WorldSession* session, const std::string& msg, uint
for (MemberList::const_iterator itr = members.begin(); itr != members.end(); ++itr)
{
Player* pl = ObjectAccessor::FindPlayer(ObjectGuid(HIGHGUID_PLAYER, itr->first));
Player* pl = sObjectAccessor.FindPlayer(ObjectGuid(HIGHGUID_PLAYER, itr->first));
if (pl && pl->GetSession() && HasRankRight(pl->GetRank(), GR_RIGHT_GCHATLISTEN) && !pl->GetSocial()->HasIgnore(player->GetObjectGuid()))
{ pl->GetSession()->SendPacket(&data); }
@ -625,7 +625,7 @@ void Guild::BroadcastToOfficers(WorldSession* session, const std::string& msg, u
WorldPacket data;
ChatHandler::BuildChatPacket(data, CHAT_MSG_OFFICER, msg.c_str(), Language(language), player->GetChatTag(), player->GetObjectGuid(), player->GetName());
Player* pl = ObjectAccessor::FindPlayer(ObjectGuid(HIGHGUID_PLAYER, itr->first));
Player* pl = sObjectAccessor.FindPlayer(ObjectGuid(HIGHGUID_PLAYER, itr->first));
if (pl && pl->GetSession() && HasRankRight(pl->GetRank(), GR_RIGHT_OFFCHATLISTEN) && !pl->GetSocial()->HasIgnore(player->GetObjectGuid()))
{ pl->GetSession()->SendPacket(&data); }
@ -636,7 +636,7 @@ void Guild::BroadcastPacket(WorldPacket* packet)
{
for (MemberList::const_iterator itr = members.begin(); itr != members.end(); ++itr)
{
Player* player = ObjectAccessor::FindPlayer(ObjectGuid(HIGHGUID_PLAYER, itr->first));
Player* player = sObjectAccessor.FindPlayer(ObjectGuid(HIGHGUID_PLAYER, itr->first));
if (player)
{ player->GetSession()->SendPacket(packet); }
}
@ -648,7 +648,7 @@ void Guild::BroadcastPacketToRank(WorldPacket* packet, uint32 rankId)
{
if (itr->second.RankId == rankId)
{
Player* player = ObjectAccessor::FindPlayer(ObjectGuid(HIGHGUID_PLAYER, itr->first));
Player* player = sObjectAccessor.FindPlayer(ObjectGuid(HIGHGUID_PLAYER, itr->first));
if (player)
{ player->GetSession()->SendPacket(packet); }
}
@ -769,7 +769,7 @@ void Guild::Roster(WorldSession* session /*= NULL*/)
for (MemberList::const_iterator itr = members.begin(); itr != members.end(); ++itr)
{
if (Player* pl = ObjectAccessor::FindPlayer(ObjectGuid(HIGHGUID_PLAYER, itr->first)))
if (Player* pl = sObjectAccessor.FindPlayer(ObjectGuid(HIGHGUID_PLAYER, itr->first)))
{
data << pl->GetObjectGuid();
data << uint8(1);

View File

@ -254,7 +254,7 @@ class Guild
void BroadcastWorker(Do& _do, Player* except = NULL)
{
for (MemberList::iterator itr = members.begin(); itr != members.end(); ++itr)
if (Player* player = ObjectAccessor::FindPlayer(ObjectGuid(HIGHGUID_PLAYER, itr->first)))
if (Player* player = sObjectAccessor.FindPlayer(ObjectGuid(HIGHGUID_PLAYER, itr->first)))
if (player != except)
{ _do(player); }
}

View File

@ -641,7 +641,7 @@ void Loot::NotifyItemRemoved(uint8 lootIndex)
{
i_next = i;
++i_next;
if (Player* pl = ObjectAccessor::FindPlayer(*i))
if (Player* pl = sObjectAccessor.FindPlayer(*i))
{ pl->SendNotifyLootItemRemoved(lootIndex); }
else
{ m_playersLooting.erase(i); }
@ -656,7 +656,7 @@ void Loot::NotifyMoneyRemoved()
{
i_next = i;
++i_next;
if (Player* pl = ObjectAccessor::FindPlayer(*i))
if (Player* pl = sObjectAccessor.FindPlayer(*i))
{ pl->SendNotifyLootMoneyRemoved(); }
else
{ m_playersLooting.erase(i); }
@ -675,7 +675,7 @@ void Loot::NotifyQuestItemRemoved(uint8 questIndex)
{
i_next = i;
++i_next;
if (Player* pl = ObjectAccessor::FindPlayer(*i))
if (Player* pl = sObjectAccessor.FindPlayer(*i))
{
QuestItemMap::const_iterator pq = m_playerQuestItems.find(pl->GetGUIDLow());
if (pq != m_playerQuestItems.end() && pq->second)

View File

@ -34,11 +34,15 @@
#include "GridNotifiersImpl.h"
#include "ObjectGuid.h"
#include "World.h"
#define CLASS_LOCK MaNGOS::ClassLevelLockable<ObjectAccessor, ACE_Thread_Mutex>
INSTANTIATE_SINGLETON_2(ObjectAccessor, CLASS_LOCK);
INSTANTIATE_CLASS_MUTEX(ObjectAccessor, ACE_Thread_Mutex);
ObjectAccessor::ObjectAccessor() : i_playerGuard(), i_corpseGuard()
#include <algorithm>
#define CLASS_LOCK MaNGOS::ClassLevelLockable<ObjectAccessor, ACE_Recursive_Thread_Mutex>
INSTANTIATE_SINGLETON_2(ObjectAccessor, CLASS_LOCK);
INSTANTIATE_CLASS_MUTEX(ObjectAccessor, ACE_Recursive_Thread_Mutex);
ObjectAccessor::ObjectAccessor() : i_playerMap(), i_corpseMap(), i_corpseGuard()
{
}
@ -55,24 +59,24 @@ Unit*
ObjectAccessor::GetUnit(WorldObject const& u, ObjectGuid guid)
{
if (!guid)
{ return NULL; }
{ return nullptr; }
if (guid.IsPlayer())
{ return FindPlayer(guid); }
if (!u.IsInWorld())
{ return NULL; }
{ return nullptr; }
return u.GetMap()->GetAnyTypeCreature(guid);
}
Corpse* ObjectAccessor::GetCorpseInMap(ObjectGuid guid, uint32 mapid)
{
Corpse* ret = HashMapHolder<Corpse>::Find(guid);
Corpse* ret = i_corpseMap.Find(guid);
if (!ret)
{ return NULL; }
{ return nullptr; }
if (ret->GetMapId() != mapid)
{ return NULL; }
{ return nullptr; }
return ret;
}
@ -80,27 +84,26 @@ Corpse* ObjectAccessor::GetCorpseInMap(ObjectGuid guid, uint32 mapid)
Player* ObjectAccessor::FindPlayer(ObjectGuid guid, bool inWorld /*= true*/)
{
if (!guid)
{ return NULL; }
{ return nullptr; }
Player* plr = HashMapHolder<Player>::Find(guid);
Player* plr = i_playerMap.Find(guid);
if (!plr || (!plr->IsInWorld() && inWorld))
{ return NULL; }
{ return nullptr; }
return plr;
}
Player* ObjectAccessor::FindPlayerByName(const char* name)
{
ACE_READ_GUARD_RETURN(HashMapHolder<Player>::LockType, guard, HashMapHolder<Player>::GetLock(), NULL)
HashMapHolder<Player>::MapType& m = sObjectAccessor.GetPlayers();
for (HashMapHolder<Player>::MapType::iterator iter = m.begin(); iter != m.end(); ++iter)
if (iter->second->IsInWorld() && (::strcmp(name, iter->second->GetName()) == 0))
{ return iter->second; }
return NULL;
ACE_READ_GUARD_RETURN(HashMapHolder<Player>::LockType, guard, i_playerMap.GetLock(), nullptr)
for (auto& iter : i_playerMap.GetContainer())
if (iter.second->IsInWorld() && (::strcmp(name, iter.second->GetName()) == 0))
{ return iter.second; }
return nullptr;
}
void
ObjectAccessor::SaveAllPlayers()
//This method should not be here
void ObjectAccessor::SaveAllPlayers()
{
SessionMap const& smap = sWorld.GetAllSessions();
SessionMap::const_iterator iter;
@ -115,7 +118,7 @@ ObjectAccessor::SaveAllPlayers()
void ObjectAccessor::KickPlayer(ObjectGuid guid)
{
if (Player* p = ObjectAccessor::FindPlayer(guid, false))
if (Player* p = FindPlayer(guid, false))
{
WorldSession* s = p->GetSession();
s->KickPlayer(); // mark session to remove at next session list update
@ -126,12 +129,12 @@ void ObjectAccessor::KickPlayer(ObjectGuid guid)
Corpse*
ObjectAccessor::GetCorpseForPlayerGUID(ObjectGuid guid)
{
ACE_GUARD_RETURN(LockType, guard, i_corpseGuard, NULL)
ACE_GUARD_RETURN(LockType, guard, i_corpseGuard, nullptr)
Player2CorpsesMapType::iterator iter = i_player2corpse.find(guid);
if (iter == i_player2corpse.end())
{ return NULL; }
{ return nullptr; }
MANGOS_ASSERT(iter->second->GetType() != CORPSE_BONES);
return iter->second;
@ -207,7 +210,7 @@ ObjectAccessor::ConvertCorpseForPlayer(ObjectGuid player_guid, bool insignia)
// in fact this function is called from several places
// even when player doesn't have a corpse, not an error
// sLog.outError("Try remove corpse that not in map for GUID %ul", player_guid);
return NULL;
return nullptr;
}
DEBUG_LOG("Deleting Corpse and spawning bones.");
@ -224,7 +227,7 @@ ObjectAccessor::ConvertCorpseForPlayer(ObjectGuid player_guid, bool insignia)
// remove corpse from DB
corpse->DeleteFromDB();
Corpse* bones = NULL;
Corpse* bones = nullptr;
// create the bones only if the map and the grid is loaded at the corpse's location
// ignore bones creating option in case insignia
if (map && (insignia ||
@ -265,7 +268,7 @@ ObjectAccessor::ConvertCorpseForPlayer(ObjectGuid player_guid, bool insignia)
void ObjectAccessor::RemoveOldCorpses()
{
time_t now = time(NULL);
time_t now = time(nullptr);
Player2CorpsesMapType::iterator next;
for (Player2CorpsesMapType::iterator itr = i_player2corpse.begin(); itr != i_player2corpse.end(); itr = next)
{
@ -279,12 +282,10 @@ void ObjectAccessor::RemoveOldCorpses()
}
}
/// Define the static member of HashMapHolder
Corpse* ObjectAccessor::FindCorpse(ObjectGuid guid)
{
if (!guid)
{ return nullptr; }
template <class T> typename HashMapHolder<T>::MapType HashMapHolder<T>::m_objectMap;
template <class T> typename HashMapHolder<T>::LockType HashMapHolder<T>::i_lock;
/// Global definitions for the hashmap storage
template class HashMapHolder<Player>;
template class HashMapHolder<Corpse>;
return i_corpseMap.Find(guid);
}

View File

@ -28,63 +28,21 @@
#include "Common.h"
#include "Platform/Define.h"
#include "Policies/Singleton.h"
#include <ace/Thread_Mutex.h>
#include <ace/RW_Thread_Mutex.h>
#include "Utilities/UnorderedMapSet.h"
#include <ace/Recursive_Thread_Mutex.h>
#include "Policies/ThreadingModel.h"
#include "UpdateData.h"
#include "GridDefines.h"
#include "Object.h"
#include "Player.h"
#include "Corpse.h"
#include <unordered_map>
class Unit;
class WorldObject;
class Map;
template <class T>
class HashMapHolder
{
public:
typedef UNORDERED_MAP<ObjectGuid, T*> MapType;
typedef ACE_RW_Thread_Mutex LockType;
static void Insert(T* o)
{
ACE_WRITE_GUARD(LockType, guard, i_lock)
m_objectMap[o->GetObjectGuid()] = o;
}
static void Remove(T* o)
{
ACE_WRITE_GUARD(LockType, guard, i_lock)
m_objectMap.erase(o->GetObjectGuid());
}
static T* Find(ObjectGuid guid)
{
ACE_READ_GUARD_RETURN (LockType, guard, i_lock, NULL)
typename MapType::iterator itr = m_objectMap.find(guid);
return (itr != m_objectMap.end()) ? itr->second : NULL;
}
static MapType& GetContainer() { return m_objectMap; }
static LockType& GetLock() { return i_lock; }
private:
// Non instanceable only static
HashMapHolder() {}
static LockType i_lock;
static MapType m_objectMap;
};
class ObjectAccessor : public MaNGOS::Singleton<ObjectAccessor, MaNGOS::ClassLevelLockable<ObjectAccessor, ACE_Thread_Mutex> >
class ObjectAccessor : public MaNGOS::Singleton<ObjectAccessor, MaNGOS::ClassLevelLockable<ObjectAccessor, ACE_Recursive_Thread_Mutex> >
{
friend class MaNGOS::OperatorNew<ObjectAccessor>;
@ -93,28 +51,62 @@ class ObjectAccessor : public MaNGOS::Singleton<ObjectAccessor, MaNGOS::ClassLev
ObjectAccessor(const ObjectAccessor&);
ObjectAccessor& operator=(const ObjectAccessor&);
template <class T>
struct HashMapHolder
{
using MapType = std::unordered_map<ObjectGuid, T*>;
using LockType = ACE_RW_Thread_Mutex;
HashMapHolder() : i_lock(nullptr), m_objectMap() {}
void Insert(T* o)
{
ACE_WRITE_GUARD(LockType, guard, i_lock)
m_objectMap[o->GetObjectGuid()] = o;
}
void Remove(T* o)
{
ACE_WRITE_GUARD(LockType, guard, i_lock)
m_objectMap.erase(o->GetObjectGuid());
}
T* Find(ObjectGuid guid)
{
ACE_READ_GUARD_RETURN (LockType, guard, i_lock, nullptr)
auto itr = m_objectMap.find(guid);
return (itr != m_objectMap.end()) ? itr->second : nullptr;
}
inline MapType& GetContainer() { return m_objectMap; }
inline LockType& GetLock() { return i_lock; }
LockType i_lock;
MapType m_objectMap;
char _cache_guard[512];
};
using Player2CorpsesMapType = std::unordered_map<ObjectGuid, Corpse*>;
using LockType = ACE_Recursive_Thread_Mutex;
public:
typedef UNORDERED_MAP<ObjectGuid, Corpse*> Player2CorpsesMapType;
// Search player at any map in world and other objects at same map with `obj`
// Note: recommended use Map::GetUnit version if player also expected at same map only
static Unit* GetUnit(WorldObject const& obj, ObjectGuid guid);
Unit* GetUnit(WorldObject const& obj, ObjectGuid guid);
// Player access
static Player* FindPlayer(ObjectGuid guid, bool inWorld = true);// if need player at specific map better use Map::GetPlayer
static Player* FindPlayerByName(const char* name);
static void KickPlayer(ObjectGuid guid);
HashMapHolder<Player>::MapType& GetPlayers()
{
return HashMapHolder<Player>::GetContainer();
}
Player* FindPlayer(ObjectGuid guid, bool inWorld = true);// if need player at specific map better use Map::GetPlayer
Player* FindPlayerByName(const char* name);
void KickPlayer(ObjectGuid guid);
void SaveAllPlayers();
// Corpse access
Corpse* FindCorpse(ObjectGuid guid);
Corpse* GetCorpseForPlayerGUID(ObjectGuid guid);
static Corpse* GetCorpseInMap(ObjectGuid guid, uint32 mapid);
Corpse* GetCorpseInMap(ObjectGuid guid, uint32 mapid);
void RemoveCorpse(Corpse* corpse);
void AddCorpse(Corpse* corpse);
void AddCorpsesToGrid(GridPair const& gridpair, GridType& grid, Map* map);
@ -122,19 +114,24 @@ class ObjectAccessor : public MaNGOS::Singleton<ObjectAccessor, MaNGOS::ClassLev
void RemoveOldCorpses();
// For call from Player/Corpse AddToWorld/RemoveFromWorld only
void AddObject(Corpse* object) { HashMapHolder<Corpse>::Insert(object); }
void AddObject(Player* object) { HashMapHolder<Player>::Insert(object); }
void RemoveObject(Corpse* object) { HashMapHolder<Corpse>::Remove(object); }
void RemoveObject(Player* object) { HashMapHolder<Player>::Remove(object); }
void AddObject(Corpse* object) { i_corpseMap.Insert(object); }
void AddObject(Player* object) { i_playerMap.Insert(object); }
void RemoveObject(Corpse* object) { i_corpseMap.Remove(object); }
void RemoveObject(Player* object) { i_playerMap.Remove(object); }
template<typename F>
void DoForAllPlayers(F&& f)
{
ACE_READ_GUARD(HashMapHolder<Player>::LockType, g, i_playerMap.GetLock())
for (auto& iter : i_playerMap.GetContainer())
if(iter.second != nullptr)
{ std::forward<F>(f)(iter.second); }
}
private:
Player2CorpsesMapType i_player2corpse;
typedef ACE_Thread_Mutex LockType;
LockType i_playerGuard;
char _cache_guard[1024];
Player2CorpsesMapType i_player2corpse;
HashMapHolder<Player> i_playerMap;
HashMapHolder<Corpse> i_corpseMap;
LockType i_corpseGuard;
};

View File

@ -3036,8 +3036,8 @@ void ObjectMgr::BuildPlayerLevelInfo(uint8 race, uint8 _class, uint8 level, Play
/* * Static Wrappers */
/* ********************************************************************************************* */
GameObjectInfo const* ObjectMgr::GetGameObjectInfo(uint32 id) { return sGOStorage.LookupEntry<GameObjectInfo>(id); }
Player* ObjectMgr::GetPlayer(const char* name) { return ObjectAccessor::FindPlayerByName(name); }
Player* ObjectMgr::GetPlayer(ObjectGuid guid, bool inWorld /*=true*/) { return ObjectAccessor::FindPlayer(guid, inWorld); }
Player* ObjectMgr::GetPlayer(const char* name) { return sObjectAccessor.FindPlayerByName(name); }
Player* ObjectMgr::GetPlayer(ObjectGuid guid, bool inWorld /*=true*/) { return sObjectAccessor.FindPlayer(guid, inWorld); }
CreatureInfo const* ObjectMgr::GetCreatureTemplate(uint32 id) { return sCreatureStorage.LookupEntry<CreatureInfo>(id); }
CreatureModelInfo const* ObjectMgr::GetCreatureModelInfo(uint32 modelid) { return sCreatureModelStorage.LookupEntry<CreatureModelInfo>(modelid); }
EquipmentInfo const* ObjectMgr::GetEquipmentInfo(uint32 entry) { return sEquipmentStorage.LookupEntry<EquipmentInfo>(entry); }

View File

@ -623,8 +623,8 @@ class ObjectMgr
// Static wrappers for various accessors
static GameObjectInfo const* GetGameObjectInfo(uint32 id); ///< Wrapper for sGOStorage.LookupEntry
static Player* GetPlayer(const char* name); ///< Wrapper for ObjectAccessor::FindPlayerByName
static Player* GetPlayer(ObjectGuid guid, bool inWorld = true); ///< Wrapper for ObjectAccessor::FindPlayer
static Player* GetPlayer(const char* name); ///< Wrapper for sObjectAccessor.FindPlayerByName
static Player* GetPlayer(ObjectGuid guid, bool inWorld = true); ///< Wrapper for sObjectAccessor.FindPlayer
static CreatureInfo const* GetCreatureTemplate(uint32 id); ///< Wrapper for sCreatureStorage.LookupEntry
static CreatureModelInfo const* GetCreatureModelInfo(uint32 modelid); ///< Wrapper for sCreatureModelStorage.LookupEntry
static EquipmentInfo const* GetEquipmentInfo(uint32 entry); ///< Wrapper for sEquipmentStorage.LookupEntry

View File

@ -17920,7 +17920,7 @@ void Player::InitPrimaryProfessions()
void Player::SetComboPoints()
{
Unit* combotarget = ObjectAccessor::GetUnit(*this, m_comboTargetGuid);
Unit* combotarget = sObjectAccessor.GetUnit(*this, m_comboTargetGuid);
if (combotarget)
{
SetGuidValue(PLAYER_FIELD_COMBO_TARGET, combotarget->GetObjectGuid());
@ -17950,7 +17950,7 @@ void Player::AddComboPoints(Unit* target, int8 count)
else
{
if (m_comboTargetGuid)
if (Unit* target2 = ObjectAccessor::GetUnit(*this, m_comboTargetGuid))
if (Unit* target2 = sObjectAccessor.GetUnit(*this, m_comboTargetGuid))
{ target2->RemoveComboPointHolder(GetGUIDLow()); }
m_comboTargetGuid = target->GetObjectGuid();
@ -17977,7 +17977,7 @@ void Player::ClearComboPoints()
SetComboPoints();
if (Unit* target = ObjectAccessor::GetUnit(*this, m_comboTargetGuid))
if (Unit* target = sObjectAccessor.GetUnit(*this, m_comboTargetGuid))
{ target->RemoveComboPointHolder(GetGUIDLow()); }
m_comboTargetGuid.Clear();
@ -19780,7 +19780,7 @@ Object* Player::GetObjectByTypeMask(ObjectGuid guid, TypeMask typemask)
if (GetObjectGuid() == guid)
{ return this; }
if ((typemask & TYPEMASK_PLAYER) && IsInWorld())
{ return ObjectAccessor::FindPlayer(guid); }
{ return sObjectAccessor.FindPlayer(guid); }
break;
case HIGHGUID_GAMEOBJECT:
if ((typemask & TYPEMASK_GAMEOBJECT) && IsInWorld())

View File

@ -398,9 +398,9 @@ void PlayerLogger::SetLogActiveMask(PlayerLogEntity entity, bool on)
Player* PlayerLogger::GetPlayer() const
{
Player* pl = ObjectAccessor::FindPlayer(ObjectGuid(HIGHGUID_PLAYER, playerGuid), true);
Player* pl = sObjectAccessor.FindPlayer(ObjectGuid(HIGHGUID_PLAYER, playerGuid), true);
if (!pl)
pl = ObjectAccessor::FindPlayer(ObjectGuid(HIGHGUID_CORPSE, playerGuid), true);
pl = sObjectAccessor.FindPlayer(ObjectGuid(HIGHGUID_CORPSE, playerGuid), true);
if (!pl)
sLog.outError("PlayerLogger: cannot get current player! Ignoring the record.");

View File

@ -221,7 +221,7 @@ void SocialMgr::GetFriendInfo(Player* player, uint32 friend_lowguid, FriendInfo&
if (!player)
{ return; }
Player* pFriend = ObjectAccessor::FindPlayer(ObjectGuid(HIGHGUID_PLAYER, friend_lowguid));
Player* pFriend = sObjectAccessor.FindPlayer(ObjectGuid(HIGHGUID_PLAYER, friend_lowguid));
Team team = player->GetTeam();
AccountTypes security = player->GetSession()->GetSecurity();
@ -309,7 +309,7 @@ void SocialMgr::BroadcastToFriendListers(Player* player, WorldPacket* packet)
PlayerSocialMap::const_iterator itr2 = itr->second.m_playerSocialMap.find(guid);
if (itr2 != itr->second.m_playerSocialMap.end() && (itr2->second.Flags & SOCIAL_FLAG_FRIEND))
{
Player* pFriend = ObjectAccessor::FindPlayer(ObjectGuid(HIGHGUID_PLAYER, itr->first));
Player* pFriend = sObjectAccessor.FindPlayer(ObjectGuid(HIGHGUID_PLAYER, itr->first));
// PLAYER see his team only and PLAYER can't see MODERATOR, GAME MASTER, ADMINISTRATOR characters
// MODERATOR, GAME MASTER, ADMINISTRATOR can see all

View File

@ -39,7 +39,7 @@ class TemporarySummon : public Creature
void UnSummon();
void SaveToDB() override;
ObjectGuid const& GetSummonerGuid() const { return m_summoner ; }
Unit* GetSummoner() const { return ObjectAccessor::GetUnit(*this, m_summoner); }
Unit* GetSummoner() const { return sObjectAccessor.GetUnit(*this, m_summoner); }
private:
TempSummonType m_type;
uint32 m_timer;

View File

@ -170,7 +170,7 @@ void Totem::SetOwner(Unit* owner)
Unit* Totem::GetOwner()
{
if (ObjectGuid ownerGuid = GetOwnerGuid())
{ return ObjectAccessor::GetUnit(*this, ownerGuid); }
{ return sObjectAccessor.GetUnit(*this, ownerGuid); }
return NULL;
}

View File

@ -5200,14 +5200,14 @@ void Unit::ModifyAuraState(AuraState flag, bool apply)
Unit* Unit::GetOwner() const
{
if (ObjectGuid ownerid = GetOwnerGuid())
{ return ObjectAccessor::GetUnit(*this, ownerid); }
{ return sObjectAccessor.GetUnit(*this, ownerid); }
return NULL;
}
Unit* Unit::GetCharmer() const
{
if (ObjectGuid charmerid = GetCharmerGuid())
{ return ObjectAccessor::GetUnit(*this, charmerid); }
{ return sObjectAccessor.GetUnit(*this, charmerid); }
return NULL;
}
@ -5223,7 +5223,7 @@ Player* Unit::GetCharmerOrOwnerPlayerOrPlayerItself()
{
ObjectGuid guid = GetCharmerOrOwnerGuid();
if (guid.IsPlayer())
{ return ObjectAccessor::FindPlayer(guid); }
{ return sObjectAccessor.FindPlayer(guid); }
return GetTypeId() == TYPEID_PLAYER ? (Player*)this : NULL;
}
@ -5232,7 +5232,7 @@ Player const* Unit::GetCharmerOrOwnerPlayerOrPlayerItself() const
{
ObjectGuid guid = GetCharmerOrOwnerGuid();
if (guid.IsPlayer())
{ return ObjectAccessor::FindPlayer(guid); }
{ return sObjectAccessor.FindPlayer(guid); }
return GetTypeId() == TYPEID_PLAYER ? (Player const*)this : NULL;
}
@ -5260,7 +5260,7 @@ Unit* Unit::GetCharm() const
{
if (ObjectGuid charm_guid = GetCharmGuid())
{
if (Unit* pet = ObjectAccessor::GetUnit(*this, charm_guid))
if (Unit* pet = sObjectAccessor.GetUnit(*this, charm_guid))
{ return pet; }
sLog.outError("Unit::GetCharm: Charmed %s not exist.", charm_guid.GetString().c_str());

View File

@ -136,7 +136,7 @@ void HostileReference::updateOnlineStatus()
if (!isValid())
{
if (Unit* target = ObjectAccessor::GetUnit(*getSourceUnit(), getUnitGuid()))
if (Unit* target = sObjectAccessor.GetUnit(*getSourceUnit(), getUnitGuid()))
{ link(target, getSource()); }
}
// only check for online status if

View File

@ -79,7 +79,7 @@ AccountOpResult AccountMgr::DeleteAccount(uint32 accid)
ObjectGuid guid = ObjectGuid(HIGHGUID_PLAYER, guidlo);
// kick if player currently
ObjectAccessor::KickPlayer(guid);
sObjectAccessor.KickPlayer(guid);
Player::DeleteFromDB(guid, accid, false); // no need to update realm characters
}
while (result->NextRow());

View File

@ -1938,7 +1938,7 @@ Unit* ChatHandler::getSelectedUnit()
{ return m_session->GetPlayer(); }
// can be selected player at another map
return ObjectAccessor::GetUnit(*m_session->GetPlayer(), guid);
return sObjectAccessor.GetUnit(*m_session->GetPlayer(), guid);
}
Creature* ChatHandler::getSelectedCreature()

View File

@ -148,13 +148,11 @@ void WorldSession::HandleGMTicketCreateOpcode(WorldPacket& recv_data)
data << uint32(GMTICKET_RESPONSE_CREATE_SUCCESS); // 2 - nothing appears (3-error creating, 5-error updating)
SendPacket(&data);
// TODO: Guard player map
HashMapHolder<Player>::MapType& m = sObjectAccessor.GetPlayers();
for (HashMapHolder<Player>::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr)
{
if (itr->second->GetSession()->GetSecurity() >= SEC_GAMEMASTER && itr->second->isAcceptTickets())
{ ChatHandler(itr->second).PSendSysMessage(LANG_COMMAND_TICKETNEW, GetPlayer()->GetName()); }
}
sObjectAccessor.DoForAllPlayers([this](Player* player)
{
if (player->GetSession()->GetSecurity() >= SEC_GAMEMASTER && player->isAcceptTickets())
{ ChatHandler(player).PSendSysMessage(LANG_COMMAND_TICKETNEW, GetPlayer()->GetName()); }
});
}
void WorldSession::HandleGMTicketSystemStatusOpcode(WorldPacket& /*recv_data*/)

View File

@ -86,7 +86,7 @@ void VisibleNotifier::Notify()
if (!iter->IsPlayer())
{ continue; }
if (Player* plr = ObjectAccessor::FindPlayer(*iter))
if (Player* plr = sObjectAccessor.FindPlayer(*iter))
{ plr->UpdateVisibilityOf(plr->GetCamera().GetBody(), &player); }
}
}
@ -183,7 +183,7 @@ bool CannibalizeObjectCheck::operator()(Corpse* u)
if (u->GetType() == CORPSE_BONES)
{ return false; }
Player* owner = ObjectAccessor::FindPlayer(u->GetOwnerGuid());
Player* owner = sObjectAccessor.FindPlayer(u->GetOwnerGuid());
if (!owner || i_fobj->IsFriendlyTo(owner))
{ return false; }

View File

@ -1719,7 +1719,7 @@ void Group::UpdateLooterGuid(WorldObject* pSource, bool ifneed)
if (ifneed)
{
// not update if only update if need and ok
Player* looter = ObjectAccessor::FindPlayer(guid_itr->guid);
Player* looter = sObjectAccessor.FindPlayer(guid_itr->guid);
if (looter && looter->IsWithinDist(pSource, sWorld.getConfig(CONFIG_FLOAT_GROUP_XP_DISTANCE), false))
{ return; }
}
@ -1731,7 +1731,7 @@ void Group::UpdateLooterGuid(WorldObject* pSource, bool ifneed)
{
for (member_citerator itr = guid_itr; itr != m_memberSlots.end(); ++itr)
{
if (Player* pl = ObjectAccessor::FindPlayer(itr->guid))
if (Player* pl = sObjectAccessor.FindPlayer(itr->guid))
{
if (pl->IsWithinDist(pSource, sWorld.getConfig(CONFIG_FLOAT_GROUP_XP_DISTANCE), false))
{
@ -1752,7 +1752,7 @@ void Group::UpdateLooterGuid(WorldObject* pSource, bool ifneed)
// search from start
for (member_citerator itr = m_memberSlots.begin(); itr != guid_itr; ++itr)
{
if (Player* pl = ObjectAccessor::FindPlayer(itr->guid))
if (Player* pl = sObjectAccessor.FindPlayer(itr->guid))
{
if (pl->IsWithinDist(pSource, sWorld.getConfig(CONFIG_FLOAT_GROUP_XP_DISTANCE), false))
{

View File

@ -783,7 +783,7 @@ void WorldSession::HandleRequestPartyMemberStatsOpcode(WorldPacket& recv_data)
ObjectGuid guid;
recv_data >> guid;
Player* player = ObjectAccessor::FindPlayer(guid, false);
Player* player = sObjectAccessor.FindPlayer(guid, false);
if (!player)
{
WorldPacket data(SMSG_PARTY_MEMBER_STATS_FULL, 3 + 4 + 1);

View File

@ -93,7 +93,7 @@ void WorldSession::HandleGuildInviteOpcode(WorldPacket& recvPacket)
recvPacket >> Invitedname;
if (normalizePlayerName(Invitedname))
{ player = ObjectAccessor::FindPlayerByName(Invitedname.c_str()); }
{ player = sObjectAccessor.FindPlayerByName(Invitedname.c_str()); }
if (!player)
{

View File

@ -577,7 +577,7 @@ void WorldSession::HandleLootMasterGiveOpcode(WorldPacket& recv_data)
return;
}
Player* target = ObjectAccessor::FindPlayer(target_playerguid);
Player* target = sObjectAccessor.FindPlayer(target_playerguid);
if (!target)
{ return; }

View File

@ -1839,7 +1839,7 @@ void Map::ScriptsProcess()
*/
Player* Map::GetPlayer(ObjectGuid guid)
{
Player* plr = ObjectAccessor::FindPlayer(guid); // return only in world players
Player* plr = sObjectAccessor.FindPlayer(guid); // return only in world players
return plr && plr->GetMap() == this ? plr : NULL;
}
@ -1872,7 +1872,7 @@ Pet* Map::GetPet(ObjectGuid guid)
*/
Corpse* Map::GetCorpse(ObjectGuid guid)
{
Corpse* ret = ObjectAccessor::GetCorpseInMap(guid, GetId());
Corpse* ret = sObjectAccessor.GetCorpseInMap(guid, GetId());
return ret && ret->GetInstanceId() == GetInstanceId() ? ret : NULL;
}

View File

@ -158,45 +158,41 @@ void WorldSession::HandleWhoOpcode(WorldPacket& recv_data)
data << uint32(matchcount); // placeholder, count of players matching criteria
data << uint32(displaycount); // placeholder, count of players displayed
// TODO: Guard Player map
HashMapHolder<Player>::MapType& m = sObjectAccessor.GetPlayers();
for (HashMapHolder<Player>::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr)
sObjectAccessor.DoForAllPlayers([&](Player* pl)
{
Player* pl = itr->second;
if (security == SEC_PLAYER)
{
// player can see member of other team only if CONFIG_BOOL_ALLOW_TWO_SIDE_WHO_LIST
if (pl->GetTeam() != team && !allowTwoSideWhoList)
{ continue; }
{ return; }
// player can see MODERATOR, GAME MASTER, ADMINISTRATOR only if CONFIG_GM_IN_WHO_LIST
if (pl->GetSession()->GetSecurity() > gmLevelInWhoList)
{ continue; }
{ return; }
}
// do not process players which are not in world
if (!pl->IsInWorld())
{ continue; }
{ return; }
// check if target is globally visible for player
if (!pl->IsVisibleGloballyFor(_player))
{ continue; }
{ return; }
// check if target's level is in level range
uint32 lvl = pl->getLevel();
if (lvl < level_min || lvl > level_max)
{ continue; }
{ return; }
// check if class matches classmask
uint32 class_ = pl->getClass();
if (!(classmask & (1 << class_)))
{ continue; }
{ return; }
// check if race matches racemask
uint32 race = pl->getRace();
if (!(racemask & (1 << race)))
{ continue; }
{ return; }
uint32 pzoneid = pl->GetZoneId();
@ -214,25 +210,25 @@ void WorldSession::HandleWhoOpcode(WorldPacket& recv_data)
z_show = false;
}
if (!z_show)
{ continue; }
{ return; }
std::string pname = pl->GetName();
std::wstring wpname;
if (!Utf8toWStr(pname, wpname))
{ continue; }
{ return; }
wstrToLower(wpname);
if (!(wplayer_name.empty() || wpname.find(wplayer_name) != std::wstring::npos))
{ continue; }
{ return; }
std::string gname = sGuildMgr.GetGuildNameById(pl->GetGuildId());
std::wstring wgname;
if (!Utf8toWStr(gname, wgname))
{ continue; }
{ return; }
wstrToLower(wgname);
if (!(wguild_name.empty() || wgname.find(wguild_name) != std::wstring::npos))
{ continue; }
{ return; }
std::string aname;
if (AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(pzoneid))
@ -254,12 +250,12 @@ void WorldSession::HandleWhoOpcode(WorldPacket& recv_data)
}
}
if (!s_show)
{ continue; }
{ return; }
// 49 is maximum player count sent to client
++matchcount;
if (matchcount > 49)
continue;
return;
++displaycount;
@ -269,7 +265,7 @@ void WorldSession::HandleWhoOpcode(WorldPacket& recv_data)
data << uint32(class_); // player class
data << uint32(race); // player race
data << uint32(pzoneid); // player zone id
}
});
data.put(0, displaycount); // insert right count, count displayed
data.put(4, matchcount); // insert right count, count of matches
@ -418,7 +414,7 @@ void WorldSession::HandleSetTargetOpcode(WorldPacket& recv_data)
_player->SetTargetGuid(guid);
// update reputation list if need
Unit* unit = ObjectAccessor::GetUnit(*_player, guid); // can select group members at diff maps
Unit* unit = sObjectAccessor.GetUnit(*_player, guid); // can select group members at diff maps
if (!unit)
{ return; }
@ -440,7 +436,7 @@ void WorldSession::HandleSetSelectionOpcode(WorldPacket& recv_data)
}
// update reputation list if need
Unit* unit = ObjectAccessor::GetUnit(*_player, guid); // can select group members at diff maps
Unit* unit = sObjectAccessor.GetUnit(*_player, guid); // can select group members at diff maps
if (!unit)
{ return; }
@ -512,7 +508,7 @@ void WorldSession::HandleAddFriendOpcodeCallBack(QueryResult* result, uint32 acc
{ friendResult = FRIEND_ALREADY; }
else
{
Player* pFriend = ObjectAccessor::FindPlayer(friendGuid);
Player* pFriend = sObjectAccessor.FindPlayer(friendGuid);
if (pFriend && pFriend->IsInWorld() && pFriend->IsVisibleGloballyFor(player))
{ friendResult = FRIEND_ADDED_ONLINE; }
else

View File

@ -455,7 +455,7 @@ void WorldSession::HandleOfferPetitionOpcode(WorldPacket& recv_data)
recv_data >> petitionGuid; // petition guid
recv_data >> playerGuid; // player guid
Player* player = ObjectAccessor::FindPlayer(playerGuid);
Player* player = sObjectAccessor.FindPlayer(playerGuid);
if (!player)
{ return; }

View File

@ -151,7 +151,7 @@ void WorldSession::HandleQuestgiverAcceptQuestOpcode(WorldPacket& recv_data)
return;
}
if (Player* pPlayer = ObjectAccessor::FindPlayer(_player->GetDividerGuid()))
if (Player* pPlayer = sObjectAccessor.FindPlayer(_player->GetDividerGuid()))
{
pPlayer->SendPushToPartyResponse(_player, QUEST_PARTY_MSG_ACCEPT_QUEST);
_player->ClearDividerGuid();
@ -362,7 +362,7 @@ void WorldSession::HandleQuestConfirmAccept(WorldPacket& recv_data)
if (!pQuest->HasQuestFlag(QUEST_FLAGS_PARTY_ACCEPT))
{ return; }
Player* pOriginalPlayer = ObjectAccessor::FindPlayer(_player->GetDividerGuid());
Player* pOriginalPlayer = sObjectAccessor.FindPlayer(_player->GetDividerGuid());
if (!pOriginalPlayer)
{ return; }
@ -487,7 +487,7 @@ void WorldSession::HandleQuestPushResult(WorldPacket& recvPacket)
DEBUG_LOG("WORLD: Received opcode MSG_QUEST_PUSH_RESULT");
if (Player* pPlayer = ObjectAccessor::FindPlayer(_player->GetDividerGuid()))
if (Player* pPlayer = sObjectAccessor.FindPlayer(_player->GetDividerGuid()))
{
WorldPacket data(MSG_QUEST_PUSH_RESULT, (8 + 1));
data << _player->GetObjectGuid();

View File

@ -908,7 +908,7 @@ bool ScriptAction::GetScriptCommandObject(const ObjectGuid guid, bool includeIte
resultObject = m_map->GetGameObject(guid);
break;
case HIGHGUID_CORPSE:
resultObject = HashMapHolder<Corpse>::Find(guid);
resultObject = sObjectAccessor.FindCorpse(guid);
break;
case HIGHGUID_ITEM:
// case HIGHGUID_CONTAINER: ==HIGHGUID_ITEM

View File

@ -148,7 +148,7 @@ void SpellCastTargets::Update(Unit* caster)
{
m_GOTarget = m_GOTargetGUID ? caster->GetMap()->GetGameObject(m_GOTargetGUID) : NULL;
m_unitTarget = m_unitTargetGUID ?
(m_unitTargetGUID == caster->GetObjectGuid() ? caster : ObjectAccessor::GetUnit(*caster, m_unitTargetGUID)) :
(m_unitTargetGUID == caster->GetObjectGuid() ? caster : sObjectAccessor.GetUnit(*caster, m_unitTargetGUID)) :
NULL;
m_itemTarget = NULL;
@ -450,7 +450,7 @@ void Spell::FillTargetMap()
{
if (m_caster->GetTypeId() == TYPEID_PLAYER)
{
if (Unit* target = ObjectAccessor::Instance().GetUnit(*m_caster, ((Player*)m_caster)->GetSelectionGuid()))
if (Unit* target = sObjectAccessor.Instance().GetUnit(*m_caster, ((Player*)m_caster)->GetSelectionGuid()))
{
if (!m_caster->IsFriendlyTo(target))
{ tmpUnitLists[i /*==effToIndex[i]*/].push_back(target); }
@ -830,7 +830,7 @@ void Spell::AddUnitTarget(Unit* pVictim, SpellEffectIndex effIndex)
void Spell::AddUnitTarget(ObjectGuid unitGuid, SpellEffectIndex effIndex)
{
if (Unit* unit = m_caster->GetObjectGuid() == unitGuid ? m_caster : ObjectAccessor::GetUnit(*m_caster, unitGuid))
if (Unit* unit = m_caster->GetObjectGuid() == unitGuid ? m_caster : sObjectAccessor.GetUnit(*m_caster, unitGuid))
{ AddUnitTarget(unit, effIndex); }
}
@ -918,7 +918,7 @@ void Spell::DoAllEffectOnTarget(TargetInfo* target)
// Get mask of effects for target
uint32 mask = target->effectMask;
Unit* unit = m_caster->GetObjectGuid() == target->targetGUID ? m_caster : ObjectAccessor::GetUnit(*m_caster, target->targetGUID);
Unit* unit = m_caster->GetObjectGuid() == target->targetGUID ? m_caster : sObjectAccessor.GetUnit(*m_caster, target->targetGUID);
if (!unit)
{ return; }
@ -1365,7 +1365,7 @@ void Spell::HandleDelayedSpellLaunch(TargetInfo* target)
// Get mask of effects for target
uint32 mask = target->effectMask;
Unit* unit = m_caster->GetObjectGuid() == target->targetGUID ? m_caster : ObjectAccessor::GetUnit(*m_caster, target->targetGUID);
Unit* unit = m_caster->GetObjectGuid() == target->targetGUID ? m_caster : sObjectAccessor.GetUnit(*m_caster, target->targetGUID);
if (!unit)
{ return; }
@ -1448,7 +1448,7 @@ bool Spell::IsAliveUnitPresentInTargetList()
{
if (ihit->missCondition == SPELL_MISS_NONE && (needAliveTargetMask & ihit->effectMask))
{
Unit* unit = m_caster->GetObjectGuid() == ihit->targetGUID ? m_caster : ObjectAccessor::GetUnit(*m_caster, ihit->targetGUID);
Unit* unit = m_caster->GetObjectGuid() == ihit->targetGUID ? m_caster : sObjectAccessor.GetUnit(*m_caster, ihit->targetGUID);
// either unit is alive and normal spell, or unit dead and deathonly-spell
if (unit && (unit->IsAlive() != IsDeathOnlySpell(m_spellInfo)))
@ -2330,7 +2330,7 @@ void Spell::SetTargetMap(SpellEffectIndex effIndex, uint32 targetMode, UnitList&
break;
case TYPEID_CORPSE:
m_targets.setCorpseTarget((Corpse*)result);
if (Player* owner = ObjectAccessor::FindPlayer(((Corpse*)result)->GetOwnerGuid()))
if (Player* owner = sObjectAccessor.FindPlayer(((Corpse*)result)->GetOwnerGuid()))
{ targetUnitMap.push_back(owner); }
break;
}
@ -2389,7 +2389,7 @@ void Spell::SetTargetMap(SpellEffectIndex effIndex, uint32 targetMode, UnitList&
if (m_targets.getCorpseTargetGuid())
{
if (Corpse* corpse = m_caster->GetMap()->GetCorpse(m_targets.getCorpseTargetGuid()))
if (Player* owner = ObjectAccessor::FindPlayer(corpse->GetOwnerGuid()))
if (Player* owner = sObjectAccessor.FindPlayer(corpse->GetOwnerGuid()))
{ targetUnitMap.push_back(owner); }
}
break;
@ -2454,7 +2454,7 @@ void Spell::SetTargetMap(SpellEffectIndex effIndex, uint32 targetMode, UnitList&
else if (m_targets.getCorpseTargetGuid())
{
if (Corpse* corpse = m_caster->GetMap()->GetCorpse(m_targets.getCorpseTargetGuid()))
if (Player* owner = ObjectAccessor::FindPlayer(corpse->GetOwnerGuid()))
if (Player* owner = sObjectAccessor.FindPlayer(corpse->GetOwnerGuid()))
{ targetUnitMap.push_back(owner); }
}
break;
@ -2664,7 +2664,7 @@ void Spell::cancel()
{
if (ihit->missCondition == SPELL_MISS_NONE)
{
Unit* unit = m_caster->GetObjectGuid() == (*ihit).targetGUID ? m_caster : ObjectAccessor::GetUnit(*m_caster, ihit->targetGUID);
Unit* unit = m_caster->GetObjectGuid() == (*ihit).targetGUID ? m_caster : sObjectAccessor.GetUnit(*m_caster, ihit->targetGUID);
if (unit && unit->IsAlive())
{ unit->RemoveAurasByCasterSpell(m_spellInfo->Id, m_caster->GetObjectGuid()); }
}
@ -3153,7 +3153,7 @@ void Spell::update(uint32 difftime)
if (!target.targetGUID.IsCreature())
{ continue; }
Unit* unit = m_caster->GetObjectGuid() == target.targetGUID ? m_caster : ObjectAccessor::GetUnit(*m_caster, target.targetGUID);
Unit* unit = m_caster->GetObjectGuid() == target.targetGUID ? m_caster : sObjectAccessor.GetUnit(*m_caster, target.targetGUID);
if (unit == NULL)
{ continue; }
@ -3216,7 +3216,7 @@ void Spell::finish(bool ok)
if (ihit->missCondition == SPELL_MISS_NONE)
{
// check m_caster->GetGUID() let load auras at login and speedup most often case
Unit* unit = m_caster->GetObjectGuid() == ihit->targetGUID ? m_caster : ObjectAccessor::GetUnit(*m_caster, ihit->targetGUID);
Unit* unit = m_caster->GetObjectGuid() == ihit->targetGUID ? m_caster : sObjectAccessor.GetUnit(*m_caster, ihit->targetGUID);
if (unit && unit->IsAlive())
{
SpellEntry const* auraSpellInfo = (*i)->GetSpellProto();
@ -3650,7 +3650,7 @@ void Spell::SendChannelUpdate(uint32 time)
ObjectGuid target_guid = m_caster->GetChannelObjectGuid();
if (target_guid != m_caster->GetObjectGuid() && target_guid.IsUnit())
if (Unit* target = ObjectAccessor::GetUnit(*m_caster, target_guid))
if (Unit* target = sObjectAccessor.GetUnit(*m_caster, target_guid))
{ target->RemoveAurasByCasterSpell(m_spellInfo->Id, m_caster->GetObjectGuid()); }
// Only finish channeling when latest channeled spell finishes
@ -3684,7 +3684,7 @@ void Spell::SendChannelStart(uint32 duration)
if ((itr->effectMask & (1 << EFFECT_INDEX_0)) && itr->reflectResult == SPELL_MISS_NONE &&
itr->targetGUID != m_caster->GetObjectGuid())
{
target = ObjectAccessor::GetUnit(*m_caster, itr->targetGUID);
target = sObjectAccessor.GetUnit(*m_caster, itr->targetGUID);
break;
}
}
@ -3962,7 +3962,7 @@ void Spell::HandleThreatSpells()
if (ihit->missCondition != SPELL_MISS_NONE)
{ continue; }
Unit* target = m_caster->GetObjectGuid() == ihit->targetGUID ? m_caster : ObjectAccessor::GetUnit(*m_caster, ihit->targetGUID);
Unit* target = m_caster->GetObjectGuid() == ihit->targetGUID ? m_caster : sObjectAccessor.GetUnit(*m_caster, ihit->targetGUID);
if (!target)
{ continue; }
@ -6187,7 +6187,7 @@ void Spell::DelayedChannel()
{
if ((*ihit).missCondition == SPELL_MISS_NONE)
{
if (Unit* unit = m_caster->GetObjectGuid() == ihit->targetGUID ? m_caster : ObjectAccessor::GetUnit(*m_caster, ihit->targetGUID))
if (Unit* unit = m_caster->GetObjectGuid() == ihit->targetGUID ? m_caster : sObjectAccessor.GetUnit(*m_caster, ihit->targetGUID))
{ unit->DelaySpellAuraHolder(m_spellInfo->Id, delaytime, unit->GetObjectGuid()); }
}
}
@ -6213,7 +6213,7 @@ void Spell::UpdateOriginalCasterPointer()
}
else
{
Unit* unit = ObjectAccessor::GetUnit(*m_caster, m_originalCasterGUID);
Unit* unit = sObjectAccessor.GetUnit(*m_caster, m_originalCasterGUID);
m_originalCaster = unit && unit->IsInWorld() ? unit : NULL;
}
}

View File

@ -353,7 +353,7 @@ SingleEnemyTargetAura::~SingleEnemyTargetAura()
Unit* SingleEnemyTargetAura::GetTriggerTarget() const
{
return ObjectAccessor::GetUnit(*(m_spellAuraHolder->GetTarget()), m_castersTargetGuid);
return sObjectAccessor.GetUnit(*(m_spellAuraHolder->GetTarget()), m_castersTargetGuid);
}
Aura* CreateAura(SpellEntry const* spellproto, SpellEffectIndex eff, int32* currentBasePoints, SpellAuraHolder* holder, Unit* target, Unit* caster, Item* castItem)
@ -4224,7 +4224,7 @@ void Aura::HandleAuraRetainComboPoints(bool apply, bool Real)
// combo points was added in SPELL_EFFECT_ADD_COMBO_POINTS handler
// remove only if aura expire by time (in case combo points amount change aura removed without combo points lost)
if (!apply && m_removeMode == AURA_REMOVE_BY_EXPIRE && target->GetComboTargetGuid())
if (Unit* unit = ObjectAccessor::GetUnit(*GetTarget(), target->GetComboTargetGuid()))
if (Unit* unit = sObjectAccessor.GetUnit(*GetTarget(), target->GetComboTargetGuid()))
{ target->AddComboPoints(unit, -m_modifier.m_amount); }
}
@ -5252,7 +5252,7 @@ Unit* SpellAuraHolder::GetCaster() const
if (GetCasterGuid() == m_target->GetObjectGuid())
{ return m_target; }
return ObjectAccessor::GetUnit(*m_target, m_casterGuid);// player will search at any maps
return sObjectAccessor.GetUnit(*m_target, m_casterGuid);// player will search at any maps
}
bool SpellAuraHolder::IsWeaponBuffCoexistableWith(SpellAuraHolder const* ref) const

View File

@ -582,7 +582,7 @@ void WorldSession::HandleInitiateTradeOpcode(WorldPacket& recvPacket)
return;
}
Player* pOther = ObjectAccessor::FindPlayer(otherGuid);
Player* pOther = sObjectAccessor.FindPlayer(otherGuid);
if (!pOther)
{

@ -1 +1 @@
Subproject commit cd5a55522574b9d74f7abb32cd8512b1d4234753
Subproject commit 807407484cb15423c33634140abb15ee621ab687