From e377263feabcef08643b8a74b74208f4152bd9af Mon Sep 17 00:00:00 2001 From: hondacrx Date: Tue, 4 Oct 2022 20:05:57 -0400 Subject: [PATCH] Core/Instances: Add instance reset events at lock expiration Port From (https://github.com/TrinityCore/TrinityCore/commit/20357af88ec9265869cca3c1db3c5f43ef37e587) --- .../Maps/Instances/InstanceLockManager.cs | 1 - Source/Game/Maps/Map.cs | 42 +++++++++++++++---- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/Source/Game/Maps/Instances/InstanceLockManager.cs b/Source/Game/Maps/Instances/InstanceLockManager.cs index 6485f1739..f4563e26f 100644 --- a/Source/Game/Maps/Instances/InstanceLockManager.cs +++ b/Source/Game/Maps/Instances/InstanceLockManager.cs @@ -279,7 +279,6 @@ namespace Game.Maps if (instanceLock.IsExpired()) { - Cypher.Assert(instanceLock.IsExtended(), "Instance lock must have been extended to create instance map from it"); instanceLock.SetExpiryTime(GetNextResetTime(entries)); instanceLock.SetExtended(false); Log.outDebug(LogFilter.Instance, $"[{entries.Map.Id}-{entries.Map.MapName[Global.WorldMgr.GetDefaultDbcLocale()]} | " + diff --git a/Source/Game/Maps/Map.cs b/Source/Game/Maps/Map.cs index a3fab9243..94c507105 100644 --- a/Source/Game/Maps/Map.cs +++ b/Source/Game/Maps/Map.cs @@ -4770,7 +4770,10 @@ namespace Game.Maps Global.WorldStateMgr.SetValue(WorldStates.TeamInInstanceHorde, instanceTeam == TeamId.Horde ? 1 : 0, false, this); if (i_instanceLock != null) + { i_instanceLock.SetInUse(true); + i_instanceExpireEvent = i_instanceLock.GetExpiryTime(); // ignore extension state for reset event (will ask players to accept extended save on expiration) + } } ~InstanceMap() @@ -4795,9 +4798,6 @@ namespace Game.Maps return EnterState.CannotEnterAlreadyInMap; } - if (m_shuttingDown) - return EnterState.CannotEnterInstanceShuttingDown; - // allow GM's to enter if (player.IsGameMaster()) return base.CannotEnter(player); @@ -4883,6 +4883,12 @@ namespace Game.Maps if (i_scenario != null) i_scenario.Update(diff); + + if (i_instanceExpireEvent.HasValue && i_instanceExpireEvent.Value < GameTime.GetSystemTime()) + { + Reset(InstanceResetMethod.Expire); + i_instanceExpireEvent = Global.InstanceLockMgr.GetNextResetTime(new MapDb2Entries(GetEntry(), GetMapDifficulty())); + } } public override void RemovePlayerFromMap(Player player, bool remove) @@ -4894,7 +4900,7 @@ namespace Game.Maps // if last player set unload timer if (m_unloadTimer == 0 && GetPlayers().Count == 1) - m_unloadTimer = m_shuttingDown ? 1 : (uint)Math.Max(WorldConfig.GetIntValue(WorldCfg.InstanceUnloadDelay), 1); + m_unloadTimer = (i_instanceLock != null && i_instanceLock.IsExpired()) ? 1 : (uint)Math.Max(WorldConfig.GetIntValue(WorldCfg.InstanceUnloadDelay), 1); if (i_scenario != null) i_scenario.OnPlayerExit(player); @@ -4964,12 +4970,30 @@ namespace Game.Maps // no client notification break; case InstanceResetMethod.Expire: - // on lock expiration boot players (do we also care about extension state?) - // set the homebind timer for players inside (1 minute) + { + RaidInstanceMessage raidInstanceMessage = new(); + raidInstanceMessage.Type = InstanceResetWarningType.Expired; + raidInstanceMessage.MapID = GetId(); + raidInstanceMessage.DifficultyID = GetDifficultyID(); + raidInstanceMessage.Write(); + + PendingRaidLock pendingRaidLock = new(); + pendingRaidLock.TimeUntilLock = 60000; + pendingRaidLock.CompletedMask = i_instanceLock.GetData().CompletedEncountersMask; + pendingRaidLock.Extending = true; + pendingRaidLock.WarningOnly = GetEntry().IsFlexLocking(); + pendingRaidLock.Write(); + foreach (Player player in GetPlayers()) - player.m_InstanceValid = false; - m_shuttingDown = true; + { + player.SendPacket(raidInstanceMessage); + player.SendPacket(pendingRaidLock); + + if (!pendingRaidLock.WarningOnly) + player.SetPendingBind(GetInstanceId(), 60000); + } break; + } default: break; } @@ -5150,7 +5174,7 @@ namespace Game.Maps InstanceScenario i_scenario; InstanceLock i_instanceLock; GroupInstanceReference i_owningGroupRef = new(); - bool m_shuttingDown; + DateTime? i_instanceExpireEvent; } public class BattlegroundMap : Map