diff options
| author | Shauren <shauren.trinity@gmail.com> | 2020-01-02 14:19:35 +0100 |
|---|---|---|
| committer | Shauren <shauren.trinity@gmail.com> | 2022-10-04 00:19:38 +0200 |
| commit | 9b924522d0549dd67b10e2cbdfc20297dd21e182 (patch) | |
| tree | f0fcdf96902b7c497c1bc65db83621a8dfadf43a /src/server/game/Maps | |
| parent | a131542855d23022714a97640be1c8d68a741c31 (diff) | |
Core/Instances: Delete InstanceSaveMgr and replace most of its uses with new InstanceLockMgr
Diffstat (limited to 'src/server/game/Maps')
| -rw-r--r-- | src/server/game/Maps/Map.cpp | 86 | ||||
| -rw-r--r-- | src/server/game/Maps/Map.h | 11 | ||||
| -rw-r--r-- | src/server/game/Maps/MapManager.cpp | 44 | ||||
| -rw-r--r-- | src/server/game/Maps/MapManager.h | 1 |
4 files changed, 77 insertions, 65 deletions
diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp index 4c838cd7d09..5d2a530b9d7 100644 --- a/src/server/game/Maps/Map.cpp +++ b/src/server/game/Maps/Map.cpp @@ -33,7 +33,6 @@ #include "Group.h" #include "InstanceLockMgr.h" #include "InstancePackets.h" -#include "InstanceSaveMgr.h" #include "InstanceScenario.h" #include "InstanceScript.h" #include "Log.h" @@ -1813,16 +1812,14 @@ Map::EnterState Map::PlayerCannotEnter(uint32 mapid, Player* player, bool /*logi if (entry->Instanceable()) { //Get instance where player's group is bound & its map - if (uint32 instanceIdToCheck = sMapMgr->FindInstanceIdForPlayer(mapid, player)) - { - if (Map* boundMap = sMapMgr->FindMap(mapid, instanceIdToCheck)) - if (EnterState denyReason = boundMap->CannotEnter(player)) - return denyReason; + uint32 instanceIdToCheck = sMapMgr->FindInstanceIdForPlayer(mapid, player); + if (Map* boundMap = sMapMgr->FindMap(mapid, instanceIdToCheck)) + if (EnterState denyReason = boundMap->CannotEnter(player)) + return denyReason; - // players are only allowed to enter 10 instances per hour - if (entry->IsDungeon() && !player->CheckInstanceCount(instanceIdToCheck) && !player->isDead()) - return Map::CANNOT_ENTER_TOO_MANY_INSTANCES; - } + // players are only allowed to enter 10 instances per hour + if (entry->IsDungeon() && !player->CheckInstanceCount(instanceIdToCheck) && !player->isDead()) + return CANNOT_ENTER_TOO_MANY_INSTANCES; } return CAN_ENTER; @@ -2161,6 +2158,9 @@ void Map::DeleteRespawnInfo(RespawnInfo* info, CharacterDatabaseTransaction dbTr void Map::DeleteRespawnInfoFromDB(SpawnObjectType type, ObjectGuid::LowType spawnId, CharacterDatabaseTransaction dbTrans) { + if (Instanceable()) + return; + CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_RESPAWN); stmt->setUInt16(0, type); stmt->setUInt64(1, spawnId); @@ -2921,7 +2921,6 @@ void InstanceMap::RemovePlayerFromMap(Player* player, bool remove) // for normal instances schedule the reset after all players have left SetResetSchedule(true); - sInstanceSaveMgr->UnloadInstanceSave(GetInstanceId()); } void InstanceMap::CreateInstanceData() @@ -2967,13 +2966,14 @@ void InstanceMap::TrySetOwningGroup(Group* group) /* Returns true if there are no players in the instance */ -bool InstanceMap::Reset(uint8 method) +bool InstanceMap::Reset(InstanceResetMethod method) { // note: since the map may not be loaded when the instance needs to be reset - // the instance must be deleted from the DB by InstanceSaveManager + // the instance must be deleted from the DB if (HavePlayers()) { + // on manual reset, fail if (method == INSTANCE_RESET_ALL || method == INSTANCE_RESET_CHANGE_DIFFICULTY) { // notify the players to leave the instance so it can be reset @@ -2982,24 +2982,15 @@ bool InstanceMap::Reset(uint8 method) } else { - bool doUnload = true; + // on lock expiration boot players (do we also care about extension state?) if (method == INSTANCE_RESET_GLOBAL) { // set the homebind timer for players inside (1 minute) for (MapRefManager::iterator itr = m_mapRefManager.begin(); itr != m_mapRefManager.end(); ++itr) - { - InstancePlayerBind* bind = itr->GetSource()->GetBoundInstance(GetId(), GetDifficultyID()); - if (bind && bind->extendState && bind->save->GetInstanceId() == GetInstanceId()) - doUnload = false; - else - itr->GetSource()->m_InstanceValid = false; - } - - if (doUnload && HasPermBoundPlayers()) // check if any unloaded players have a nonexpired save to this - doUnload = false; + itr->GetSource()->m_InstanceValid = false; } - if (doUnload) + if (!HasPermBoundPlayers()) { // the unload timer is not started // instead the map will unload immediately after the players have left @@ -3107,25 +3098,8 @@ void InstanceMap::UnloadAll() Map::UnloadAll(); } -void InstanceMap::SendResetWarnings(uint32 timeLeft) const +void InstanceMap::SetResetSchedule(bool /*on*/) { - for (MapRefManager::const_iterator itr = m_mapRefManager.begin(); itr != m_mapRefManager.end(); ++itr) - itr->GetSource()->SendInstanceResetWarning(GetId(), itr->GetSource()->GetDifficultyID(GetEntry()), timeLeft, true); -} - -void InstanceMap::SetResetSchedule(bool on) -{ - // only for normal instances - // the reset time is only scheduled when there are no payers inside - // it is assumed that the reset time will rarely (if ever) change while the reset is scheduled - if (IsDungeon() && !HavePlayers() && !IsRaidOrHeroicDungeon()) - { - if (InstanceSave* save = sInstanceSaveMgr->GetInstanceSave(GetInstanceId())) - sInstanceSaveMgr->ScheduleReset(on, save->GetResetTime(), InstanceSaveManager::InstResetEvent(0, GetId(), GetDifficultyID(), GetInstanceId())); - else - TC_LOG_ERROR("maps", "InstanceMap::SetResetSchedule: cannot turn schedule %s, there is no save information for instance (map [id: %u, name: %s], instance id: %u, difficulty: %u)", - on ? "on" : "off", GetId(), GetMapName(), GetInstanceId(), static_cast<uint32>(GetDifficultyID())); - } } MapDifficultyEntry const* Map::GetMapDifficulty() const @@ -3170,11 +3144,6 @@ bool Map::IsRaid() const return i_mapEntry && i_mapEntry->IsRaid(); } -bool Map::IsRaidOrHeroicDungeon() const -{ - return IsRaid() || IsHeroic(); -} - bool Map::IsHeroic() const { if (DifficultyEntry const* difficulty = sDifficultyStore.LookupEntry(i_spawnMode)) @@ -3235,12 +3204,6 @@ uint32 InstanceMap::GetMaxPlayers() const return GetEntry()->MaxPlayers; } -uint32 InstanceMap::GetMaxResetDelay() const -{ - MapDifficultyEntry const* mapDiff = GetMapDifficulty(); - return mapDiff ? mapDiff->GetRaidDuration() : 0; -} - TeamId InstanceMap::GetTeamIdInInstance() const { if (sWorldStateMgr->GetValue(WS_TEAM_IN_INSTANCE_ALLIANCE, this)) @@ -3451,6 +3414,9 @@ void Map::SaveRespawnTime(SpawnObjectType type, ObjectGuid::LowType spawnId, uin void Map::SaveRespawnInfoDB(RespawnInfo const& info, CharacterDatabaseTransaction dbTrans) { + if (Instanceable()) + return; + CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_REP_RESPAWN); stmt->setUInt16(0, info.type); stmt->setUInt64(1, info.spawnId); @@ -3462,6 +3428,9 @@ void Map::SaveRespawnInfoDB(RespawnInfo const& info, CharacterDatabaseTransactio void Map::LoadRespawnTimes() { + if (Instanceable()) + return; + CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_RESPAWNS); stmt->setUInt16(0, GetId()); stmt->setUInt32(1, GetInstanceId()); @@ -3490,11 +3459,14 @@ void Map::LoadRespawnTimes() } } -/*static*/ void Map::DeleteRespawnTimesInDB(uint16 mapId, uint32 instanceId) +void Map::DeleteRespawnTimesInDB() { + if (Instanceable()) + return; + CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_ALL_RESPAWNS); - stmt->setUInt16(0, mapId); - stmt->setUInt32(1, instanceId); + stmt->setUInt16(0, GetId()); + stmt->setUInt32(1, GetInstanceId()); CharacterDatabase.Execute(stmt); } diff --git a/src/server/game/Maps/Map.h b/src/server/game/Maps/Map.h index e1e70b4ab6f..68a81710c64 100644 --- a/src/server/game/Maps/Map.h +++ b/src/server/game/Maps/Map.h @@ -52,7 +52,6 @@ class GameObjectModel; class Group; class InstanceLock; class InstanceMap; -class InstanceSave; class InstanceScript; class InstanceScenario; class Object; @@ -292,7 +291,6 @@ class TC_GAME_API Map : public GridRefManager<NGridType> bool IsDungeon() const; bool IsNonRaidDungeon() const; bool IsRaid() const; - bool IsRaidOrHeroicDungeon() const; bool IsHeroic() const; bool Is25ManRaid() const; bool IsBattleground() const; @@ -446,8 +444,8 @@ class TC_GAME_API Map : public GridRefManager<NGridType> void SaveRespawnTime(SpawnObjectType type, ObjectGuid::LowType spawnId, uint32 entry, time_t respawnTime, uint32 gridId, CharacterDatabaseTransaction dbTrans = nullptr, bool startup = false); void SaveRespawnInfoDB(RespawnInfo const& info, CharacterDatabaseTransaction dbTrans = nullptr); void LoadRespawnTimes(); - void DeleteRespawnTimes() { UnloadAllRespawnInfos(); DeleteRespawnTimesInDB(GetId(), GetInstanceId()); } - static void DeleteRespawnTimesInDB(uint16 mapId, uint32 instanceId); + void DeleteRespawnTimes() { UnloadAllRespawnInfos(); DeleteRespawnTimesInDB(); } + void DeleteRespawnTimesInDB(); void LoadCorpseData(); void DeleteCorpseData(); @@ -807,7 +805,7 @@ class TC_GAME_API InstanceMap : public Map void RemovePlayerFromMap(Player*, bool) override; void Update(uint32) override; void CreateInstanceData(); - bool Reset(uint8 method); + bool Reset(InstanceResetMethod method); uint32 GetScriptId() const { return i_script_id; } std::string const& GetScriptName() const; InstanceScript* GetInstanceScript() { return i_data; } @@ -820,18 +818,17 @@ class TC_GAME_API InstanceMap : public Map void CreateInstanceLockForPlayer(Player* player); void UnloadAll() override; EnterState CannotEnter(Player* player) override; - void SendResetWarnings(uint32 timeLeft) const; void SetResetSchedule(bool on); /* this checks if any players have a permanent bind (included reactivatable expired binds) to the instance ID it needs a DB query, so use sparingly */ bool HasPermBoundPlayers() const; uint32 GetMaxPlayers() const; - uint32 GetMaxResetDelay() const; TeamId GetTeamIdInInstance() const; Team GetTeamInInstance() const { return GetTeamIdInInstance() == TEAM_ALLIANCE ? ALLIANCE : HORDE; } virtual void InitVisibilityDistance() override; + Group* GetOwningGroup() const { return i_owningGroupRef.getTarget(); } void TrySetOwningGroup(Group* group); 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); diff --git a/src/server/game/Maps/MapManager.h b/src/server/game/Maps/MapManager.h index 474972707a8..5121fd5aeac 100644 --- a/src/server/game/Maps/MapManager.h +++ b/src/server/game/Maps/MapManager.h @@ -52,6 +52,7 @@ class TC_GAME_API MapManager Map* CreateMap(uint32 mapId, Player* player); Map* FindMap(uint32 mapId, uint32 instanceId) const; + uint32 FindInstanceIdForPlayer(uint32 mapId, Player const* player) const; void Initialize(); void Update(uint32 diff); |
