From 3461b6fcaaa86e357118a3afe4bf0d3bdd2c6c6a Mon Sep 17 00:00:00 2001 From: hondacrx Date: Mon, 4 Sep 2023 11:40:06 -0400 Subject: [PATCH] Core/AreaTriggers: Teleport to current instance entrance when entering instances via areatrigger entity Port From (https://github.com/TrinityCore/TrinityCore/commit/4e7508db7b70b2b79ee1fc77a1899d08173ffc62) --- .../Game/Entities/AreaTrigger/AreaTrigger.cs | 8 ++++ Source/Game/Entities/Player/Player.Map.cs | 39 +++++++++++++++++++ Source/Game/Handlers/MiscHandler.cs | 36 +---------------- 3 files changed, 49 insertions(+), 34 deletions(-) diff --git a/Source/Game/Entities/AreaTrigger/AreaTrigger.cs b/Source/Game/Entities/AreaTrigger/AreaTrigger.cs index c69ab7a55..89860e3ce 100644 --- a/Source/Game/Entities/AreaTrigger/AreaTrigger.cs +++ b/Source/Game/Entities/AreaTrigger/AreaTrigger.cs @@ -802,7 +802,15 @@ namespace Game.Entities { Player player = caster.ToPlayer(); if (player != null) + { + if (player.GetMapId() != safeLoc.Loc.GetMapId()) + { + WorldSafeLocsEntry instanceEntrance = player.GetInstanceEntrance(safeLoc.Loc.GetMapId()); + if (instanceEntrance != null) + safeLoc = instanceEntrance; + } player.TeleportTo(safeLoc.Loc); + } } break; default: diff --git a/Source/Game/Entities/Player/Player.Map.cs b/Source/Game/Entities/Player/Player.Map.cs index 6182f5bcc..74b45a4a3 100644 --- a/Source/Game/Entities/Player/Player.Map.cs +++ b/Source/Game/Entities/Player/Player.Map.cs @@ -466,6 +466,45 @@ namespace Game.Entities _instanceResetTimes.Add(instanceId, enterTime + Time.Hour); } + public WorldSafeLocsEntry GetInstanceEntrance(uint targetMapId) + { + WorldSafeLocsEntry entranceLocation = null; + MapRecord mapEntry = CliDB.MapStorage.LookupByKey(targetMapId); + + if (mapEntry.Instanceable()) + { + // Check if we can contact the instancescript of the instance for an updated entrance location + uint targetInstanceId = Global.MapMgr.FindInstanceIdForPlayer(targetMapId, this); + if (targetInstanceId != 0) + { + Map map = Global.MapMgr.FindMap(targetMapId, targetInstanceId); + if (map != null) + { + InstanceMap instanceMap = map.ToInstanceMap(); + if (instanceMap != null) + { + InstanceScript instanceScript = instanceMap.GetInstanceScript(); + if (instanceScript != null) + entranceLocation = Global.ObjectMgr.GetWorldSafeLoc(instanceScript.GetEntranceLocation()); + } + } + } + + // Finally check with the instancesave for an entrance location if we did not get a valid one from the instancescript + if (entranceLocation == null) + { + Group group = GetGroup(); + Difficulty difficulty = group != null ? group.GetDifficultyID(mapEntry) : GetDifficultyID(mapEntry); + ObjectGuid instanceOwnerGuid = group ? group.GetRecentInstanceOwner(targetMapId) : GetGUID(); + + InstanceLock instanceLock = Global.InstanceLockMgr.FindActiveInstanceLock(instanceOwnerGuid, new MapDb2Entries(mapEntry, Global.DB2Mgr.GetDownscaledMapDifficultyData(targetMapId, ref difficulty))); + if (instanceLock != null) + entranceLocation = Global.ObjectMgr.GetWorldSafeLoc(instanceLock.GetData().EntranceWorldSafeLocId); + } + } + return entranceLocation; + } + public void SendDungeonDifficulty(int forcedDifficulty = -1) { DungeonDifficultySet dungeonDifficultySet = new(); diff --git a/Source/Game/Handlers/MiscHandler.cs b/Source/Game/Handlers/MiscHandler.cs index f5757b0c3..be9f835aa 100644 --- a/Source/Game/Handlers/MiscHandler.cs +++ b/Source/Game/Handlers/MiscHandler.cs @@ -356,40 +356,8 @@ namespace Game if (!teleported) { - WorldSafeLocsEntry entranceLocation = null; - MapRecord mapEntry = CliDB.MapStorage.LookupByKey(at.target_mapId); - if (mapEntry.Instanceable()) - { - // Check if we can contact the instancescript of the instance for an updated entrance location - uint targetInstanceId = Global.MapMgr.FindInstanceIdForPlayer(at.target_mapId, _player); - if (targetInstanceId != 0) - { - Map map = Global.MapMgr.FindMap(at.target_mapId, targetInstanceId); - if (map != null) - { - InstanceMap instanceMap = map.ToInstanceMap(); - if (instanceMap) - { - InstanceScript instanceScript = instanceMap.GetInstanceScript(); - if (instanceScript != null) - entranceLocation = Global.ObjectMgr.GetWorldSafeLoc(instanceScript.GetEntranceLocation()); - } - } - } - - // Finally check with the instancesave for an entrance location if we did not get a valid one from the instancescript - if (entranceLocation == null) - { - Group group = player.GetGroup(); - Difficulty difficulty = group ? group.GetDifficultyID(mapEntry) : player.GetDifficultyID(mapEntry); - ObjectGuid instanceOwnerGuid = group ? group.GetRecentInstanceOwner(at.target_mapId) : player.GetGUID(); - InstanceLock instanceLock = Global.InstanceLockMgr.FindActiveInstanceLock(instanceOwnerGuid, new MapDb2Entries(mapEntry, Global.DB2Mgr.GetDownscaledMapDifficultyData(at.target_mapId, ref difficulty))); - if (instanceLock != null) - entranceLocation = Global.ObjectMgr.GetWorldSafeLoc(instanceLock.GetData().EntranceWorldSafeLocId); - } - } - - if (entranceLocation != null) + WorldSafeLocsEntry entranceLocation = player.GetInstanceEntrance(at.target_mapId); + if (entranceLocation != null && player.GetMapId() != at.target_mapId) player.TeleportTo(entranceLocation.Loc, TeleportToOptions.NotLeaveTransport); else player.TeleportTo(at.target_mapId, at.target_X, at.target_Y, at.target_Z, at.target_Orientation, TeleportToOptions.NotLeaveTransport);