From 9b924522d0549dd67b10e2cbdfc20297dd21e182 Mon Sep 17 00:00:00 2001 From: Shauren Date: Thu, 2 Jan 2020 14:19:35 +0100 Subject: Core/Instances: Delete InstanceSaveMgr and replace most of its uses with new InstanceLockMgr --- src/server/game/Maps/MapManager.cpp | 44 ++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'src/server/game/Maps/MapManager.cpp') diff --git a/src/server/game/Maps/MapManager.cpp b/src/server/game/Maps/MapManager.cpp index 8a525d2b64e..788d27301a4 100644 --- a/src/server/game/Maps/MapManager.cpp +++ b/src/server/game/Maps/MapManager.cpp @@ -23,7 +23,6 @@ #include "GarrisonMap.h" #include "Group.h" #include "InstanceLockMgr.h" -#include "InstanceSaveMgr.h" #include "Log.h" #include "Map.h" #include "Player.h" @@ -250,6 +249,49 @@ Map* MapManager::FindMap(uint32 mapId, uint32 instanceId) const return FindMap_i(mapId, instanceId); } +uint32 MapManager::FindInstanceIdForPlayer(uint32 mapId, Player const* player) const +{ + MapEntry const* entry = sMapStore.LookupEntry(mapId); + if (!entry) + return 0; + + if (entry->IsBattlegroundOrArena()) + return player->GetBattlegroundId(); + else if (entry->IsDungeon()) + { + Group const* group = player->GetGroup(); + Difficulty difficulty = group ? group->GetDifficultyID(entry) : player->GetDifficultyID(entry); + MapDb2Entries entries{ entry, sDB2Manager.GetDownscaledMapDifficultyData(mapId, difficulty) }; + ObjectGuid instanceOwnerGuid = group ? group->GetRecentInstanceOwner(mapId) : player->GetGUID(); + InstanceLock* instanceLock = sInstanceLockMgr.FindActiveInstanceLock(instanceOwnerGuid, entries); + uint32 newInstanceId = 0; + if (instanceLock) + newInstanceId = instanceLock->GetInstanceId(); + else if (!entries.MapDifficulty->HasResetSchedule()) // Try finding instance id for normal dungeon + newInstanceId = group ? group->GetRecentInstanceId(mapId) : player->GetRecentInstanceId(mapId); + + if (!newInstanceId) + return 0; + + Map* map = FindMap(mapId, newInstanceId); + + // is is possible that instance id is already in use by another group for boss-based locks + if (!entries.IsInstanceIdBound() && instanceLock && map && map->ToInstanceMap()->GetInstanceLock() != instanceLock) + return 0; + + return newInstanceId; + } + else if (entry->IsGarrison()) + return uint32(player->GetGUID().GetCounter()); + else + { + if (entry->IsSplitByFaction()) + return player->GetTeamId(); + + return 0; + } +} + void MapManager::Update(uint32 diff) { i_timer.Update(diff); -- cgit v1.2.3