feat(Core/Misc): implement ObjectGuid class (port from TC) (#4885)
This commit is contained in:
@@ -22,31 +22,45 @@
|
||||
#include "Opcodes.h"
|
||||
#include "Pet.h"
|
||||
#include "Player.h"
|
||||
#include "Transport.h"
|
||||
#include "Vehicle.h"
|
||||
#include "World.h"
|
||||
#include "WorldPacket.h"
|
||||
#include <cmath>
|
||||
|
||||
template<class T>
|
||||
void HashMapHolder<T>::Insert(T* o)
|
||||
{
|
||||
static_assert(std::is_same<Player, T>::value
|
||||
|| std::is_same<MotionTransport, T>::value,
|
||||
"Only Player and Motion Transport can be registered in global HashMapHolder");
|
||||
|
||||
std::unique_lock<std::shared_mutex> lock(*GetLock());
|
||||
m_objectMap[o->GetGUID()] = o;
|
||||
|
||||
GetContainer()[o->GetGUID()] = o;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void HashMapHolder<T>::Remove(T* o)
|
||||
{
|
||||
std::unique_lock<std::shared_mutex> lock(*GetLock());
|
||||
m_objectMap.erase(o->GetGUID());
|
||||
|
||||
GetContainer().erase(o->GetGUID());
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T* HashMapHolder<T>::Find(uint64 guid)
|
||||
T* HashMapHolder<T>::Find(ObjectGuid guid)
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> lock(*GetLock());
|
||||
typename MapType::iterator itr = m_objectMap.find(guid);
|
||||
return (itr != m_objectMap.end()) ? itr->second : nullptr;
|
||||
|
||||
typename MapType::iterator itr = GetContainer().find(guid);
|
||||
return (itr != GetContainer().end()) ? itr->second : nullptr;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
auto HashMapHolder<T>::GetContainer() -> MapType&
|
||||
{
|
||||
static MapType _objectMap;
|
||||
return _objectMap;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
@@ -56,181 +70,188 @@ std::shared_mutex* HashMapHolder<T>::GetLock()
|
||||
return &_lock;
|
||||
}
|
||||
|
||||
ObjectAccessor::ObjectAccessor()
|
||||
HashMapHolder<Player>::MapType const& ObjectAccessor::GetPlayers()
|
||||
{
|
||||
return HashMapHolder<Player>::GetContainer();
|
||||
}
|
||||
|
||||
ObjectAccessor::~ObjectAccessor()
|
||||
{
|
||||
}
|
||||
template class HashMapHolder<Player>;
|
||||
template class HashMapHolder<MotionTransport>;
|
||||
|
||||
ObjectAccessor* ObjectAccessor::instance()
|
||||
namespace PlayerNameMapHolder
|
||||
{
|
||||
static ObjectAccessor instance;
|
||||
return &instance;
|
||||
}
|
||||
typedef std::unordered_map<std::string, Player*> MapType;
|
||||
static MapType PlayerNameMap;
|
||||
|
||||
Player* ObjectAccessor::GetObjectInWorld(uint64 guid, Player* /*typeSpecifier*/)
|
||||
{
|
||||
Player* player = HashMapHolder<Player>::Find(guid);
|
||||
return player && player->IsInWorld() ? player : nullptr;
|
||||
}
|
||||
|
||||
WorldObject* ObjectAccessor::GetWorldObject(WorldObject const& p, uint64 guid)
|
||||
{
|
||||
switch (GUID_HIPART(guid))
|
||||
void Insert(Player* p)
|
||||
{
|
||||
case HIGHGUID_PLAYER:
|
||||
PlayerNameMap[p->GetName()] = p;
|
||||
}
|
||||
|
||||
void Remove(Player* p)
|
||||
{
|
||||
PlayerNameMap.erase(p->GetName());
|
||||
}
|
||||
|
||||
Player* Find(std::string const& name)
|
||||
{
|
||||
std::string charName(name);
|
||||
if (!normalizePlayerName(charName))
|
||||
return nullptr;
|
||||
|
||||
auto itr = PlayerNameMap.find(charName);
|
||||
return (itr != PlayerNameMap.end()) ? itr->second : nullptr;
|
||||
}
|
||||
|
||||
} // namespace PlayerNameMapHolder
|
||||
|
||||
WorldObject* ObjectAccessor::GetWorldObject(WorldObject const& p, ObjectGuid const guid)
|
||||
{
|
||||
switch (guid.GetHigh())
|
||||
{
|
||||
case HighGuid::Player:
|
||||
return GetPlayer(p, guid);
|
||||
case HIGHGUID_TRANSPORT:
|
||||
case HIGHGUID_MO_TRANSPORT:
|
||||
case HIGHGUID_GAMEOBJECT:
|
||||
case HighGuid::Transport:
|
||||
case HighGuid::Mo_Transport:
|
||||
case HighGuid::GameObject:
|
||||
return GetGameObject(p, guid);
|
||||
case HIGHGUID_VEHICLE:
|
||||
case HIGHGUID_UNIT:
|
||||
case HighGuid::Vehicle:
|
||||
case HighGuid::Unit:
|
||||
return GetCreature(p, guid);
|
||||
case HIGHGUID_PET:
|
||||
case HighGuid::Pet:
|
||||
return GetPet(p, guid);
|
||||
case HIGHGUID_DYNAMICOBJECT:
|
||||
case HighGuid::DynamicObject:
|
||||
return GetDynamicObject(p, guid);
|
||||
case HIGHGUID_CORPSE:
|
||||
case HighGuid::Corpse:
|
||||
return GetCorpse(p, guid);
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
Object* ObjectAccessor::GetObjectByTypeMask(WorldObject const& p, uint64 guid, uint32 typemask)
|
||||
{
|
||||
switch (GUID_HIPART(guid))
|
||||
{
|
||||
case HIGHGUID_ITEM:
|
||||
if (typemask & TYPEMASK_ITEM && p.GetTypeId() == TYPEID_PLAYER)
|
||||
return ((Player const&)p).GetItemByGuid(guid);
|
||||
break;
|
||||
case HIGHGUID_PLAYER:
|
||||
if (typemask & TYPEMASK_PLAYER)
|
||||
return GetPlayer(p, guid);
|
||||
break;
|
||||
case HIGHGUID_TRANSPORT:
|
||||
case HIGHGUID_MO_TRANSPORT:
|
||||
case HIGHGUID_GAMEOBJECT:
|
||||
if (typemask & TYPEMASK_GAMEOBJECT)
|
||||
return GetGameObject(p, guid);
|
||||
break;
|
||||
case HIGHGUID_UNIT:
|
||||
case HIGHGUID_VEHICLE:
|
||||
if (typemask & TYPEMASK_UNIT)
|
||||
return GetCreature(p, guid);
|
||||
break;
|
||||
case HIGHGUID_PET:
|
||||
if (typemask & TYPEMASK_UNIT)
|
||||
return GetPet(p, guid);
|
||||
break;
|
||||
case HIGHGUID_DYNAMICOBJECT:
|
||||
if (typemask & TYPEMASK_DYNAMICOBJECT)
|
||||
return GetDynamicObject(p, guid);
|
||||
break;
|
||||
case HIGHGUID_CORPSE:
|
||||
break;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Corpse* ObjectAccessor::GetCorpse(WorldObject const& u, uint64 guid)
|
||||
Object* ObjectAccessor::GetObjectByTypeMask(WorldObject const& p, ObjectGuid const guid, uint32 typemask)
|
||||
{
|
||||
return GetObjectInMap(guid, u.GetMap(), (Corpse*)nullptr);
|
||||
switch (guid.GetHigh())
|
||||
{
|
||||
case HighGuid::Item:
|
||||
if (typemask & TYPEMASK_ITEM && p.GetTypeId() == TYPEID_PLAYER)
|
||||
return ((Player const&)p).GetItemByGuid(guid);
|
||||
break;
|
||||
case HighGuid::Player:
|
||||
if (typemask & TYPEMASK_PLAYER)
|
||||
return GetPlayer(p, guid);
|
||||
break;
|
||||
case HighGuid::Transport:
|
||||
case HighGuid::Mo_Transport:
|
||||
case HighGuid::GameObject:
|
||||
if (typemask & TYPEMASK_GAMEOBJECT)
|
||||
return GetGameObject(p, guid);
|
||||
break;
|
||||
case HighGuid::Unit:
|
||||
case HighGuid::Vehicle:
|
||||
if (typemask & TYPEMASK_UNIT)
|
||||
return GetCreature(p, guid);
|
||||
break;
|
||||
case HighGuid::Pet:
|
||||
if (typemask & TYPEMASK_UNIT)
|
||||
return GetPet(p, guid);
|
||||
break;
|
||||
case HighGuid::DynamicObject:
|
||||
if (typemask & TYPEMASK_DYNAMICOBJECT)
|
||||
return GetDynamicObject(p, guid);
|
||||
break;
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
GameObject* ObjectAccessor::GetGameObject(WorldObject const& u, uint64 guid)
|
||||
Corpse* ObjectAccessor::GetCorpse(WorldObject const& u, ObjectGuid const guid)
|
||||
{
|
||||
return GetObjectInMap(guid, u.GetMap(), (GameObject*)nullptr);
|
||||
return u.GetMap()->GetCorpse(guid);
|
||||
}
|
||||
|
||||
Transport* ObjectAccessor::GetTransport(WorldObject const& u, uint64 guid)
|
||||
GameObject* ObjectAccessor::GetGameObject(WorldObject const& u, ObjectGuid const guid)
|
||||
{
|
||||
if (GUID_HIPART(guid) != HIGHGUID_MO_TRANSPORT && GUID_HIPART(guid) != HIGHGUID_TRANSPORT)
|
||||
return nullptr;
|
||||
|
||||
GameObject* go = GetGameObject(u, guid);
|
||||
return go ? go->ToTransport() : nullptr;
|
||||
return u.GetMap()->GetGameObject(guid);
|
||||
}
|
||||
|
||||
DynamicObject* ObjectAccessor::GetDynamicObject(WorldObject const& u, uint64 guid)
|
||||
Transport* ObjectAccessor::GetTransport(WorldObject const& u, ObjectGuid const guid)
|
||||
{
|
||||
return GetObjectInMap(guid, u.GetMap(), (DynamicObject*)nullptr);
|
||||
return u.GetMap()->GetTransport(guid);
|
||||
}
|
||||
|
||||
Unit* ObjectAccessor::GetUnit(WorldObject const& u, uint64 guid)
|
||||
DynamicObject* ObjectAccessor::GetDynamicObject(WorldObject const& u, ObjectGuid const guid)
|
||||
{
|
||||
return GetObjectInMap(guid, u.GetMap(), (Unit*)nullptr);
|
||||
return u.GetMap()->GetDynamicObject(guid);
|
||||
}
|
||||
|
||||
Creature* ObjectAccessor::GetCreature(WorldObject const& u, uint64 guid)
|
||||
Unit* ObjectAccessor::GetUnit(WorldObject const& u, ObjectGuid const guid)
|
||||
{
|
||||
return GetObjectInMap(guid, u.GetMap(), (Creature*)nullptr);
|
||||
}
|
||||
if (guid.IsPlayer())
|
||||
return GetPlayer(u, guid);
|
||||
|
||||
Pet* ObjectAccessor::GetPet(WorldObject const& u, uint64 guid)
|
||||
{
|
||||
return GetObjectInMap(guid, u.GetMap(), (Pet*)nullptr);
|
||||
}
|
||||
|
||||
Player* ObjectAccessor::GetPlayer(WorldObject const& u, uint64 guid)
|
||||
{
|
||||
return GetObjectInMap(guid, u.GetMap(), (Player*)nullptr);
|
||||
}
|
||||
|
||||
Creature* ObjectAccessor::GetCreatureOrPetOrVehicle(WorldObject const& u, uint64 guid)
|
||||
{
|
||||
if (IS_PET_GUID(guid))
|
||||
if (guid.IsPet())
|
||||
return GetPet(u, guid);
|
||||
|
||||
if (IS_CRE_OR_VEH_GUID(guid))
|
||||
return GetCreature(u, guid);
|
||||
}
|
||||
|
||||
Creature* ObjectAccessor::GetCreature(WorldObject const& u, ObjectGuid const guid)
|
||||
{
|
||||
return u.GetMap()->GetCreature(guid);
|
||||
}
|
||||
|
||||
Pet* ObjectAccessor::GetPet(WorldObject const& u, ObjectGuid const guid)
|
||||
{
|
||||
return u.GetMap()->GetPet(guid);
|
||||
}
|
||||
|
||||
Player* ObjectAccessor::GetPlayer(Map const* m, ObjectGuid const guid)
|
||||
{
|
||||
if (Player * player = HashMapHolder<Player>::Find(guid))
|
||||
if (player->IsInWorld() && player->GetMap() == m)
|
||||
return player;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Player* ObjectAccessor::GetPlayer(WorldObject const& u, ObjectGuid const guid)
|
||||
{
|
||||
return GetPlayer(u.GetMap(), guid);
|
||||
}
|
||||
|
||||
Creature* ObjectAccessor::GetCreatureOrPetOrVehicle(WorldObject const& u, ObjectGuid const guid)
|
||||
{
|
||||
if (guid.IsPet())
|
||||
return GetPet(u, guid);
|
||||
|
||||
if (guid.IsCreatureOrVehicle())
|
||||
return GetCreature(u, guid);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Pet* ObjectAccessor::FindPet(uint64 guid)
|
||||
Player* ObjectAccessor::FindPlayer(ObjectGuid const guid)
|
||||
{
|
||||
return GetObjectInWorld(guid, (Pet*)nullptr);
|
||||
Player* player = HashMapHolder<Player>::Find(guid);
|
||||
return player && player->IsInWorld() ? player : nullptr;
|
||||
}
|
||||
|
||||
Player* ObjectAccessor::FindPlayer(uint64 guid)
|
||||
Player* ObjectAccessor::FindPlayerByLowGUID(ObjectGuid::LowType lowguid)
|
||||
{
|
||||
return GetObjectInWorld(guid, (Player*)nullptr);
|
||||
ObjectGuid guid = ObjectGuid::Create<HighGuid::Player>(lowguid);
|
||||
return ObjectAccessor::FindPlayer(guid);
|
||||
}
|
||||
|
||||
Player* ObjectAccessor::FindPlayerInOrOutOfWorld(uint64 guid)
|
||||
{
|
||||
return GetObjectInOrOutOfWorld(guid, (Player*)nullptr);
|
||||
}
|
||||
|
||||
Unit* ObjectAccessor::FindUnit(uint64 guid)
|
||||
{
|
||||
return GetObjectInWorld(guid, (Unit*)nullptr);
|
||||
}
|
||||
|
||||
Player* ObjectAccessor::FindConnectedPlayer(uint64 const& guid)
|
||||
Player* ObjectAccessor::FindConnectedPlayer(ObjectGuid const guid)
|
||||
{
|
||||
return HashMapHolder<Player>::Find(guid);
|
||||
}
|
||||
|
||||
Player* ObjectAccessor::FindPlayerByName(std::string const& name, bool checkInWorld)
|
||||
{
|
||||
// pussywizard: optimization
|
||||
std::string nameStr = name;
|
||||
std::transform(nameStr.begin(), nameStr.end(), nameStr.begin(), ::tolower);
|
||||
std::map<std::string, Player*>::iterator itr = playerNameToPlayerPointer.find(nameStr);
|
||||
if (itr != playerNameToPlayerPointer.end())
|
||||
if (!checkInWorld || itr->second->IsInWorld())
|
||||
return itr->second;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void ObjectAccessor::SaveAllPlayers()
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> lock(*HashMapHolder<Player>::GetLock());
|
||||
@@ -240,354 +261,25 @@ void ObjectAccessor::SaveAllPlayers()
|
||||
itr->second->SaveToDB(false, false);
|
||||
}
|
||||
|
||||
Corpse* ObjectAccessor::GetCorpseForPlayerGUID(uint64 guid)
|
||||
Player* ObjectAccessor::FindPlayerByName(std::string const& name, bool checkInWorld)
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> lock(i_corpseLock);
|
||||
|
||||
Player2CorpsesMapType::iterator iter = i_player2corpse.find(guid);
|
||||
if (iter == i_player2corpse.end())
|
||||
return nullptr;
|
||||
|
||||
ASSERT(iter->second->GetType() != CORPSE_BONES);
|
||||
|
||||
return iter->second;
|
||||
}
|
||||
|
||||
void ObjectAccessor::RemoveCorpse(Corpse* corpse, bool final)
|
||||
{
|
||||
ASSERT(corpse && corpse->GetType() != CORPSE_BONES);
|
||||
|
||||
if (!final)
|
||||
{
|
||||
std::unique_lock<std::shared_mutex> guard(i_corpseLock);
|
||||
Player2CorpsesMapType::iterator iter = i_player2corpse.find(corpse->GetOwnerGUID());
|
||||
if (iter == i_player2corpse.end())
|
||||
return;
|
||||
i_player2corpse.erase(iter);
|
||||
AddDelayedCorpseAction(corpse, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
//TODO: more works need to be done for corpse and other world object
|
||||
if (Map* map = corpse->FindMap())
|
||||
{
|
||||
// xinef: ok, should be called in both cases
|
||||
corpse->DestroyForNearbyPlayers();
|
||||
if (corpse->IsInGrid())
|
||||
map->RemoveFromMap(corpse, false);
|
||||
else
|
||||
{
|
||||
corpse->RemoveFromWorld();
|
||||
corpse->ResetMap();
|
||||
}
|
||||
}
|
||||
else
|
||||
corpse->RemoveFromWorld();
|
||||
|
||||
// Critical section
|
||||
{
|
||||
std::unique_lock<std::shared_mutex> guard(i_corpseLock);
|
||||
|
||||
// build mapid*cellid -> guid_set map
|
||||
CellCoord cellCoord = acore::ComputeCellCoord(corpse->GetPositionX(), corpse->GetPositionY());
|
||||
sObjectMgr->DeleteCorpseCellData(corpse->GetMapId(), cellCoord.GetId(), GUID_LOPART(corpse->GetOwnerGUID()));
|
||||
}
|
||||
|
||||
delete corpse; // pussywizard: as it is delayed now, delete is moved here (previously in ConvertCorpseForPlayer)
|
||||
}
|
||||
|
||||
void ObjectAccessor::AddCorpse(Corpse* corpse)
|
||||
{
|
||||
ASSERT(corpse && corpse->GetType() != CORPSE_BONES);
|
||||
|
||||
// Critical section
|
||||
{
|
||||
std::unique_lock<std::shared_mutex> guard(i_corpseLock);
|
||||
|
||||
ASSERT(i_player2corpse.find(corpse->GetOwnerGUID()) == i_player2corpse.end());
|
||||
i_player2corpse[corpse->GetOwnerGUID()] = corpse;
|
||||
|
||||
// build mapid*cellid -> guid_set map
|
||||
CellCoord cellCoord = acore::ComputeCellCoord(corpse->GetPositionX(), corpse->GetPositionY());
|
||||
sObjectMgr->AddCorpseCellData(corpse->GetMapId(), cellCoord.GetId(), GUID_LOPART(corpse->GetOwnerGUID()), corpse->GetInstanceId());
|
||||
}
|
||||
}
|
||||
|
||||
void ObjectAccessor::AddCorpsesToGrid(GridCoord const& gridpair, GridType& grid, Map* map)
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> guard(i_corpseLock);
|
||||
|
||||
for (Player2CorpsesMapType::iterator iter = i_player2corpse.begin(); iter != i_player2corpse.end(); ++iter)
|
||||
{
|
||||
// We need this check otherwise a corpose may be added to a grid twice
|
||||
if (iter->second->IsInGrid())
|
||||
continue;
|
||||
|
||||
if (iter->second->GetGridCoord() == gridpair)
|
||||
{
|
||||
// verify, if the corpse in our instance (add only corpses which are)
|
||||
if (map->Instanceable())
|
||||
{
|
||||
if (iter->second->GetInstanceId() == map->GetInstanceId())
|
||||
grid.AddWorldObject(iter->second);
|
||||
}
|
||||
else
|
||||
grid.AddWorldObject(iter->second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Corpse* ObjectAccessor::ConvertCorpseForPlayer(uint64 player_guid, bool insignia /*=false*/)
|
||||
{
|
||||
Corpse* corpse = GetCorpseForPlayerGUID(player_guid);
|
||||
if (!corpse)
|
||||
{
|
||||
//in fact this function is called from several places
|
||||
//even when player doesn't have a corpse, not an error
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
|
||||
LOG_DEBUG("server", "Deleting Corpse and spawned bones.");
|
||||
#endif
|
||||
|
||||
// Map can be nullptr
|
||||
Map* map = corpse->FindMap();
|
||||
bool inWorld = corpse->IsInWorld();
|
||||
|
||||
// remove corpse from player_guid -> corpse map and from current map
|
||||
RemoveCorpse(corpse);
|
||||
|
||||
// remove corpse from DB
|
||||
SQLTransaction trans = CharacterDatabase.BeginTransaction();
|
||||
corpse->DeleteFromDB(trans);
|
||||
CharacterDatabase.CommitTransaction(trans);
|
||||
|
||||
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 && corpse->IsPositionValid() && inWorld && (insignia ||
|
||||
(map->IsBattlegroundOrArena() ? sWorld->getBoolConfig(CONFIG_DEATH_BONES_BG_OR_ARENA) : sWorld->getBoolConfig(CONFIG_DEATH_BONES_WORLD))) &&
|
||||
!map->IsRemovalGrid(corpse->GetPositionX(), corpse->GetPositionY()))
|
||||
{
|
||||
// Create bones, don't change Corpse
|
||||
bones = new Corpse;
|
||||
bones->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_CORPSE), map);
|
||||
|
||||
for (uint8 i = OBJECT_FIELD_TYPE + 1; i < CORPSE_END; ++i) // don't overwrite guid and object type
|
||||
bones->SetUInt32Value(i, corpse->GetUInt32Value(i));
|
||||
|
||||
bones->SetGridCoord(corpse->GetGridCoord());
|
||||
// bones->m_time = m_time; // don't overwrite time
|
||||
// bones->m_type = m_type; // don't overwrite type
|
||||
bones->Relocate(corpse->GetPositionX(), corpse->GetPositionY(), corpse->GetPositionZ(), corpse->GetOrientation());
|
||||
bones->SetPhaseMask(corpse->GetPhaseMask(), false);
|
||||
|
||||
bones->SetUInt32Value(CORPSE_FIELD_FLAGS, CORPSE_FLAG_UNK2 | CORPSE_FLAG_BONES);
|
||||
bones->SetUInt64Value(CORPSE_FIELD_OWNER, 0);
|
||||
|
||||
for (uint8 i = 0; i < EQUIPMENT_SLOT_END; ++i)
|
||||
{
|
||||
if (corpse->GetUInt32Value(CORPSE_FIELD_ITEM + i))
|
||||
bones->SetUInt32Value(CORPSE_FIELD_ITEM + i, 0);
|
||||
}
|
||||
|
||||
// add bones in grid store if grid loaded where corpse placed
|
||||
if (insignia) // pussywizard: in case of insignia we need bones right now, map is the same so not a problem
|
||||
map->AddToMap(bones);
|
||||
else
|
||||
{
|
||||
bones->ResetMap();
|
||||
sObjectAccessor->AddDelayedCorpseAction(bones, 1, map->GetId(), map->GetInstanceId());
|
||||
}
|
||||
|
||||
// pussywizard: for deleting bones
|
||||
std::unique_lock<std::shared_mutex> guard(i_corpseLock);
|
||||
i_playerBones.push_back(bones->GetGUID());
|
||||
}
|
||||
|
||||
// all references to the corpse should be removed at this point
|
||||
//delete corpse; // pussywizard: deleting corpse is delayed (crashfix)
|
||||
|
||||
return bones;
|
||||
}
|
||||
|
||||
void ObjectAccessor::RemoveOldCorpses()
|
||||
{
|
||||
time_t now = time(nullptr);
|
||||
Player2CorpsesMapType::iterator next;
|
||||
for (Player2CorpsesMapType::iterator itr = i_player2corpse.begin(); itr != i_player2corpse.end(); itr = next)
|
||||
{
|
||||
next = itr;
|
||||
++next;
|
||||
|
||||
if (!itr->second->IsExpired(now))
|
||||
continue;
|
||||
|
||||
ConvertCorpseForPlayer(itr->first);
|
||||
}
|
||||
|
||||
// pussywizard: for deleting bones
|
||||
std::list<uint64>::iterator next2;
|
||||
std::unique_lock<std::shared_mutex> guard(i_corpseLock);
|
||||
for (std::list<uint64>::iterator itr = i_playerBones.begin(); itr != i_playerBones.end(); itr = next2)
|
||||
{
|
||||
next2 = itr;
|
||||
++next2;
|
||||
|
||||
Corpse* c = GetObjectInWorld((*itr), (Corpse*)nullptr);
|
||||
if (c)
|
||||
{
|
||||
if (!c->IsExpired(now))
|
||||
continue;
|
||||
|
||||
if (Map* map = c->FindMap())
|
||||
{
|
||||
if (c->IsInGrid())
|
||||
map->RemoveFromMap(c, false);
|
||||
else
|
||||
{
|
||||
c->DestroyForNearbyPlayers();
|
||||
c->RemoveFromWorld();
|
||||
c->ResetMap();
|
||||
}
|
||||
}
|
||||
else
|
||||
c->RemoveFromWorld();
|
||||
}
|
||||
|
||||
i_playerBones.erase(itr);
|
||||
}
|
||||
}
|
||||
|
||||
void ObjectAccessor::AddDelayedCorpseAction(Corpse* corpse, uint8 action, uint32 mapId, uint32 instanceId)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(DelayedCorpseLock);
|
||||
i_delayedCorpseActions.push_back(DelayedCorpseAction(corpse, action, mapId, instanceId));
|
||||
}
|
||||
|
||||
void ObjectAccessor::ProcessDelayedCorpseActions()
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(DelayedCorpseLock);
|
||||
for (std::list<DelayedCorpseAction>::iterator itr = i_delayedCorpseActions.begin(); itr != i_delayedCorpseActions.end(); ++itr)
|
||||
{
|
||||
DelayedCorpseAction a = (*itr);
|
||||
switch (a._action)
|
||||
{
|
||||
case 0: // remove corpse
|
||||
RemoveCorpse(a._corpse, true);
|
||||
break;
|
||||
case 1: // add bones
|
||||
if (Map* map = sMapMgr->FindMap(a._mapId, a._instanceId))
|
||||
if (!map->IsRemovalGrid(a._corpse->GetPositionX(), a._corpse->GetPositionY()))
|
||||
{
|
||||
a._corpse->SetMap(map);
|
||||
map->AddToMap(a._corpse);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
i_delayedCorpseActions.clear();
|
||||
}
|
||||
|
||||
void ObjectAccessor::Update(uint32 /*diff*/)
|
||||
{
|
||||
UpdateDataMapType update_players;
|
||||
UpdatePlayerSet player_set;
|
||||
|
||||
while (!i_objects.empty())
|
||||
{
|
||||
Object* obj = *i_objects.begin();
|
||||
ASSERT(obj && obj->IsInWorld());
|
||||
i_objects.erase(i_objects.begin());
|
||||
obj->BuildUpdate(update_players, player_set);
|
||||
}
|
||||
|
||||
WorldPacket packet; // here we allocate a std::vector with a size of 0x10000
|
||||
for (UpdateDataMapType::iterator iter = update_players.begin(); iter != update_players.end(); ++iter)
|
||||
{
|
||||
iter->second.BuildPacket(&packet);
|
||||
iter->first->GetSession()->SendPacket(&packet);
|
||||
packet.clear(); // clean the string
|
||||
}
|
||||
}
|
||||
|
||||
void Map::BuildAndSendUpdateForObjects()
|
||||
{
|
||||
UpdateDataMapType update_players;
|
||||
UpdatePlayerSet player_set;
|
||||
|
||||
while (!i_objectsToUpdate.empty())
|
||||
{
|
||||
Object* obj = *i_objectsToUpdate.begin();
|
||||
ASSERT(obj && obj->IsInWorld());
|
||||
i_objectsToUpdate.erase(i_objectsToUpdate.begin());
|
||||
obj->BuildUpdate(update_players, player_set);
|
||||
}
|
||||
|
||||
WorldPacket packet; // here we allocate a std::vector with a size of 0x10000
|
||||
for (UpdateDataMapType::iterator iter = update_players.begin(); iter != update_players.end(); ++iter)
|
||||
{
|
||||
iter->second.BuildPacket(&packet);
|
||||
iter->first->GetSession()->SendPacket(&packet);
|
||||
packet.clear(); // clean the string
|
||||
}
|
||||
}
|
||||
|
||||
void ObjectAccessor::UnloadAll()
|
||||
{
|
||||
for (Player2CorpsesMapType::const_iterator itr = i_player2corpse.begin(); itr != i_player2corpse.end(); ++itr)
|
||||
{
|
||||
itr->second->RemoveFromWorld();
|
||||
delete itr->second;
|
||||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
/*static*/ T* ObjectAccessor::GetObjectInWorld(uint32 mapid, float x, float y, uint64 guid, T* /*fake*/)
|
||||
{
|
||||
T* obj = HashMapHolder<T>::Find(guid);
|
||||
if (!obj || obj->GetMapId() != mapid)
|
||||
return nullptr;
|
||||
|
||||
CellCoord p = acore::ComputeCellCoord(x, y);
|
||||
if (!p.IsCoordValid())
|
||||
{
|
||||
LOG_ERROR("server", "ObjectAccessor::GetObjectInWorld: invalid coordinates supplied X:%f Y:%f grid cell [%u:%u]", x, y, p.x_coord, p.y_coord);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
CellCoord q = acore::ComputeCellCoord(obj->GetPositionX(), obj->GetPositionY());
|
||||
if (!q.IsCoordValid())
|
||||
{
|
||||
LOG_ERROR("server", "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);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int32 dx = int32(p.x_coord) - int32(q.x_coord);
|
||||
int32 dy = int32(p.y_coord) - int32(q.y_coord);
|
||||
|
||||
if (dx > -2 && dx < 2 && dy > -2 && dy < 2)
|
||||
return obj;
|
||||
if (Player* player = PlayerNameMapHolder::Find(name))
|
||||
if (!checkInWorld || player->IsInWorld())
|
||||
return player;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::map<std::string, Player*> ObjectAccessor::playerNameToPlayerPointer;
|
||||
template<>
|
||||
void ObjectAccessor::AddObject(Player* player)
|
||||
{
|
||||
HashMapHolder<Player>::Insert(player);
|
||||
PlayerNameMapHolder::Insert(player);
|
||||
}
|
||||
|
||||
/// Global definitions for the hashmap storage
|
||||
|
||||
template class HashMapHolder<Player>;
|
||||
template class HashMapHolder<Pet>;
|
||||
template class HashMapHolder<GameObject>;
|
||||
template class HashMapHolder<DynamicObject>;
|
||||
template class HashMapHolder<Creature>;
|
||||
template class HashMapHolder<Corpse>;
|
||||
|
||||
template Player* ObjectAccessor::GetObjectInWorld<Player>(uint32 mapid, float x, float y, uint64 guid, Player* /*fake*/);
|
||||
template Pet* ObjectAccessor::GetObjectInWorld<Pet>(uint32 mapid, float x, float y, uint64 guid, Pet* /*fake*/);
|
||||
template Creature* ObjectAccessor::GetObjectInWorld<Creature>(uint32 mapid, float x, float y, uint64 guid, Creature* /*fake*/);
|
||||
template Corpse* ObjectAccessor::GetObjectInWorld<Corpse>(uint32 mapid, float x, float y, uint64 guid, Corpse* /*fake*/);
|
||||
template GameObject* ObjectAccessor::GetObjectInWorld<GameObject>(uint32 mapid, float x, float y, uint64 guid, GameObject* /*fake*/);
|
||||
template DynamicObject* ObjectAccessor::GetObjectInWorld<DynamicObject>(uint32 mapid, float x, float y, uint64 guid, DynamicObject* /*fake*/);
|
||||
template<>
|
||||
void ObjectAccessor::RemoveObject(Player* player)
|
||||
{
|
||||
HashMapHolder<Player>::Remove(player);
|
||||
PlayerNameMapHolder::Remove(player);
|
||||
}
|
||||
|
||||
@@ -32,206 +32,69 @@ class MotionTransport;
|
||||
template <class T>
|
||||
class HashMapHolder
|
||||
{
|
||||
//Non instanceable only static
|
||||
HashMapHolder() { }
|
||||
|
||||
public:
|
||||
typedef std::unordered_map<uint64, T*> MapType;
|
||||
|
||||
typedef std::unordered_map<ObjectGuid, T*> MapType;
|
||||
|
||||
static void Insert(T* o);
|
||||
|
||||
static void Remove(T* o);
|
||||
static T* Find(uint64 guid);
|
||||
|
||||
static MapType& GetContainer() { return m_objectMap; }
|
||||
static T* Find(ObjectGuid guid);
|
||||
|
||||
static MapType& GetContainer();
|
||||
|
||||
static std::shared_mutex* GetLock();
|
||||
|
||||
private:
|
||||
//Non instanceable only static
|
||||
HashMapHolder() = default;
|
||||
|
||||
static MapType m_objectMap;
|
||||
};
|
||||
|
||||
/// Define the static members of HashMapHolder
|
||||
|
||||
template <class T> std::unordered_map< uint64, T* > HashMapHolder<T>::m_objectMap;
|
||||
|
||||
// pussywizard:
|
||||
class DelayedCorpseAction
|
||||
namespace ObjectAccessor
|
||||
{
|
||||
public:
|
||||
DelayedCorpseAction(Corpse* corpse, uint8 action, uint32 mapId, uint32 instanceId) : _corpse(corpse), _action(action), _mapId(mapId), _instanceId(instanceId) {}
|
||||
Corpse* _corpse;
|
||||
uint8 _action;
|
||||
uint32 _mapId;
|
||||
uint32 _instanceId;
|
||||
};
|
||||
|
||||
class ObjectAccessor
|
||||
{
|
||||
private:
|
||||
ObjectAccessor();
|
||||
~ObjectAccessor();
|
||||
ObjectAccessor(const ObjectAccessor&);
|
||||
ObjectAccessor& operator=(const ObjectAccessor&);
|
||||
|
||||
public:
|
||||
static ObjectAccessor* instance();
|
||||
// TODO: override these template functions for each holder type and add assertions
|
||||
|
||||
template<class T> static T* GetObjectInOrOutOfWorld(uint64 guid, T* /*typeSpecifier*/)
|
||||
{
|
||||
return HashMapHolder<T>::Find(guid);
|
||||
}
|
||||
|
||||
static Unit* GetObjectInOrOutOfWorld(uint64 guid, Unit* /*typeSpecifier*/)
|
||||
{
|
||||
if (IS_PLAYER_GUID(guid))
|
||||
return (Unit*)GetObjectInOrOutOfWorld(guid, (Player*)nullptr);
|
||||
|
||||
if (IS_PET_GUID(guid))
|
||||
return (Unit*)GetObjectInOrOutOfWorld(guid, (Pet*)nullptr);
|
||||
|
||||
return (Unit*)GetObjectInOrOutOfWorld(guid, (Creature*)nullptr);
|
||||
}
|
||||
|
||||
// returns object if is in world
|
||||
template<class T> static T* GetObjectInWorld(uint64 guid, T* /*typeSpecifier*/)
|
||||
{
|
||||
return HashMapHolder<T>::Find(guid);
|
||||
}
|
||||
|
||||
// Player may be not in world while in ObjectAccessor
|
||||
static Player* GetObjectInWorld(uint64 guid, Player* /*typeSpecifier*/);
|
||||
|
||||
static Unit* GetObjectInWorld(uint64 guid, Unit* /*typeSpecifier*/)
|
||||
{
|
||||
if (IS_PLAYER_GUID(guid))
|
||||
return (Unit*)GetObjectInWorld(guid, (Player*)nullptr);
|
||||
|
||||
if (IS_PET_GUID(guid))
|
||||
return (Unit*)GetObjectInWorld(guid, (Pet*)nullptr);
|
||||
|
||||
return (Unit*)GetObjectInWorld(guid, (Creature*)nullptr);
|
||||
}
|
||||
|
||||
// returns object if is in map
|
||||
template<class T> static T* GetObjectInMap(uint64 guid, Map* map, T* /*typeSpecifier*/)
|
||||
{
|
||||
ASSERT(map);
|
||||
if (T* obj = GetObjectInWorld(guid, (T*)nullptr))
|
||||
if (obj->GetMap() == map)
|
||||
return obj;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
static T* GetObjectInWorld(uint32 mapid, float x, float y, uint64 guid, T* /*fake*/);
|
||||
|
||||
// these functions return objects only if in map of specified object
|
||||
static WorldObject* GetWorldObject(WorldObject const&, uint64);
|
||||
static Object* GetObjectByTypeMask(WorldObject const&, uint64, uint32 typemask);
|
||||
static Corpse* GetCorpse(WorldObject const& u, uint64 guid);
|
||||
static GameObject* GetGameObject(WorldObject const& u, uint64 guid);
|
||||
static Transport* GetTransport(WorldObject const& u, uint64 guid);
|
||||
static DynamicObject* GetDynamicObject(WorldObject const& u, uint64 guid);
|
||||
static Unit* GetUnit(WorldObject const&, uint64 guid);
|
||||
static Creature* GetCreature(WorldObject const& u, uint64 guid);
|
||||
static Pet* GetPet(WorldObject const&, uint64 guid);
|
||||
static Player* GetPlayer(WorldObject const&, uint64 guid);
|
||||
static Creature* GetCreatureOrPetOrVehicle(WorldObject const&, uint64);
|
||||
WorldObject* GetWorldObject(WorldObject const&, ObjectGuid const guid);
|
||||
Object* GetObjectByTypeMask(WorldObject const&, ObjectGuid const guid, uint32 typemask);
|
||||
Corpse* GetCorpse(WorldObject const& u, ObjectGuid const guid);
|
||||
GameObject* GetGameObject(WorldObject const& u, ObjectGuid const guid);
|
||||
Transport* GetTransport(WorldObject const& u, ObjectGuid const guid);
|
||||
DynamicObject* GetDynamicObject(WorldObject const& u, ObjectGuid const guid);
|
||||
Unit* GetUnit(WorldObject const&, ObjectGuid const guid);
|
||||
Creature* GetCreature(WorldObject const& u, ObjectGuid const guid);
|
||||
Pet* GetPet(WorldObject const&, ObjectGuid const guid);
|
||||
Player* GetPlayer(Map const*, ObjectGuid const guid);
|
||||
Player* GetPlayer(WorldObject const&, ObjectGuid const guid);
|
||||
Creature* GetCreatureOrPetOrVehicle(WorldObject const&, ObjectGuid const);
|
||||
|
||||
// these functions return objects if found in whole world
|
||||
// ACCESS LIKE THAT IS NOT THREAD SAFE
|
||||
static Pet* FindPet(uint64);
|
||||
static Player* FindPlayer(uint64);
|
||||
static Player* FindPlayerInOrOutOfWorld(uint64 m_guid);
|
||||
|
||||
static Unit* FindUnit(uint64);
|
||||
static Player* FindConnectedPlayer(uint64 const&);
|
||||
static Player* FindPlayerByName(std::string const& name, bool checkInWorld = true);
|
||||
static std::map<std::string, Player*> playerNameToPlayerPointer; // pussywizard: optimization
|
||||
Player* FindPlayer(ObjectGuid const guid);
|
||||
Player* FindPlayerByLowGUID(ObjectGuid::LowType lowguid);
|
||||
Player* FindConnectedPlayer(ObjectGuid const guid);
|
||||
Player* FindPlayerByName(std::string const& name, bool checkInWorld = true);
|
||||
|
||||
// when using this, you must use the hashmapholder's lock
|
||||
static HashMapHolder<Player>::MapType const& GetPlayers()
|
||||
{
|
||||
return HashMapHolder<Player>::GetContainer();
|
||||
}
|
||||
HashMapHolder<Player>::MapType const& GetPlayers();
|
||||
|
||||
// when using this, you must use the hashmapholder's lock
|
||||
static HashMapHolder<Creature>::MapType const& GetCreatures()
|
||||
{
|
||||
return HashMapHolder<Creature>::GetContainer();
|
||||
}
|
||||
|
||||
// when using this, you must use the hashmapholder's lock
|
||||
static HashMapHolder<GameObject>::MapType const& GetGameObjects()
|
||||
{
|
||||
return HashMapHolder<GameObject>::GetContainer();
|
||||
}
|
||||
|
||||
template<class T> static void AddObject(T* object)
|
||||
template<class T>
|
||||
void AddObject(T* object)
|
||||
{
|
||||
HashMapHolder<T>::Insert(object);
|
||||
}
|
||||
|
||||
template<class T> static void RemoveObject(T* object)
|
||||
template<class T>
|
||||
void RemoveObject(T* object)
|
||||
{
|
||||
HashMapHolder<T>::Remove(object);
|
||||
}
|
||||
|
||||
static void SaveAllPlayers();
|
||||
void SaveAllPlayers();
|
||||
|
||||
//non-static functions
|
||||
void AddUpdateObject(Object* obj)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(i_objectLock);
|
||||
if (obj->GetTypeId() < TYPEID_UNIT) // these are not in map: TYPEID_OBJECT, TYPEID_ITEM, TYPEID_CONTAINER
|
||||
i_objects.insert(obj);
|
||||
else
|
||||
((WorldObject*)obj)->FindMap()->i_objectsToUpdate.insert(obj);
|
||||
}
|
||||
template<>
|
||||
void AddObject(Player* player);
|
||||
|
||||
void RemoveUpdateObject(Object* obj)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(i_objectLock);
|
||||
if (obj->GetTypeId() < TYPEID_UNIT) // these are not in map: TYPEID_OBJECT, TYPEID_ITEM, TYPEID_CONTAINER
|
||||
i_objects.erase(obj);
|
||||
else
|
||||
((WorldObject*)obj)->FindMap()->i_objectsToUpdate.erase(obj);
|
||||
}
|
||||
|
||||
//Thread safe
|
||||
Corpse* GetCorpseForPlayerGUID(uint64 guid);
|
||||
void RemoveCorpse(Corpse* corpse, bool final = false);
|
||||
void AddCorpse(Corpse* corpse);
|
||||
void AddCorpsesToGrid(GridCoord const& gridpair, GridType& grid, Map* map);
|
||||
Corpse* ConvertCorpseForPlayer(uint64 player_guid, bool insignia = false);
|
||||
|
||||
//Thread unsafe
|
||||
void Update(uint32 diff);
|
||||
void RemoveOldCorpses();
|
||||
void UnloadAll();
|
||||
|
||||
// pussywizard: crashfix for corpses
|
||||
void AddDelayedCorpseAction(Corpse* corpse, uint8 action, uint32 mapId = 0, uint32 instanceId = 0);
|
||||
void ProcessDelayedCorpseActions();
|
||||
|
||||
private:
|
||||
static void _buildChangeObjectForPlayer(WorldObject*, UpdateDataMapType&);
|
||||
static void _buildPacket(Player*, Object*, UpdateDataMapType&);
|
||||
void _update();
|
||||
|
||||
typedef std::unordered_map<uint64, Corpse*> Player2CorpsesMapType;
|
||||
typedef std::unordered_map<Player*, UpdateData>::value_type UpdateDataValueType;
|
||||
|
||||
std::unordered_set<Object*> i_objects;
|
||||
Player2CorpsesMapType i_player2corpse;
|
||||
std::list<uint64> i_playerBones;
|
||||
|
||||
std::mutex i_objectLock;
|
||||
std::shared_mutex i_corpseLock;
|
||||
std::list<DelayedCorpseAction> i_delayedCorpseActions;
|
||||
mutable std::mutex DelayedCorpseLock;
|
||||
template<>
|
||||
void RemoveObject(Player* player);
|
||||
};
|
||||
|
||||
#define sObjectAccessor ObjectAccessor::instance()
|
||||
|
||||
#endif
|
||||
|
||||
@@ -281,18 +281,10 @@ bool SpellClickInfo::IsFitToRequirements(Unit const* clicker, Unit const* clicke
|
||||
ObjectMgr::ObjectMgr():
|
||||
_auctionId(1),
|
||||
_equipmentSetGuid(1),
|
||||
_itemTextId(1),
|
||||
_mailId(1),
|
||||
_hiPetNumber(1),
|
||||
_hiCharGuid(1),
|
||||
_hiCreatureGuid(1),
|
||||
_hiPetGuid(1),
|
||||
_hiVehicleGuid(1),
|
||||
_hiItemGuid(1),
|
||||
_hiGoGuid(1),
|
||||
_hiDoGuid(1),
|
||||
_hiCorpseGuid(1),
|
||||
_hiMoTransGuid(1),
|
||||
_creatureSpawnId(1),
|
||||
_gameObjectSpawnId(1),
|
||||
DBCLocaleIndex(LOCALE_enUS)
|
||||
{
|
||||
for (uint8 i = 0; i < MAX_CLASSES; ++i)
|
||||
@@ -1149,7 +1141,7 @@ void ObjectMgr::LoadCreatureAddons()
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
|
||||
uint32 guid = fields[0].GetUInt32();
|
||||
ObjectGuid::LowType guid = fields[0].GetUInt32();
|
||||
|
||||
CreatureData const* creData = GetCreatureData(guid);
|
||||
if (!creData)
|
||||
@@ -1228,7 +1220,7 @@ void ObjectMgr::LoadGameObjectAddons()
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
|
||||
uint32 guid = fields[0].GetUInt32();
|
||||
ObjectGuid::LowType guid = fields[0].GetUInt32();
|
||||
|
||||
const GameObjectData* goData = GetGOData(guid);
|
||||
if (!goData)
|
||||
@@ -1261,7 +1253,7 @@ void ObjectMgr::LoadGameObjectAddons()
|
||||
LOG_INFO("server", " ");
|
||||
}
|
||||
|
||||
GameObjectAddon const* ObjectMgr::GetGameObjectAddon(uint32 lowguid)
|
||||
GameObjectAddon const* ObjectMgr::GetGameObjectAddon(ObjectGuid::LowType lowguid)
|
||||
{
|
||||
GameObjectAddonContainer::const_iterator itr = _gameObjectAddonStore.find(lowguid);
|
||||
if (itr != _gameObjectAddonStore.end())
|
||||
@@ -1270,7 +1262,7 @@ GameObjectAddon const* ObjectMgr::GetGameObjectAddon(uint32 lowguid)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
CreatureAddon const* ObjectMgr::GetCreatureAddon(uint32 lowguid)
|
||||
CreatureAddon const* ObjectMgr::GetCreatureAddon(ObjectGuid::LowType lowguid)
|
||||
{
|
||||
CreatureAddonContainer::const_iterator itr = _creatureAddonStore.find(lowguid);
|
||||
if (itr != _creatureAddonStore.end())
|
||||
@@ -1528,11 +1520,11 @@ void ObjectMgr::LoadLinkedRespawn()
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
|
||||
uint32 guidLow = fields[0].GetUInt32();
|
||||
uint32 linkedGuidLow = fields[1].GetUInt32();
|
||||
ObjectGuid::LowType guidLow = fields[0].GetUInt32();
|
||||
ObjectGuid::LowType linkedGuidLow = fields[1].GetUInt32();
|
||||
uint8 linkType = fields[2].GetUInt8();
|
||||
|
||||
uint64 guid = 0, linkedGuid = 0;
|
||||
ObjectGuid guid, linkedGuid;
|
||||
bool error = false;
|
||||
switch (linkType)
|
||||
{
|
||||
@@ -1569,8 +1561,8 @@ void ObjectMgr::LoadLinkedRespawn()
|
||||
break;
|
||||
}
|
||||
|
||||
guid = MAKE_NEW_GUID(guidLow, slave->id, HIGHGUID_UNIT);
|
||||
linkedGuid = MAKE_NEW_GUID(linkedGuidLow, master->id, HIGHGUID_UNIT);
|
||||
guid = ObjectGuid::Create<HighGuid::Unit>(slave->id, guidLow);
|
||||
linkedGuid = ObjectGuid::Create<HighGuid::Unit>(master->id, linkedGuidLow);
|
||||
break;
|
||||
}
|
||||
case CREATURE_TO_GO:
|
||||
@@ -1606,8 +1598,8 @@ void ObjectMgr::LoadLinkedRespawn()
|
||||
break;
|
||||
}
|
||||
|
||||
guid = MAKE_NEW_GUID(guidLow, slave->id, HIGHGUID_UNIT);
|
||||
linkedGuid = MAKE_NEW_GUID(linkedGuidLow, master->id, HIGHGUID_GAMEOBJECT);
|
||||
guid = ObjectGuid::Create<HighGuid::Unit>(slave->id, guidLow);
|
||||
linkedGuid = ObjectGuid::Create<HighGuid::GameObject>(master->id, linkedGuidLow);
|
||||
break;
|
||||
}
|
||||
case GO_TO_GO:
|
||||
@@ -1643,8 +1635,8 @@ void ObjectMgr::LoadLinkedRespawn()
|
||||
break;
|
||||
}
|
||||
|
||||
guid = MAKE_NEW_GUID(guidLow, slave->id, HIGHGUID_GAMEOBJECT);
|
||||
linkedGuid = MAKE_NEW_GUID(linkedGuidLow, master->id, HIGHGUID_GAMEOBJECT);
|
||||
guid = ObjectGuid::Create<HighGuid::GameObject>(slave->id, guidLow);
|
||||
linkedGuid = ObjectGuid::Create<HighGuid::GameObject>(master->id, linkedGuidLow);
|
||||
break;
|
||||
}
|
||||
case GO_TO_CREATURE:
|
||||
@@ -1680,8 +1672,8 @@ void ObjectMgr::LoadLinkedRespawn()
|
||||
break;
|
||||
}
|
||||
|
||||
guid = MAKE_NEW_GUID(guidLow, slave->id, HIGHGUID_GAMEOBJECT);
|
||||
linkedGuid = MAKE_NEW_GUID(linkedGuidLow, master->id, HIGHGUID_UNIT);
|
||||
guid = ObjectGuid::Create<HighGuid::GameObject>(slave->id, guidLow);
|
||||
linkedGuid = ObjectGuid::Create<HighGuid::Unit>(master->id, linkedGuidLow);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1694,13 +1686,13 @@ void ObjectMgr::LoadLinkedRespawn()
|
||||
LOG_INFO("server", " ");
|
||||
}
|
||||
|
||||
bool ObjectMgr::SetCreatureLinkedRespawn(uint32 guidLow, uint32 linkedGuidLow)
|
||||
bool ObjectMgr::SetCreatureLinkedRespawn(ObjectGuid::LowType guidLow, ObjectGuid::LowType linkedGuidLow)
|
||||
{
|
||||
if (!guidLow)
|
||||
return false;
|
||||
|
||||
const CreatureData* master = GetCreatureData(guidLow);
|
||||
uint64 guid = MAKE_NEW_GUID(guidLow, master->id, HIGHGUID_UNIT);
|
||||
CreatureData const* master = GetCreatureData(guidLow);
|
||||
ObjectGuid guid = ObjectGuid::Create<HighGuid::Unit>(master->id, guidLow);
|
||||
|
||||
if (!linkedGuidLow) // we're removing the linking
|
||||
{
|
||||
@@ -1711,14 +1703,14 @@ bool ObjectMgr::SetCreatureLinkedRespawn(uint32 guidLow, uint32 linkedGuidLow)
|
||||
return true;
|
||||
}
|
||||
|
||||
const CreatureData* slave = GetCreatureData(linkedGuidLow);
|
||||
CreatureData const* slave = GetCreatureData(linkedGuidLow);
|
||||
if (!slave)
|
||||
{
|
||||
// LOG_ERROR("server", "sql.sql", "Creature '%u' linking to non-existent creature '%u'.", guidLow, linkedGuidLow);
|
||||
return false;
|
||||
}
|
||||
|
||||
const MapEntry* const map = sMapStore.LookupEntry(master->mapid);
|
||||
MapEntry const* map = sMapStore.LookupEntry(master->mapid);
|
||||
if (!map || !map->Instanceable() || (master->mapid != slave->mapid))
|
||||
{
|
||||
LOG_ERROR("sql.sql", "Creature '%u' linking to '%u' on an unpermitted map.", guidLow, linkedGuidLow);
|
||||
@@ -1731,7 +1723,7 @@ bool ObjectMgr::SetCreatureLinkedRespawn(uint32 guidLow, uint32 linkedGuidLow)
|
||||
return false;
|
||||
}
|
||||
|
||||
uint64 linkedGuid = MAKE_NEW_GUID(linkedGuidLow, slave->id, HIGHGUID_UNIT);
|
||||
ObjectGuid linkedGuid = ObjectGuid::Create<HighGuid::Unit>(slave->id, linkedGuidLow);
|
||||
|
||||
_linkedRespawnStore[guid] = linkedGuid;
|
||||
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_REP_CREATURE_LINKED_RESPAWN);
|
||||
@@ -1860,17 +1852,17 @@ void ObjectMgr::LoadCreatures()
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
|
||||
uint32 guid = fields[0].GetUInt32();
|
||||
uint32 entry = fields[1].GetUInt32();
|
||||
ObjectGuid::LowType spawnId = fields[0].GetUInt32();
|
||||
uint32 entry = fields[1].GetUInt32();
|
||||
|
||||
CreatureTemplate const* cInfo = GetCreatureTemplate(entry);
|
||||
if (!cInfo)
|
||||
{
|
||||
LOG_ERROR("sql.sql", "Table `creature` has creature (GUID: %u) with non existing creature entry %u, skipped.", guid, entry);
|
||||
LOG_ERROR("sql.sql", "Table `creature` has creature (SpawnId: %u) with non existing creature entry %u, skipped.", spawnId, entry);
|
||||
continue;
|
||||
}
|
||||
|
||||
CreatureData& data = _creatureDataStore[guid];
|
||||
CreatureData& data = _creatureDataStore[spawnId];
|
||||
data.id = entry;
|
||||
data.mapid = fields[2].GetUInt16();
|
||||
data.displayid = fields[3].GetUInt32();
|
||||
@@ -1896,7 +1888,7 @@ void ObjectMgr::LoadCreatures()
|
||||
MapEntry const* mapEntry = sMapStore.LookupEntry(data.mapid);
|
||||
if (!mapEntry)
|
||||
{
|
||||
LOG_ERROR("sql.sql", "Table `creature` have creature (GUID: %u) that spawned at not existed map (Id: %u), skipped.", guid, data.mapid);
|
||||
LOG_ERROR("sql.sql", "Table `creature` have creature (SpawnId: %u) that spawned at not existed map (Id: %u), skipped.", spawnId, data.mapid);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1906,15 +1898,16 @@ void ObjectMgr::LoadCreatures()
|
||||
|
||||
// Skip spawnMask check for transport maps
|
||||
if (!_transportMaps.count(data.mapid) && data.spawnMask & ~spawnMasks[data.mapid])
|
||||
LOG_ERROR("sql.sql", "Table `creature` have creature (GUID: %u) that have wrong spawn mask %u including not supported difficulty modes for map (Id: %u).", guid, data.spawnMask, data.mapid);
|
||||
LOG_ERROR("sql.sql", "Table `creature` have creature (SpawnId: %u) that have wrong spawn mask %u including not supported difficulty modes for map (Id: %u).",
|
||||
spawnId, data.spawnMask, data.mapid);
|
||||
|
||||
bool ok = true;
|
||||
for (uint32 diff = 0; diff < MAX_DIFFICULTY - 1 && ok; ++diff)
|
||||
{
|
||||
if (_difficultyEntries[diff].find(data.id) != _difficultyEntries[diff].end())
|
||||
{
|
||||
LOG_ERROR("sql.sql", "Table `creature` have creature (GUID: %u) that listed as difficulty %u template (entry: %u) in `creature_template`, skipped.",
|
||||
guid, diff + 1, data.id);
|
||||
LOG_ERROR("sql.sql", "Table `creature` have creature (SpawnId: %u) that listed as difficulty %u template (entry: %u) in `creature_template`, skipped.",
|
||||
spawnId, diff + 1, data.id);
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
@@ -1926,7 +1919,8 @@ void ObjectMgr::LoadCreatures()
|
||||
{
|
||||
if (!GetEquipmentInfo(data.id, data.equipmentId))
|
||||
{
|
||||
LOG_ERROR("sql.sql", "Table `creature` have creature (Entry: %u) with equipment_id %u not found in table `creature_equip_template`, set to no equipment.", data.id, data.equipmentId);
|
||||
LOG_ERROR("sql.sql", "Table `creature` have creature (Entry: %u) with equipment_id %u not found in table `creature_equip_template`, set to no equipment.",
|
||||
data.id, data.equipmentId);
|
||||
data.equipmentId = 0;
|
||||
}
|
||||
}
|
||||
@@ -1934,19 +1928,21 @@ void ObjectMgr::LoadCreatures()
|
||||
if (cInfo->flags_extra & CREATURE_FLAG_EXTRA_INSTANCE_BIND)
|
||||
{
|
||||
if (!mapEntry->IsDungeon())
|
||||
LOG_ERROR("sql.sql", "Table `creature` have creature (GUID: %u Entry: %u) with `creature_template`.`flags_extra` including CREATURE_FLAG_EXTRA_INSTANCE_BIND but creature are not in instance.", guid, data.id);
|
||||
LOG_ERROR("sql.sql", "Table `creature` have creature (SpawnId: %u Entry: %u) with `creature_template`.`flags_extra` including CREATURE_FLAG_EXTRA_INSTANCE_BIND but creature are not in instance.",
|
||||
spawnId, data.id);
|
||||
}
|
||||
|
||||
if (data.wander_distance < 0.0f)
|
||||
{
|
||||
LOG_ERROR("sql.sql", "Table `creature` have creature (GUID: %u Entry: %u) with `wander_distance`< 0, set to 0.", guid, data.id);
|
||||
LOG_ERROR("sql.sql", "Table `creature` have creature (SpawnId: %u Entry: %u) with `wander_distance`< 0, set to 0.", spawnId, data.id);
|
||||
data.wander_distance = 0.0f;
|
||||
}
|
||||
else if (data.movementType == RANDOM_MOTION_TYPE)
|
||||
{
|
||||
if (data.wander_distance == 0.0f)
|
||||
{
|
||||
LOG_ERROR("sql.sql", "Table `creature` have creature (GUID: %u Entry: %u) with `MovementType`=1 (random movement) but with `wander_distance`=0, replace by idle movement type (0).", guid, data.id);
|
||||
LOG_ERROR("sql.sql", "Table `creature` have creature (SpawnId: %u Entry: %u) with `MovementType`=1 (random movement) but with `wander_distance`=0, replace by idle movement type (0).",
|
||||
spawnId, data.id);
|
||||
data.movementType = IDLE_MOTION_TYPE;
|
||||
}
|
||||
}
|
||||
@@ -1954,14 +1950,14 @@ void ObjectMgr::LoadCreatures()
|
||||
{
|
||||
if (data.wander_distance != 0.0f)
|
||||
{
|
||||
LOG_ERROR("sql.sql", "Table `creature` have creature (GUID: %u Entry: %u) with `MovementType`=0 (idle) have `wander_distance`<>0, set to 0.", guid, data.id);
|
||||
LOG_ERROR("sql.sql", "Table `creature` have creature (SpawnId: %u Entry: %u) with `MovementType`=0 (idle) have `wander_distance`<>0, set to 0.", spawnId, data.id);
|
||||
data.wander_distance = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
if (data.phaseMask == 0)
|
||||
{
|
||||
LOG_ERROR("sql.sql", "Table `creature` have creature (GUID: %u Entry: %u) with `phaseMask`=0 (not visible for anyone), set to 1.", guid, data.id);
|
||||
LOG_ERROR("sql.sql", "Table `creature` have creature (SpawnId: %u Entry: %u) with `phaseMask`=0 (not visible for anyone), set to 1.", spawnId, data.id);
|
||||
data.phaseMask = 1;
|
||||
}
|
||||
|
||||
@@ -1974,14 +1970,14 @@ void ObjectMgr::LoadCreatures()
|
||||
|
||||
stmt->setUInt32(0, zoneId);
|
||||
stmt->setUInt32(1, areaId);
|
||||
stmt->setUInt64(2, guid);
|
||||
stmt->setUInt32(2, spawnId);
|
||||
|
||||
WorldDatabase.Execute(stmt);
|
||||
}
|
||||
|
||||
// Add to grid if not managed by the game event or pool system
|
||||
if (gameEvent == 0 && PoolId == 0)
|
||||
AddCreatureToGrid(guid, &data);
|
||||
AddCreatureToGrid(spawnId, &data);
|
||||
|
||||
++count;
|
||||
} while (result->NextRow());
|
||||
@@ -1990,7 +1986,7 @@ void ObjectMgr::LoadCreatures()
|
||||
LOG_INFO("server", " ");
|
||||
}
|
||||
|
||||
void ObjectMgr::AddCreatureToGrid(uint32 guid, CreatureData const* data)
|
||||
void ObjectMgr::AddCreatureToGrid(ObjectGuid::LowType guid, CreatureData const* data)
|
||||
{
|
||||
uint8 mask = data->spawnMask;
|
||||
for (uint8 i = 0; mask != 0; i++, mask >>= 1)
|
||||
@@ -2004,7 +2000,7 @@ void ObjectMgr::AddCreatureToGrid(uint32 guid, CreatureData const* data)
|
||||
}
|
||||
}
|
||||
|
||||
void ObjectMgr::RemoveCreatureFromGrid(uint32 guid, CreatureData const* data)
|
||||
void ObjectMgr::RemoveCreatureFromGrid(ObjectGuid::LowType guid, CreatureData const* data)
|
||||
{
|
||||
uint8 mask = data->spawnMask;
|
||||
for (uint8 i = 0; mask != 0; i++, mask >>= 1)
|
||||
@@ -2028,8 +2024,9 @@ uint32 ObjectMgr::AddGOData(uint32 entry, uint32 mapId, float x, float y, float
|
||||
if (!map)
|
||||
return 0;
|
||||
|
||||
uint32 guid = GenerateLowGuid(HIGHGUID_GAMEOBJECT);
|
||||
GameObjectData& data = NewGOData(guid);
|
||||
ObjectGuid::LowType spawnId = GenerateGameObjectSpawnId();
|
||||
|
||||
GameObjectData& data = NewGOData(spawnId);
|
||||
data.id = entry;
|
||||
data.mapid = mapId;
|
||||
data.posX = x;
|
||||
@@ -2048,14 +2045,14 @@ uint32 ObjectMgr::AddGOData(uint32 entry, uint32 mapId, float x, float y, float
|
||||
data.artKit = goinfo->type == GAMEOBJECT_TYPE_CAPTURE_POINT ? 21 : 0;
|
||||
data.dbData = false;
|
||||
|
||||
AddGameobjectToGrid(guid, &data);
|
||||
AddGameobjectToGrid(spawnId, &data);
|
||||
|
||||
// Spawn if necessary (loaded grids only)
|
||||
// We use spawn coords to spawn
|
||||
if (!map->Instanceable() && map->IsGridLoaded(x, y))
|
||||
{
|
||||
GameObject* go = sObjectMgr->IsGameObjectStaticTransport(data.id) ? new StaticTransport() : new GameObject();
|
||||
if (!go->LoadGameObjectFromDB(guid, map))
|
||||
if (!go->LoadGameObjectFromDB(spawnId, map))
|
||||
{
|
||||
LOG_ERROR("server", "AddGOData: cannot add gameobject entry %u to map", entry);
|
||||
delete go;
|
||||
@@ -2064,43 +2061,10 @@ uint32 ObjectMgr::AddGOData(uint32 entry, uint32 mapId, float x, float y, float
|
||||
}
|
||||
|
||||
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
|
||||
LOG_DEBUG("maps", "AddGOData: dbguid %u entry %u map %u x %f y %f z %f o %f", guid, entry, mapId, x, y, z, o);
|
||||
LOG_DEBUG("maps", "AddGOData: spawnId %u entry %u map %u x %f y %f z %f o %f", spawnId, entry, mapId, x, y, z, o);
|
||||
#endif
|
||||
|
||||
return guid;
|
||||
}
|
||||
|
||||
bool ObjectMgr::MoveCreData(uint32 guid, uint32 mapId, Position pos)
|
||||
{
|
||||
CreatureData& data = NewOrExistCreatureData(guid);
|
||||
if (!data.id)
|
||||
return false;
|
||||
|
||||
RemoveCreatureFromGrid(guid, &data);
|
||||
if (data.posX == pos.GetPositionX() && data.posY == pos.GetPositionY() && data.posZ == pos.GetPositionZ())
|
||||
return true;
|
||||
data.posX = pos.GetPositionX();
|
||||
data.posY = pos.GetPositionY();
|
||||
data.posZ = pos.GetPositionZ();
|
||||
data.orientation = pos.GetOrientation();
|
||||
AddCreatureToGrid(guid, &data);
|
||||
|
||||
// Spawn if necessary (loaded grids only)
|
||||
if (Map* map = sMapMgr->CreateBaseMap(mapId))
|
||||
{
|
||||
// We use spawn coords to spawn
|
||||
if (!map->Instanceable() && map->IsGridLoaded(data.posX, data.posY))
|
||||
{
|
||||
Creature* creature = new Creature();
|
||||
if (!creature->LoadCreatureFromDB(guid, map))
|
||||
{
|
||||
LOG_ERROR("server", "MoveCreData: Cannot add creature guid %u to map", guid);
|
||||
delete creature;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return spawnId;
|
||||
}
|
||||
|
||||
uint32 ObjectMgr::AddCreData(uint32 entry, uint32 mapId, float x, float y, float z, float o, uint32 spawntimedelay)
|
||||
@@ -2111,9 +2075,13 @@ uint32 ObjectMgr::AddCreData(uint32 entry, uint32 mapId, float x, float y, float
|
||||
|
||||
uint32 level = cInfo->minlevel == cInfo->maxlevel ? cInfo->minlevel : urand(cInfo->minlevel, cInfo->maxlevel); // Only used for extracting creature base stats
|
||||
CreatureBaseStats const* stats = GetCreatureBaseStats(level, cInfo->unit_class);
|
||||
Map* map = sMapMgr->CreateBaseMap(mapId);
|
||||
if (!map)
|
||||
return 0;
|
||||
|
||||
uint32 guid = GenerateLowGuid(HIGHGUID_UNIT);
|
||||
CreatureData& data = NewOrExistCreatureData(guid);
|
||||
ObjectGuid::LowType spawnId = GenerateCreatureSpawnId();
|
||||
CreatureData& data = NewOrExistCreatureData(spawnId);
|
||||
data.spawnMask = spawnId;
|
||||
data.id = entry;
|
||||
data.mapid = mapId;
|
||||
data.displayid = 0;
|
||||
@@ -2135,25 +2103,21 @@ uint32 ObjectMgr::AddCreData(uint32 entry, uint32 mapId, float x, float y, float
|
||||
data.unit_flags = cInfo->unit_flags;
|
||||
data.dynamicflags = cInfo->dynamicflags;
|
||||
|
||||
AddCreatureToGrid(guid, &data);
|
||||
AddCreatureToGrid(spawnId, &data);
|
||||
|
||||
// Spawn if necessary (loaded grids only)
|
||||
if (Map* map = sMapMgr->CreateBaseMap(mapId))
|
||||
if (!map->Instanceable() && !map->IsRemovalGrid(x, y))
|
||||
{
|
||||
// We use spawn coords to spawn
|
||||
if (!map->Instanceable() && !map->IsRemovalGrid(x, y))
|
||||
Creature* creature = new Creature();
|
||||
if (!creature->LoadCreatureFromDB(spawnId, map, true, false, true))
|
||||
{
|
||||
Creature* creature = new Creature();
|
||||
if (!creature->LoadCreatureFromDB(guid, map))
|
||||
{
|
||||
LOG_ERROR("server", "AddCreature: Cannot add creature entry %u to map", entry);
|
||||
delete creature;
|
||||
return 0;
|
||||
}
|
||||
LOG_ERROR("server", "AddCreature: Cannot add creature entry %u to map", entry);
|
||||
delete creature;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return guid;
|
||||
return spawnId;
|
||||
}
|
||||
|
||||
void ObjectMgr::LoadGameobjects()
|
||||
@@ -2189,8 +2153,8 @@ void ObjectMgr::LoadGameobjects()
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
|
||||
uint32 guid = fields[0].GetUInt32();
|
||||
uint32 entry = fields[1].GetUInt32();
|
||||
ObjectGuid::LowType guid = fields[0].GetUInt32();
|
||||
uint32 entry = fields[1].GetUInt32();
|
||||
|
||||
GameObjectTemplate const* gInfo = GetGameObjectTemplate(entry);
|
||||
if (!gInfo)
|
||||
@@ -2309,7 +2273,7 @@ void ObjectMgr::LoadGameobjects()
|
||||
|
||||
stmt->setUInt32(0, zoneId);
|
||||
stmt->setUInt32(1, areaId);
|
||||
stmt->setUInt64(2, guid);
|
||||
stmt->setUInt32(2, guid);
|
||||
|
||||
WorldDatabase.Execute(stmt);
|
||||
}
|
||||
@@ -2323,7 +2287,7 @@ void ObjectMgr::LoadGameobjects()
|
||||
LOG_INFO("server", " ");
|
||||
}
|
||||
|
||||
void ObjectMgr::AddGameobjectToGrid(uint32 guid, GameObjectData const* data)
|
||||
void ObjectMgr::AddGameobjectToGrid(ObjectGuid::LowType guid, GameObjectData const* data)
|
||||
{
|
||||
uint8 mask = data->spawnMask;
|
||||
for (uint8 i = 0; mask != 0; i++, mask >>= 1)
|
||||
@@ -2337,7 +2301,7 @@ void ObjectMgr::AddGameobjectToGrid(uint32 guid, GameObjectData const* data)
|
||||
}
|
||||
}
|
||||
|
||||
void ObjectMgr::RemoveGameobjectFromGrid(uint32 guid, GameObjectData const* data)
|
||||
void ObjectMgr::RemoveGameobjectFromGrid(ObjectGuid::LowType guid, GameObjectData const* data)
|
||||
{
|
||||
uint8 mask = data->spawnMask;
|
||||
for (uint8 i = 0; mask != 0; i++, mask >>= 1)
|
||||
@@ -2351,20 +2315,20 @@ void ObjectMgr::RemoveGameobjectFromGrid(uint32 guid, GameObjectData const* data
|
||||
}
|
||||
}
|
||||
|
||||
uint64 ObjectMgr::GetPlayerGUIDByName(std::string const& name) const
|
||||
ObjectGuid ObjectMgr::GetPlayerGUIDByName(std::string const& name) const
|
||||
{
|
||||
// Get data from global storage
|
||||
if (uint32 guidLow = sWorld->GetGlobalPlayerGUID(name))
|
||||
return MAKE_NEW_GUID(guidLow, 0, HIGHGUID_PLAYER);
|
||||
if (ObjectGuid guid = sWorld->GetGlobalPlayerGUID(name))
|
||||
return guid;
|
||||
|
||||
// No player found
|
||||
return 0;
|
||||
return ObjectGuid::Empty;
|
||||
}
|
||||
|
||||
bool ObjectMgr::GetPlayerNameByGUID(uint64 guid, std::string& name) const
|
||||
bool ObjectMgr::GetPlayerNameByGUID(ObjectGuid::LowType lowGuid, std::string& name) const
|
||||
{
|
||||
// Get data from global storage
|
||||
if (GlobalPlayerData const* playerData = sWorld->GetGlobalPlayerData(GUID_LOPART(guid)))
|
||||
if (GlobalPlayerData const* playerData = sWorld->GetGlobalPlayerData(lowGuid))
|
||||
{
|
||||
name = playerData->name;
|
||||
return true;
|
||||
@@ -2373,19 +2337,19 @@ bool ObjectMgr::GetPlayerNameByGUID(uint64 guid, std::string& name) const
|
||||
return false;
|
||||
}
|
||||
|
||||
TeamId ObjectMgr::GetPlayerTeamIdByGUID(uint64 guid) const
|
||||
TeamId ObjectMgr::GetPlayerTeamIdByGUID(ObjectGuid::LowType guid) const
|
||||
{
|
||||
// xinef: Get data from global storage
|
||||
if (GlobalPlayerData const* playerData = sWorld->GetGlobalPlayerData(GUID_LOPART(guid)))
|
||||
if (GlobalPlayerData const* playerData = sWorld->GetGlobalPlayerData(guid))
|
||||
return Player::TeamIdForRace(playerData->race);
|
||||
|
||||
return TEAM_NEUTRAL;
|
||||
}
|
||||
|
||||
uint32 ObjectMgr::GetPlayerAccountIdByGUID(uint64 guid) const
|
||||
uint32 ObjectMgr::GetPlayerAccountIdByGUID(ObjectGuid::LowType guid) const
|
||||
{
|
||||
// xinef: Get data from global storage
|
||||
if (GlobalPlayerData const* playerData = sWorld->GetGlobalPlayerData(GUID_LOPART(guid)))
|
||||
if (GlobalPlayerData const* playerData = sWorld->GetGlobalPlayerData(guid))
|
||||
return playerData->accountId;
|
||||
|
||||
return 0;
|
||||
@@ -2394,8 +2358,8 @@ uint32 ObjectMgr::GetPlayerAccountIdByGUID(uint64 guid) const
|
||||
uint32 ObjectMgr::GetPlayerAccountIdByPlayerName(const std::string& name) const
|
||||
{
|
||||
// Get data from global storage
|
||||
if (uint32 guidLow = sWorld->GetGlobalPlayerGUID(name))
|
||||
if (GlobalPlayerData const* playerData = sWorld->GetGlobalPlayerData(guidLow))
|
||||
if (ObjectGuid guid = sWorld->GetGlobalPlayerGUID(name))
|
||||
if (GlobalPlayerData const* playerData = sWorld->GetGlobalPlayerData(guid.GetCounter()))
|
||||
return playerData->accountId;
|
||||
|
||||
return 0;
|
||||
@@ -5713,7 +5677,7 @@ void ObjectMgr::ReturnOrDeleteOldMails(bool serverUp)
|
||||
|
||||
Player* player = nullptr;
|
||||
if (serverUp)
|
||||
player = ObjectAccessor::FindPlayerInOrOutOfWorld(MAKE_NEW_GUID(m->receiver, 0, HIGHGUID_PLAYER));
|
||||
player = ObjectAccessor::FindPlayerByLowGUID(m->receiver);
|
||||
|
||||
if (player) // don't modify mails of a logged in player
|
||||
{
|
||||
@@ -6418,39 +6382,21 @@ void ObjectMgr::SetHighestGuids()
|
||||
{
|
||||
QueryResult result = CharacterDatabase.Query("SELECT MAX(guid) FROM characters");
|
||||
if (result)
|
||||
_hiCharGuid = (*result)[0].GetUInt32() + 1;
|
||||
|
||||
result = WorldDatabase.Query("SELECT MAX(guid) FROM creature");
|
||||
if (result)
|
||||
{
|
||||
_hiCreatureGuid = (*result)[0].GetUInt32() + 1;
|
||||
_hiCreatureRecycledGuid = _hiCreatureGuid;
|
||||
_hiCreatureRecycledGuidMax = _hiCreatureRecycledGuid + 10000;
|
||||
_hiCreatureGuid = _hiCreatureRecycledGuidMax + 1;
|
||||
}
|
||||
GetGuidSequenceGenerator<HighGuid::Player>().Set((*result)[0].GetUInt32() + 1);
|
||||
|
||||
result = CharacterDatabase.Query("SELECT MAX(guid) FROM item_instance");
|
||||
if (result)
|
||||
_hiItemGuid = (*result)[0].GetUInt32() + 1;
|
||||
GetGuidSequenceGenerator<HighGuid::Item>().Set((*result)[0].GetUInt32() + 1);
|
||||
|
||||
// Cleanup other tables from not existed guids ( >= _hiItemGuid)
|
||||
CharacterDatabase.PExecute("DELETE FROM character_inventory WHERE item >= '%u'", _hiItemGuid); // One-time query
|
||||
CharacterDatabase.PExecute("DELETE FROM mail_items WHERE item_guid >= '%u'", _hiItemGuid); // One-time query
|
||||
CharacterDatabase.PExecute("DELETE FROM auctionhouse WHERE itemguid >= '%u'", _hiItemGuid); // One-time query
|
||||
CharacterDatabase.PExecute("DELETE FROM guild_bank_item WHERE item_guid >= '%u'", _hiItemGuid); // One-time query
|
||||
|
||||
result = WorldDatabase.Query("SELECT MAX(guid) FROM gameobject");
|
||||
if (result)
|
||||
{
|
||||
_hiGoGuid = (*result)[0].GetUInt32() + 1;
|
||||
_hiGoRecycledGuid = _hiGoGuid;
|
||||
_hiGoRecycledGuidMax = _hiGoRecycledGuid + 1;
|
||||
_hiGoGuid = _hiGoRecycledGuidMax + 1;
|
||||
}
|
||||
CharacterDatabase.PExecute("DELETE FROM character_inventory WHERE item >= '%u'", GetGuidSequenceGenerator<HighGuid::Item>().GetNextAfterMaxUsed()); // One-time query
|
||||
CharacterDatabase.PExecute("DELETE FROM mail_items WHERE item_guid >= '%u'", GetGuidSequenceGenerator<HighGuid::Item>().GetNextAfterMaxUsed()); // One-time query
|
||||
CharacterDatabase.PExecute("DELETE FROM auctionhouse WHERE itemguid >= '%u'", GetGuidSequenceGenerator<HighGuid::Item>().GetNextAfterMaxUsed()); // One-time query
|
||||
CharacterDatabase.PExecute("DELETE FROM guild_bank_item WHERE item_guid >= '%u'", GetGuidSequenceGenerator<HighGuid::Item>().GetNextAfterMaxUsed()); // One-time query
|
||||
|
||||
result = WorldDatabase.Query("SELECT MAX(guid) FROM transports");
|
||||
if (result)
|
||||
_hiMoTransGuid = (*result)[0].GetUInt32() + 1;
|
||||
GetGuidSequenceGenerator<HighGuid::Mo_Transport>().Set((*result)[0].GetUInt32() + 1);
|
||||
|
||||
result = CharacterDatabase.Query("SELECT MAX(id) FROM auctionhouse");
|
||||
if (result)
|
||||
@@ -6460,10 +6406,6 @@ void ObjectMgr::SetHighestGuids()
|
||||
if (result)
|
||||
_mailId = (*result)[0].GetUInt32() + 1;
|
||||
|
||||
result = CharacterDatabase.Query("SELECT MAX(corpseGuid) FROM corpse");
|
||||
if (result)
|
||||
_hiCorpseGuid = (*result)[0].GetUInt32() + 1;
|
||||
|
||||
result = CharacterDatabase.Query("SELECT MAX(arenateamid) FROM arena_team");
|
||||
if (result)
|
||||
sArenaTeamMgr->SetNextArenaTeamId((*result)[0].GetUInt32() + 1);
|
||||
@@ -6479,6 +6421,14 @@ void ObjectMgr::SetHighestGuids()
|
||||
result = CharacterDatabase.Query("SELECT MAX(guildId) FROM guild");
|
||||
if (result)
|
||||
sGuildMgr->SetNextGuildId((*result)[0].GetUInt32() + 1);
|
||||
|
||||
result = WorldDatabase.Query("SELECT MAX(guid) FROM creature");
|
||||
if (result)
|
||||
_creatureSpawnId = (*result)[0].GetUInt32() + 1;
|
||||
|
||||
result = WorldDatabase.Query("SELECT MAX(guid) FROM gameobject");
|
||||
if (result)
|
||||
_gameObjectSpawnId = (*result)[0].GetUInt32() + 1;
|
||||
}
|
||||
|
||||
uint32 ObjectMgr::GenerateAuctionID()
|
||||
@@ -6512,92 +6462,24 @@ uint32 ObjectMgr::GenerateMailID()
|
||||
return _mailId++;
|
||||
}
|
||||
|
||||
uint32 ObjectMgr::GenerateLowGuid(HighGuid guidhigh)
|
||||
uint32 ObjectMgr::GenerateCreatureSpawnId()
|
||||
{
|
||||
switch (guidhigh)
|
||||
if (_creatureSpawnId >= uint32(0xFFFFFF))
|
||||
{
|
||||
case HIGHGUID_ITEM:
|
||||
{
|
||||
ASSERT(_hiItemGuid < 0xFFFFFFFE && "Item guid overflow!");
|
||||
std::lock_guard<std::mutex> guard(_hiItemGuidMutex);
|
||||
return _hiItemGuid++;
|
||||
}
|
||||
case HIGHGUID_UNIT:
|
||||
{
|
||||
ASSERT(_hiCreatureGuid < 0x00FFFFFE && "Creature guid overflow!");
|
||||
std::lock_guard<std::mutex> guard(_hiCreatureGuidMutex);
|
||||
return _hiCreatureGuid++;
|
||||
}
|
||||
case HIGHGUID_PET:
|
||||
{
|
||||
ASSERT(_hiPetGuid < 0x00FFFFFE && "Pet guid overflow!");
|
||||
std::lock_guard<std::mutex> guard(_hiPetGuidMutex);
|
||||
return _hiPetGuid++;
|
||||
}
|
||||
case HIGHGUID_VEHICLE:
|
||||
{
|
||||
ASSERT(_hiVehicleGuid < 0x00FFFFFF && "Vehicle guid overflow!");
|
||||
std::lock_guard<std::mutex> guard(_hiVehicleGuidMutex);
|
||||
return _hiVehicleGuid++;
|
||||
}
|
||||
case HIGHGUID_PLAYER:
|
||||
{
|
||||
ASSERT(_hiCharGuid < 0xFFFFFFFE && "Player guid overflow!");
|
||||
return _hiCharGuid++;
|
||||
}
|
||||
case HIGHGUID_GAMEOBJECT:
|
||||
{
|
||||
ASSERT(_hiGoGuid < 0x00FFFFFE && "Gameobject guid overflow!");
|
||||
std::lock_guard<std::mutex> guard(_hiGoGuidMutex);
|
||||
return _hiGoGuid++;
|
||||
}
|
||||
case HIGHGUID_CORPSE:
|
||||
{
|
||||
ASSERT(_hiCorpseGuid < 0xFFFFFFFE && "Corpse guid overflow!");
|
||||
std::lock_guard<std::mutex> guard(_hiCorpseGuidMutex);
|
||||
return _hiCorpseGuid++;
|
||||
}
|
||||
case HIGHGUID_DYNAMICOBJECT:
|
||||
{
|
||||
ASSERT(_hiDoGuid < 0xFFFFFFFE && "DynamicObject guid overflow!");
|
||||
std::lock_guard<std::mutex> guard(_hiDoGuidMutex);
|
||||
return _hiDoGuid++;
|
||||
}
|
||||
case HIGHGUID_MO_TRANSPORT:
|
||||
{
|
||||
ASSERT(_hiMoTransGuid < 0xFFFFFFFE && "MO Transport guid overflow!");
|
||||
std::lock_guard<std::mutex> guard(_hiMoTransGuidMutex);
|
||||
return _hiMoTransGuid++;
|
||||
}
|
||||
default:
|
||||
ASSERT(false && "ObjectMgr::GenerateLowGuid - Unknown HIGHGUID type");
|
||||
return 0;
|
||||
LOG_ERROR("server", "Creature spawn id overflow!! Can't continue, shutting down server. Search on forum for TCE00007 for more info.");
|
||||
World::StopNow(ERROR_EXIT_CODE);
|
||||
}
|
||||
return _creatureSpawnId++;
|
||||
}
|
||||
|
||||
uint32 ObjectMgr::GenerateRecycledLowGuid(HighGuid guidHigh)
|
||||
uint32 ObjectMgr::GenerateGameObjectSpawnId()
|
||||
{
|
||||
switch (guidHigh)
|
||||
if (_gameObjectSpawnId >= uint32(0xFFFFFF))
|
||||
{
|
||||
case HIGHGUID_UNIT:
|
||||
{
|
||||
ASSERT(_hiCreatureRecycledGuid < 0x00FFFFFE && "Creature recycled guid overflow!");
|
||||
if (_hiCreatureRecycledGuid < _hiCreatureRecycledGuidMax)
|
||||
return _hiCreatureRecycledGuid++;
|
||||
break;
|
||||
}
|
||||
case HIGHGUID_GAMEOBJECT:
|
||||
{
|
||||
ASSERT(_hiGoRecycledGuid < 0x00FFFFFE && "Gameobject recycled guid overflow!");
|
||||
if (_hiGoRecycledGuid < _hiGoRecycledGuidMax)
|
||||
return _hiGoRecycledGuid++;
|
||||
break;
|
||||
}
|
||||
default: // Default case is not handled by the recycler
|
||||
break;
|
||||
LOG_ERROR("server", "GameObject spawn id overflow!! Can't continue, shutting down server. Search on forum for TCE00007 for more info. ");
|
||||
World::StopNow(ERROR_EXIT_CODE);
|
||||
}
|
||||
|
||||
return GenerateLowGuid(guidHigh);
|
||||
return _gameObjectSpawnId++;
|
||||
}
|
||||
|
||||
void ObjectMgr::LoadGameObjectLocales()
|
||||
@@ -7051,45 +6933,6 @@ uint32 ObjectMgr::GeneratePetNumber()
|
||||
return ++_hiPetNumber;
|
||||
}
|
||||
|
||||
void ObjectMgr::LoadCorpses()
|
||||
{
|
||||
uint32 oldMSTime = getMSTime();
|
||||
|
||||
PreparedQueryResult result = CharacterDatabase.Query(CharacterDatabase.GetPreparedStatement(CHAR_SEL_CORPSES));
|
||||
if (!result)
|
||||
{
|
||||
LOG_INFO("server", ">> Loaded 0 corpses. DB table `corpse` is empty.");
|
||||
LOG_INFO("server", " ");
|
||||
return;
|
||||
}
|
||||
|
||||
uint32 count = 0;
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
uint32 guid = fields[16].GetUInt32();
|
||||
CorpseType type = CorpseType(fields[13].GetUInt8());
|
||||
if (type >= MAX_CORPSE_TYPE)
|
||||
{
|
||||
LOG_ERROR("server", "Corpse (guid: %u) have wrong corpse type (%u), not loading.", guid, type);
|
||||
continue;
|
||||
}
|
||||
|
||||
Corpse* corpse = new Corpse(type);
|
||||
if (!corpse->LoadCorpseFromDB(guid, fields))
|
||||
{
|
||||
delete corpse;
|
||||
continue;
|
||||
}
|
||||
|
||||
sObjectAccessor->AddCorpse(corpse);
|
||||
++count;
|
||||
} while (result->NextRow());
|
||||
|
||||
LOG_INFO("server", ">> Loaded %u corpses in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
|
||||
LOG_INFO("server", " ");
|
||||
}
|
||||
|
||||
void ObjectMgr::LoadReputationRewardRate()
|
||||
{
|
||||
uint32 oldMSTime = getMSTime();
|
||||
@@ -7554,7 +7397,7 @@ void ObjectMgr::LoadNPCSpellClickSpells()
|
||||
LOG_INFO("server", " ");
|
||||
}
|
||||
|
||||
void ObjectMgr::DeleteCreatureData(uint32 guid)
|
||||
void ObjectMgr::DeleteCreatureData(ObjectGuid::LowType guid)
|
||||
{
|
||||
// remove mapid*cellid -> guid_set map
|
||||
CreatureData const* data = GetCreatureData(guid);
|
||||
@@ -7564,7 +7407,7 @@ void ObjectMgr::DeleteCreatureData(uint32 guid)
|
||||
_creatureDataStore.erase(guid);
|
||||
}
|
||||
|
||||
void ObjectMgr::DeleteGOData(uint32 guid)
|
||||
void ObjectMgr::DeleteGOData(ObjectGuid::LowType guid)
|
||||
{
|
||||
// remove mapid*cellid -> guid_set map
|
||||
GameObjectData const* data = GetGOData(guid);
|
||||
@@ -7574,20 +7417,6 @@ void ObjectMgr::DeleteGOData(uint32 guid)
|
||||
_gameObjectDataStore.erase(guid);
|
||||
}
|
||||
|
||||
void ObjectMgr::AddCorpseCellData(uint32 mapid, uint32 cellid, uint32 player_guid, uint32 instance)
|
||||
{
|
||||
// corpses are always added to spawn mode 0 and they are spawned by their instance id
|
||||
CellObjectGuids& cell_guids = _mapObjectGuidsStore[MAKE_PAIR32(mapid, 0)][cellid];
|
||||
cell_guids.corpses[player_guid] = instance;
|
||||
}
|
||||
|
||||
void ObjectMgr::DeleteCorpseCellData(uint32 mapid, uint32 cellid, uint32 player_guid)
|
||||
{
|
||||
// corpses are always added to spawn mode 0 and they are spawned by their instance id
|
||||
CellObjectGuids& cell_guids = _mapObjectGuidsStore[MAKE_PAIR32(mapid, 0)][cellid];
|
||||
cell_guids.corpses.erase(player_guid);
|
||||
}
|
||||
|
||||
void ObjectMgr::LoadQuestRelationsHelper(QuestRelations& map, std::string const& table, bool starter, bool go)
|
||||
{
|
||||
uint32 oldMSTime = getMSTime();
|
||||
@@ -9327,12 +9156,6 @@ GameObjectTemplate const* ObjectMgr::GetGameObjectTemplate(uint32 entry)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Player* ObjectMgr::GetPlayerByLowGUID(uint32 lowguid) const
|
||||
{
|
||||
uint64 guid = MAKE_NEW_GUID(lowguid, 0, HIGHGUID_PLAYER);
|
||||
return ObjectAccessor::FindPlayer(guid);
|
||||
}
|
||||
|
||||
bool ObjectMgr::IsGameObjectStaticTransport(uint32 entry)
|
||||
{
|
||||
GameObjectTemplate const* goinfo = GetGameObjectTemplate(entry);
|
||||
@@ -9358,7 +9181,7 @@ VehicleAccessoryList const* ObjectMgr::GetVehicleAccessoryList(Vehicle* veh) con
|
||||
if (Creature* cre = veh->GetBase()->ToCreature())
|
||||
{
|
||||
// Give preference to GUID-based accessories
|
||||
VehicleAccessoryContainer::const_iterator itr = _vehicleAccessoryStore.find(cre->GetDBTableGUIDLow());
|
||||
VehicleAccessoryContainer::const_iterator itr = _vehicleAccessoryStore.find(cre->GetSpawnId());
|
||||
if (itr != _vehicleAccessoryStore.end())
|
||||
return &itr->second;
|
||||
}
|
||||
|
||||
@@ -461,14 +461,12 @@ struct BroadcastText
|
||||
|
||||
typedef std::unordered_map<uint32, BroadcastText> BroadcastTextContainer;
|
||||
|
||||
typedef std::set<uint32> CellGuidSet;
|
||||
typedef std::unordered_map<uint32/*player guid*/, uint32/*instance*/> CellCorpseSet;
|
||||
typedef std::set<ObjectGuid::LowType> CellGuidSet;
|
||||
|
||||
struct CellObjectGuids
|
||||
{
|
||||
CellGuidSet creatures;
|
||||
CellGuidSet gameobjects;
|
||||
CellCorpseSet corpses;
|
||||
};
|
||||
|
||||
typedef std::unordered_map<uint32/*cell_id*/, CellObjectGuids> CellObjectGuidsMap;
|
||||
@@ -488,9 +486,9 @@ struct AcoreString
|
||||
StringVector Content;
|
||||
};
|
||||
|
||||
typedef std::map<uint64, uint64> LinkedRespawnContainer;
|
||||
typedef std::unordered_map<uint32, CreatureData> CreatureDataContainer;
|
||||
typedef std::unordered_map<uint32, GameObjectData> GameObjectDataContainer;
|
||||
typedef std::map<ObjectGuid, ObjectGuid> LinkedRespawnContainer;
|
||||
typedef std::unordered_map<ObjectGuid::LowType, CreatureData> CreatureDataContainer;
|
||||
typedef std::unordered_map<ObjectGuid::LowType, GameObjectData> GameObjectDataContainer;
|
||||
typedef std::map<TempSummonGroupKey, std::vector<TempSummonData> > TempSummonDataContainer;
|
||||
typedef std::unordered_map<uint32, CreatureLocale> CreatureLocaleContainer;
|
||||
typedef std::unordered_map<uint32, GameObjectLocale> GameObjectLocaleContainer;
|
||||
@@ -716,8 +714,6 @@ public:
|
||||
|
||||
typedef std::map<uint32, uint32> CharacterConversionMap;
|
||||
|
||||
[[nodiscard]] Player* GetPlayerByLowGUID(uint32 lowguid) const;
|
||||
|
||||
GameObjectTemplate const* GetGameObjectTemplate(uint32 entry);
|
||||
bool IsGameObjectStaticTransport(uint32 entry);
|
||||
[[nodiscard]] GameObjectTemplateContainer const* GetGameObjectTemplates() const { return &_gameObjectTemplateStore; }
|
||||
@@ -734,8 +730,8 @@ public:
|
||||
static uint32 ChooseDisplayId(CreatureTemplate const* cinfo, CreatureData const* data = nullptr);
|
||||
static void ChooseCreatureFlags(CreatureTemplate const* cinfo, uint32& npcflag, uint32& unit_flags, uint32& dynamicflags, CreatureData const* data = nullptr);
|
||||
EquipmentInfo const* GetEquipmentInfo(uint32 entry, int8& id);
|
||||
CreatureAddon const* GetCreatureAddon(uint32 lowguid);
|
||||
GameObjectAddon const* GetGameObjectAddon(uint32 lowguid);
|
||||
CreatureAddon const* GetCreatureAddon(ObjectGuid::LowType lowguid);
|
||||
GameObjectAddon const* GetGameObjectAddon(ObjectGuid::LowType lowguid);
|
||||
[[nodiscard]] GameObjectTemplateAddon const* GetGameObjectTemplateAddon(uint32 entry) const;
|
||||
CreatureAddon const* GetCreatureTemplateAddon(uint32 entry);
|
||||
ItemTemplate const* GetItemTemplate(uint32 entry);
|
||||
@@ -766,10 +762,10 @@ public:
|
||||
|
||||
void GetPlayerLevelInfo(uint32 race, uint32 class_, uint8 level, PlayerLevelInfo* info) const;
|
||||
|
||||
[[nodiscard]] uint64 GetPlayerGUIDByName(std::string const& name) const;
|
||||
bool GetPlayerNameByGUID(uint64 guid, std::string& name) const;
|
||||
[[nodiscard]] TeamId GetPlayerTeamIdByGUID(uint64 guid) const;
|
||||
[[nodiscard]] uint32 GetPlayerAccountIdByGUID(uint64 guid) const;
|
||||
[[nodiscard]] ObjectGuid GetPlayerGUIDByName(std::string const& name) const;
|
||||
bool GetPlayerNameByGUID(ObjectGuid::LowType lowGuid, std::string& name) const;
|
||||
[[nodiscard]] TeamId GetPlayerTeamIdByGUID(ObjectGuid::LowType guid) const;
|
||||
[[nodiscard]] uint32 GetPlayerAccountIdByGUID(ObjectGuid::LowType guid) const;
|
||||
[[nodiscard]] uint32 GetPlayerAccountIdByPlayerName(std::string const& name) const;
|
||||
|
||||
uint32 GetNearestTaxiNode(float x, float y, float z, uint32 mapid, uint32 teamId);
|
||||
@@ -988,7 +984,7 @@ public:
|
||||
void LoadTempSummons();
|
||||
void LoadCreatures();
|
||||
void LoadLinkedRespawn();
|
||||
bool SetCreatureLinkedRespawn(uint32 guid, uint32 linkedGuid);
|
||||
bool SetCreatureLinkedRespawn(ObjectGuid::LowType guid, ObjectGuid::LowType linkedGuid);
|
||||
void LoadCreatureAddons();
|
||||
void LoadGameObjectAddons();
|
||||
void LoadCreatureModelInfo();
|
||||
@@ -1030,7 +1026,6 @@ public:
|
||||
void LoadExplorationBaseXP();
|
||||
void LoadPetNames();
|
||||
void LoadPetNumber();
|
||||
void LoadCorpses();
|
||||
void LoadFishingBaseSkillLevel();
|
||||
void ChangeFishingBaseSkillLevel(uint32 entry, int32 skill);
|
||||
|
||||
@@ -1067,12 +1062,20 @@ public:
|
||||
CreatureBaseStats const* GetCreatureBaseStats(uint8 level, uint8 unitClass);
|
||||
|
||||
void SetHighestGuids();
|
||||
uint32 GenerateLowGuid(HighGuid guidhigh);
|
||||
uint32 GenerateRecycledLowGuid(HighGuid guidHigh);
|
||||
|
||||
template<HighGuid type>
|
||||
inline ObjectGuidGeneratorBase& GetGenerator()
|
||||
{
|
||||
static_assert(ObjectGuidTraits<type>::Global, "Only global guid can be generated in ObjectMgr context");
|
||||
return GetGuidSequenceGenerator<type>();
|
||||
}
|
||||
|
||||
uint32 GenerateAuctionID();
|
||||
uint64 GenerateEquipmentSetGuid();
|
||||
uint32 GenerateMailID();
|
||||
uint32 GeneratePetNumber();
|
||||
ObjectGuid::LowType GenerateCreatureSpawnId();
|
||||
ObjectGuid::LowType GenerateGameObjectSpawnId();
|
||||
|
||||
typedef std::multimap<int32, uint32> ExclusiveQuestGroups;
|
||||
typedef std::pair<ExclusiveQuestGroups::const_iterator, ExclusiveQuestGroups::const_iterator> ExclusiveQuestGroupsBounds;
|
||||
@@ -1137,26 +1140,27 @@ public:
|
||||
return &itr->second;
|
||||
return nullptr;
|
||||
}
|
||||
[[nodiscard]] CreatureData const* GetCreatureData(uint32 guid) const
|
||||
[[nodiscard]] CreatureData const* GetCreatureData(ObjectGuid::LowType spawnId) const
|
||||
{
|
||||
CreatureDataContainer::const_iterator itr = _creatureDataStore.find(guid);
|
||||
CreatureDataContainer::const_iterator itr = _creatureDataStore.find(spawnId);
|
||||
if (itr == _creatureDataStore.end()) return nullptr;
|
||||
return &itr->second;
|
||||
}
|
||||
CreatureData& NewOrExistCreatureData(uint32 guid) { return _creatureDataStore[guid]; }
|
||||
void DeleteCreatureData(uint32 guid);
|
||||
[[nodiscard]] uint64 GetLinkedRespawnGuid(uint64 guid) const
|
||||
CreatureData& NewOrExistCreatureData(ObjectGuid::LowType spawnId) { return _creatureDataStore[spawnId]; }
|
||||
void DeleteCreatureData(ObjectGuid::LowType spawnId);
|
||||
[[nodiscard]] ObjectGuid GetLinkedRespawnGuid(ObjectGuid guid) const
|
||||
{
|
||||
LinkedRespawnContainer::const_iterator itr = _linkedRespawnStore.find(guid);
|
||||
if (itr == _linkedRespawnStore.end()) return 0;
|
||||
if (itr == _linkedRespawnStore.end())
|
||||
return ObjectGuid::Empty;
|
||||
return itr->second;
|
||||
}
|
||||
|
||||
[[nodiscard]] GameObjectData const* GetGOData(uint32 guid) const
|
||||
[[nodiscard]] GameObjectData const* GetGOData(ObjectGuid::LowType spawnId) const
|
||||
{
|
||||
GameObjectDataContainer::const_iterator itr = _gameObjectDataStore.find(guid);
|
||||
GameObjectDataContainer::const_iterator itr = _gameObjectDataStore.find(spawnId);
|
||||
if (itr == _gameObjectDataStore.end()) return nullptr;
|
||||
return &itr->second;
|
||||
return &itr->second;
|
||||
}
|
||||
[[nodiscard]] CreatureLocale const* GetCreatureLocale(uint32 entry) const
|
||||
{
|
||||
@@ -1224,8 +1228,8 @@ public:
|
||||
if (itr == _npcTextLocaleStore.end()) return nullptr;
|
||||
return &itr->second;
|
||||
}
|
||||
GameObjectData& NewGOData(uint32 guid) { return _gameObjectDataStore[guid]; }
|
||||
void DeleteGOData(uint32 guid);
|
||||
GameObjectData& NewGOData(ObjectGuid::LowType guid) { return _gameObjectDataStore[guid]; }
|
||||
void DeleteGOData(ObjectGuid::LowType guid);
|
||||
|
||||
[[nodiscard]] AcoreString const* GetAcoreString(uint32 entry) const
|
||||
{
|
||||
@@ -1240,17 +1244,13 @@ public:
|
||||
[[nodiscard]] LocaleConstant GetDBCLocaleIndex() const { return DBCLocaleIndex; }
|
||||
void SetDBCLocaleIndex(LocaleConstant locale) { DBCLocaleIndex = locale; }
|
||||
|
||||
void AddCorpseCellData(uint32 mapid, uint32 cellid, uint32 player_guid, uint32 instance);
|
||||
void DeleteCorpseCellData(uint32 mapid, uint32 cellid, uint32 player_guid);
|
||||
|
||||
// grid objects
|
||||
void AddCreatureToGrid(uint32 guid, CreatureData const* data);
|
||||
void RemoveCreatureFromGrid(uint32 guid, CreatureData const* data);
|
||||
void AddGameobjectToGrid(uint32 guid, GameObjectData const* data);
|
||||
void RemoveGameobjectFromGrid(uint32 guid, GameObjectData const* data);
|
||||
void AddCreatureToGrid(ObjectGuid::LowType guid, CreatureData const* data);
|
||||
void RemoveCreatureFromGrid(ObjectGuid::LowType guid, CreatureData const* data);
|
||||
void AddGameobjectToGrid(ObjectGuid::LowType guid, GameObjectData const* data);
|
||||
void RemoveGameobjectFromGrid(ObjectGuid::LowType guid, GameObjectData const* data);
|
||||
uint32 AddGOData(uint32 entry, uint32 map, float x, float y, float z, float o, uint32 spawntimedelay = 0, float rotation0 = 0, float rotation1 = 0, float rotation2 = 0, float rotation3 = 0);
|
||||
uint32 AddCreData(uint32 entry, uint32 map, float x, float y, float z, float o, uint32 spawntimedelay = 0);
|
||||
bool MoveCreData(uint32 guid, uint32 map, Position pos);
|
||||
|
||||
// reserved names
|
||||
void LoadReservedPlayersNames();
|
||||
@@ -1351,35 +1351,26 @@ private:
|
||||
// first free id for selected id type
|
||||
uint32 _auctionId; // pussywizard: accessed by a single thread
|
||||
uint64 _equipmentSetGuid; // pussywizard: accessed by a single thread
|
||||
uint32 _itemTextId; // pussywizard: unused? xD
|
||||
uint32 _mailId;
|
||||
std::mutex _mailIdMutex;
|
||||
uint32 _hiPetNumber;
|
||||
std::mutex _hiPetNumberMutex;
|
||||
|
||||
// first free low guid for selected guid type
|
||||
uint32 _hiCharGuid; // pussywizard: accessed by a single thread
|
||||
uint32 _hiCreatureGuid;
|
||||
std::mutex _hiCreatureGuidMutex;
|
||||
uint32 _hiPetGuid;
|
||||
std::mutex _hiPetGuidMutex;
|
||||
uint32 _hiVehicleGuid;
|
||||
std::mutex _hiVehicleGuidMutex;
|
||||
uint32 _hiItemGuid;
|
||||
std::mutex _hiItemGuidMutex;
|
||||
uint32 _hiGoGuid;
|
||||
std::mutex _hiGoGuidMutex;
|
||||
uint32 _hiDoGuid;
|
||||
std::mutex _hiDoGuidMutex;
|
||||
uint32 _hiCorpseGuid;
|
||||
std::mutex _hiCorpseGuidMutex;
|
||||
uint32 _hiMoTransGuid;
|
||||
std::mutex _hiMoTransGuidMutex;
|
||||
ObjectGuid::LowType _creatureSpawnId;
|
||||
ObjectGuid::LowType _gameObjectSpawnId;
|
||||
|
||||
uint32 _hiCreatureRecycledGuidMax;
|
||||
uint32 _hiCreatureRecycledGuid;
|
||||
uint32 _hiGoRecycledGuidMax;
|
||||
uint32 _hiGoRecycledGuid;
|
||||
// first free low guid for selected guid type
|
||||
template<HighGuid high>
|
||||
inline ObjectGuidGeneratorBase& GetGuidSequenceGenerator()
|
||||
{
|
||||
auto itr = _guidGenerators.find(high);
|
||||
if (itr == _guidGenerators.end())
|
||||
itr = _guidGenerators.insert(std::make_pair(high, std::unique_ptr<ObjectGuidGenerator<high>>(new ObjectGuidGenerator<high>()))).first;
|
||||
|
||||
return *itr->second;
|
||||
}
|
||||
|
||||
std::map<HighGuid, std::unique_ptr<ObjectGuidGeneratorBase>> _guidGenerators;
|
||||
|
||||
QuestMap _questTemplates;
|
||||
std::vector<Quest*> _questTemplatesFast; // pussywizard
|
||||
|
||||
Reference in New Issue
Block a user