feat(Core/Misc): implement ObjectGuid class (port from TC) (#4885)

This commit is contained in:
UltraNix
2021-04-25 22:18:03 +02:00
committed by GitHub
parent 91081f4ad8
commit f4c226423d
568 changed files with 10655 additions and 11019 deletions

View File

@@ -197,16 +197,16 @@ MapEntry const* InstanceSave::GetMapEntry()
return sMapStore.LookupEntry(m_mapid);
}
void InstanceSave::AddPlayer(uint32 guidLow)
void InstanceSave::AddPlayer(ObjectGuid guid)
{
std::lock_guard<std::mutex> guard(_lock);
m_playerList.push_back(guidLow);
m_playerList.push_back(guid);
}
bool InstanceSave::RemovePlayer(uint32 guidLow, InstanceSaveManager* ism)
bool InstanceSave::RemovePlayer(ObjectGuid guid, InstanceSaveManager* ism)
{
std::lock_guard<std::mutex> guard(_lock);
m_playerList.remove(guidLow);
m_playerList.remove(guid);
// ism passed as an argument to avoid calling via singleton (might result in a deadlock)
return ism->DeleteInstanceSaveIfNeeded(this->GetInstanceId(), false);
@@ -365,7 +365,7 @@ void InstanceSaveManager::LoadCharacterBinds()
{
Field* fields = result->Fetch();
uint32 guid = fields[0].GetUInt32();
ObjectGuid guid = ObjectGuid::Create<HighGuid::Player>(fields[0].GetUInt32());
uint32 instanceId = fields[1].GetUInt32();
bool perm = fields[2].GetBool();
bool extended = fields[3].GetBool();
@@ -379,7 +379,7 @@ void InstanceSaveManager::LoadCharacterBinds()
if (bind.perm) // already loaded perm -> delete currently checked one from db
{
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_INSTANCE_BY_INSTANCE_GUID);
stmt->setUInt32(0, guid);
stmt->setUInt32(0, guid.GetCounter());
stmt->setUInt32(1, instanceId);
CharacterDatabase.Execute(stmt);
continue;
@@ -387,7 +387,7 @@ void InstanceSaveManager::LoadCharacterBinds()
else // override temp bind by newest one
{
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_INSTANCE_BY_INSTANCE_GUID);
stmt->setUInt32(0, guid);
stmt->setUInt32(0, guid.GetCounter());
stmt->setUInt32(1, bind.save->GetInstanceId());
CharacterDatabase.Execute(stmt);
bind.save->RemovePlayer(guid, this);
@@ -460,11 +460,11 @@ void InstanceSaveManager::_ResetSave(InstanceSaveHashMap::iterator& itr)
{
lock_instLists = true;
InstanceSave::PlayerListType& pList = itr->second->m_playerList;
for (InstanceSave::PlayerListType::iterator iter = pList.begin(), iter2; iter != pList.end(); )
GuidList& pList = itr->second->m_playerList;
for (GuidList::iterator iter = pList.begin(), iter2; iter != pList.end(); )
{
iter2 = iter++;
PlayerUnbindInstanceNotExtended(*iter2, itr->second->GetMapId(), itr->second->GetDifficulty(), ObjectAccessor::GetObjectInOrOutOfWorld(MAKE_NEW_GUID(*iter2, 0, HIGHGUID_PLAYER), (Player*)nullptr));
PlayerUnbindInstanceNotExtended(*iter2, itr->second->GetMapId(), itr->second->GetDifficulty(), ObjectAccessor::FindConnectedPlayer(*iter2));
}
// delete stuff if no players left (noone extended id)
@@ -581,9 +581,9 @@ void InstanceSaveManager::_ResetOrWarnAll(uint32 mapid, Difficulty difficulty, b
}
}
InstancePlayerBind* InstanceSaveManager::PlayerBindToInstance(uint32 guidLow, InstanceSave* save, bool permanent, Player* player /*= nullptr*/)
InstancePlayerBind* InstanceSaveManager::PlayerBindToInstance(ObjectGuid guid, InstanceSave* save, bool permanent, Player* player /*= nullptr*/)
{
InstancePlayerBind& bind = playerBindStorage[guidLow]->m[save->GetDifficulty()][save->GetMapId()];
InstancePlayerBind& bind = playerBindStorage[guid]->m[save->GetDifficulty()][save->GetMapId()];
ASSERT(!bind.perm || permanent); // ensure there's no changing permanent to temporary, this can be done only by unbinding
if (bind.save)
@@ -595,7 +595,7 @@ InstancePlayerBind* InstanceSaveManager::PlayerBindToInstance(uint32 guidLow, In
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_CHAR_INSTANCE);
stmt->setUInt32(0, save->GetInstanceId());
stmt->setBool(1, permanent);
stmt->setUInt32(2, guidLow);
stmt->setUInt32(2, guid.GetCounter());
stmt->setUInt32(3, bind.save->GetInstanceId());
CharacterDatabase.Execute(stmt);
}
@@ -621,7 +621,7 @@ InstancePlayerBind* InstanceSaveManager::PlayerBindToInstance(uint32 guidLow, In
CharacterDatabase.CommitTransaction(trans);*/
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_CHAR_INSTANCE);
stmt->setUInt32(0, guidLow);
stmt->setUInt32(0, guid.GetCounter());
stmt->setUInt32(1, save->GetInstanceId());
stmt->setBool(2, permanent);
CharacterDatabase.Execute(stmt);
@@ -630,8 +630,8 @@ InstancePlayerBind* InstanceSaveManager::PlayerBindToInstance(uint32 guidLow, In
if (bind.save != save)
{
if (bind.save)
bind.save->RemovePlayer(guidLow, this);
save->AddPlayer(guidLow);
bind.save->RemovePlayer(guid, this);
save->AddPlayer(guid);
}
if (permanent)
@@ -650,16 +650,16 @@ InstancePlayerBind* InstanceSaveManager::PlayerBindToInstance(uint32 guidLow, In
return &bind;
}
void InstanceSaveManager::PlayerUnbindInstance(uint32 guidLow, uint32 mapid, Difficulty difficulty, bool deleteFromDB, Player* player /*= nullptr*/)
void InstanceSaveManager::PlayerUnbindInstance(ObjectGuid guid, uint32 mapid, Difficulty difficulty, bool deleteFromDB, Player* player /*= nullptr*/)
{
BoundInstancesMapWrapper* w = playerBindStorage[guidLow];
BoundInstancesMapWrapper* w = playerBindStorage[guid];
BoundInstancesMap::iterator itr = w->m[difficulty].find(mapid);
if (itr != w->m[difficulty].end())
{
if (deleteFromDB)
{
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_INSTANCE_BY_INSTANCE_GUID);
stmt->setUInt32(0, guidLow);
stmt->setUInt32(0, guid.GetCounter());
stmt->setUInt32(1, itr->second.save->GetInstanceId());
CharacterDatabase.Execute(stmt);
}
@@ -669,13 +669,13 @@ void InstanceSaveManager::PlayerUnbindInstance(uint32 guidLow, uint32 mapid, Dif
InstanceSave* tmp = itr->second.save;
w->m[difficulty].erase(itr);
tmp->RemovePlayer(guidLow, this);
tmp->RemovePlayer(guid, this);
}
}
void InstanceSaveManager::PlayerUnbindInstanceNotExtended(uint32 guidLow, uint32 mapid, Difficulty difficulty, Player* player /*= nullptr*/)
void InstanceSaveManager::PlayerUnbindInstanceNotExtended(ObjectGuid guid, uint32 mapid, Difficulty difficulty, Player* player /*= nullptr*/)
{
BoundInstancesMapWrapper* w = playerBindStorage[guidLow];
BoundInstancesMapWrapper* w = playerBindStorage[guid];
BoundInstancesMap::iterator itr = w->m[difficulty].find(mapid);
if (itr != w->m[difficulty].end())
{
@@ -688,12 +688,12 @@ void InstanceSaveManager::PlayerUnbindInstanceNotExtended(uint32 guidLow, uint32
InstanceSave* tmp = itr->second.save;
w->m[difficulty].erase(itr);
tmp->RemovePlayer(guidLow, this);
tmp->RemovePlayer(guid, this);
}
}
}
InstancePlayerBind* InstanceSaveManager::PlayerGetBoundInstance(uint32 guidLow, uint32 mapid, Difficulty difficulty)
InstancePlayerBind* InstanceSaveManager::PlayerGetBoundInstance(ObjectGuid guid, uint32 mapid, Difficulty difficulty)
{
Difficulty difficulty_fixed = ( IsSharedDifficultyMap(mapid) ? Difficulty(difficulty % 2) : difficulty);
@@ -702,7 +702,7 @@ InstancePlayerBind* InstanceSaveManager::PlayerGetBoundInstance(uint32 guidLow,
return nullptr;
BoundInstancesMapWrapper* w = nullptr;
PlayerBindStorage::const_iterator itr = playerBindStorage.find(guidLow);
PlayerBindStorage::const_iterator itr = playerBindStorage.find(guid);
if (itr != playerBindStorage.end())
w = itr->second;
else
@@ -715,31 +715,31 @@ InstancePlayerBind* InstanceSaveManager::PlayerGetBoundInstance(uint32 guidLow,
return nullptr;
}
bool InstanceSaveManager::PlayerIsPermBoundToInstance(uint32 guidLow, uint32 mapid, Difficulty difficulty)
bool InstanceSaveManager::PlayerIsPermBoundToInstance(ObjectGuid guid, uint32 mapid, Difficulty difficulty)
{
if (InstancePlayerBind* bind = PlayerGetBoundInstance(guidLow, mapid, difficulty))
if (InstancePlayerBind* bind = PlayerGetBoundInstance(guid, mapid, difficulty))
if (bind->perm)
return true;
return false;
}
BoundInstancesMap const& InstanceSaveManager::PlayerGetBoundInstances(uint32 guidLow, Difficulty difficulty)
BoundInstancesMap const& InstanceSaveManager::PlayerGetBoundInstances(ObjectGuid guid, Difficulty difficulty)
{
PlayerBindStorage::iterator itr = playerBindStorage.find(guidLow);
PlayerBindStorage::iterator itr = playerBindStorage.find(guid);
if (itr != playerBindStorage.end())
return itr->second->m[difficulty];
return emptyBoundInstancesMap;
}
void InstanceSaveManager::PlayerCreateBoundInstancesMaps(uint32 guidLow)
void InstanceSaveManager::PlayerCreateBoundInstancesMaps(ObjectGuid guid)
{
if (playerBindStorage.find(guidLow) == playerBindStorage.end())
playerBindStorage[guidLow] = new BoundInstancesMapWrapper;
if (playerBindStorage.find(guid) == playerBindStorage.end())
playerBindStorage[guid] = new BoundInstancesMapWrapper;
}
InstanceSave* InstanceSaveManager::PlayerGetInstanceSave(uint32 guidLow, uint32 mapid, Difficulty difficulty)
InstanceSave* InstanceSaveManager::PlayerGetInstanceSave(ObjectGuid guid, uint32 mapid, Difficulty difficulty)
{
InstancePlayerBind* pBind = PlayerGetBoundInstance(guidLow, mapid, difficulty);
InstancePlayerBind* pBind = PlayerGetBoundInstance(guid, mapid, difficulty);
return (pBind ? pBind->save : nullptr);
}
@@ -748,19 +748,19 @@ uint32 InstanceSaveManager::PlayerGetDestinationInstanceId(Player* player, uint3
// returning 0 means a new instance will be created
// non-zero implicates that InstanceSave exists
InstancePlayerBind* ipb = PlayerGetBoundInstance(player->GetGUIDLow(), mapid, difficulty);
InstancePlayerBind* ipb = PlayerGetBoundInstance(player->GetGUID(), mapid, difficulty);
if (ipb && ipb->perm) // 1. self perm
return ipb->save->GetInstanceId();
if (Group* g = player->GetGroup())
{
if (InstancePlayerBind* ilb = PlayerGetBoundInstance(GUID_LOPART(g->GetLeaderGUID()), mapid, difficulty)) // 2. leader temp/perm
if (InstancePlayerBind* ilb = PlayerGetBoundInstance(g->GetLeaderGUID(), mapid, difficulty)) // 2. leader temp/perm
return ilb->save->GetInstanceId();
return 0; // 3. in group, no leader bind
}
return ipb ? ipb->save->GetInstanceId() : 0; // 4. self temp
}
void InstanceSaveManager::CopyBinds(uint32 from, uint32 to, Player* toPlr)
void InstanceSaveManager::CopyBinds(ObjectGuid from, ObjectGuid to, Player* toPlr)
{
if (from == to)
return;
@@ -776,7 +776,7 @@ void InstanceSaveManager::CopyBinds(uint32 from, uint32 to, Player* toPlr)
void InstanceSaveManager::UnbindAllFor(InstanceSave* save)
{
InstanceSave::PlayerListType& pList = save->m_playerList;
GuidList& pList = save->m_playerList;
while (!pList.empty())
PlayerUnbindInstance(*(pList.begin()), save->GetMapId(), save->GetDifficulty(), true, ObjectAccessor::GetObjectInOrOutOfWorld(MAKE_NEW_GUID(*(pList.begin()), 0, HIGHGUID_PLAYER), (Player*)nullptr));
PlayerUnbindInstance(*(pList.begin()), save->GetMapId(), save->GetDifficulty(), true, ObjectAccessor::FindConnectedPlayer(*(pList.begin())));
}

View File

@@ -31,14 +31,14 @@ struct InstancePlayerBind
InstancePlayerBind() : perm(false), extended(false) {}
};
typedef std::unordered_map< uint32 /*mapId*/, InstancePlayerBind > BoundInstancesMap;
typedef std::unordered_map<uint32 /*mapId*/, InstancePlayerBind > BoundInstancesMap;
struct BoundInstancesMapWrapper
{
BoundInstancesMap m[MAX_DIFFICULTY];
};
typedef std::unordered_map< uint32 /*guidLow*/, BoundInstancesMapWrapper* > PlayerBindStorage;
typedef std::unordered_map<ObjectGuid /*guid*/, BoundInstancesMapWrapper* > PlayerBindStorage;
class InstanceSave
{
@@ -72,12 +72,11 @@ public:
InstanceTemplate const* GetTemplate();
MapEntry const* GetMapEntry();
void AddPlayer(uint32 guidLow);
bool RemovePlayer(uint32 guidLow, InstanceSaveManager* ism);
void AddPlayer(ObjectGuid guid);
bool RemovePlayer(ObjectGuid guid, InstanceSaveManager* ism);
typedef std::list<uint32> PlayerListType;
private:
PlayerListType m_playerList;
GuidList m_playerList;
time_t m_resetTime;
time_t m_extendedResetTime;
uint32 m_instanceid;
@@ -159,16 +158,16 @@ public:
InstanceSave* GetInstanceSave(uint32 InstanceId);
InstancePlayerBind* PlayerBindToInstance(uint32 guidLow, InstanceSave* save, bool permanent, Player* player = nullptr);
void PlayerUnbindInstance(uint32 guidLow, uint32 mapid, Difficulty difficulty, bool deleteFromDB, Player* player = nullptr);
void PlayerUnbindInstanceNotExtended(uint32 guidLow, uint32 mapid, Difficulty difficulty, Player* player = nullptr);
InstancePlayerBind* PlayerGetBoundInstance(uint32 guidLow, uint32 mapid, Difficulty difficulty);
bool PlayerIsPermBoundToInstance(uint32 guidLow, uint32 mapid, Difficulty difficulty);
BoundInstancesMap const& PlayerGetBoundInstances(uint32 guidLow, Difficulty difficulty);
void PlayerCreateBoundInstancesMaps(uint32 guidLow);
InstanceSave* PlayerGetInstanceSave(uint32 guidLow, uint32 mapid, Difficulty difficulty);
InstancePlayerBind* PlayerBindToInstance(ObjectGuid guid, InstanceSave* save, bool permanent, Player* player = nullptr);
void PlayerUnbindInstance(ObjectGuid guid, uint32 mapid, Difficulty difficulty, bool deleteFromDB, Player* player = nullptr);
void PlayerUnbindInstanceNotExtended(ObjectGuid guid, uint32 mapid, Difficulty difficulty, Player* player = nullptr);
InstancePlayerBind* PlayerGetBoundInstance(ObjectGuid guid, uint32 mapid, Difficulty difficulty);
bool PlayerIsPermBoundToInstance(ObjectGuid guid, uint32 mapid, Difficulty difficulty);
BoundInstancesMap const& PlayerGetBoundInstances(ObjectGuid guid, Difficulty difficulty);
void PlayerCreateBoundInstancesMaps(ObjectGuid guid);
InstanceSave* PlayerGetInstanceSave(ObjectGuid guid, uint32 mapid, Difficulty difficulty);
uint32 PlayerGetDestinationInstanceId(Player* player, uint32 mapid, Difficulty difficulty);
void CopyBinds(uint32 from, uint32 to, Player* toPlr = nullptr);
void CopyBinds(ObjectGuid from, ObjectGuid to, Player* toPlr = nullptr);
void UnbindAllFor(InstanceSave* save);
protected:

View File

@@ -36,7 +36,7 @@ void InstanceScript::SaveToDB()
CharacterDatabase.Execute(stmt);
}
void InstanceScript::HandleGameObject(uint64 GUID, bool open, GameObject* go)
void InstanceScript::HandleGameObject(ObjectGuid GUID, bool open, GameObject* go)
{
if (!go)
go = instance->GetGameObject(GUID);
@@ -255,7 +255,7 @@ std::string InstanceScript::GetBossSaveData()
return saveStream.str();
}
void InstanceScript::DoUseDoorOrButton(uint64 uiGuid, uint32 uiWithRestoreTime, bool bUseAlternativeState)
void InstanceScript::DoUseDoorOrButton(ObjectGuid uiGuid, uint32 uiWithRestoreTime, bool bUseAlternativeState)
{
if (!uiGuid)
return;
@@ -276,7 +276,7 @@ void InstanceScript::DoUseDoorOrButton(uint64 uiGuid, uint32 uiWithRestoreTime,
}
}
void InstanceScript::DoRespawnGameObject(uint64 uiGuid, uint32 uiTimeToDespawn)
void InstanceScript::DoRespawnGameObject(ObjectGuid uiGuid, uint32 uiTimeToDespawn)
{
if (GameObject* go = instance->GetGameObject(uiGuid))
{
@@ -427,7 +427,7 @@ void InstanceScript::SendEncounterUnit(uint32 type, Unit* unit /*= nullptr*/, ui
case ENCOUNTER_FRAME_ENGAGE:
case ENCOUNTER_FRAME_DISENGAGE:
case ENCOUNTER_FRAME_UPDATE_PRIORITY:
data.append(unit->GetPackGUID());
data << unit->GetPackGUID();
data << uint8(param1);
break;
case ENCOUNTER_FRAME_ADD_TIMER:

View File

@@ -89,6 +89,12 @@ struct MinionData
uint32 entry, bossId;
};
struct ObjectData
{
uint32 entry;
uint32 type;
};
struct BossInfo
{
BossInfo() : state(TO_BE_DECIDED) {}
@@ -153,15 +159,15 @@ public:
virtual void OnPlayerAreaUpdate(Player* /*player*/, uint32 /*oldArea*/, uint32 /*newArea*/) {}
//Handle open / close objects
//use HandleGameObject(0, boolen, GO); in OnObjectCreate in instance scripts
//use HandleGameObject(ObjectGuid::Empty, boolen, GO); in OnObjectCreate in instance scripts
//use HandleGameObject(GUID, boolen, nullptr); in any other script
void HandleGameObject(uint64 guid, bool open, GameObject* go = nullptr);
void HandleGameObject(ObjectGuid guid, bool open, GameObject* go = nullptr);
//change active state of doors or buttons
void DoUseDoorOrButton(uint64 guid, uint32 withRestoreTime = 0, bool useAlternativeState = false);
void DoUseDoorOrButton(ObjectGuid guid, uint32 withRestoreTime = 0, bool useAlternativeState = false);
//Respawns a GO having negative spawntimesecs in gameobject-table
void DoRespawnGameObject(uint64 guid, uint32 timeToDespawn = MINUTE);
void DoRespawnGameObject(ObjectGuid guid, uint32 timeToDespawn = MINUTE);
//sends world state update to all players in instance
void DoUpdateWorldState(uint32 worldstateId, uint32 worldstateValue);