From f66c3aec14ab376b8a6c2b5f05e7910d852051d0 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Sun, 12 Jun 2022 00:22:32 -0400 Subject: [PATCH] Core/Players: Allow teleporting to a specific instance id Port From (https://github.com/TrinityCore/TrinityCore/commit/25c0aaa83fede6cd5214da00bb08a21c0b28c4be) --- Source/Game/Chat/Commands/GroupCommands.cs | 2 +- Source/Game/Chat/Commands/MiscCommands.cs | 4 +-- Source/Game/Entities/Player/Player.Fields.cs | 3 +++ Source/Game/Entities/Player/Player.cs | 27 +++++++++++++++----- Source/Game/Handlers/MovementHandler.cs | 2 +- 5 files changed, 27 insertions(+), 11 deletions(-) diff --git a/Source/Game/Chat/Commands/GroupCommands.cs b/Source/Game/Chat/Commands/GroupCommands.cs index 21824d94b..3d6bea7b1 100644 --- a/Source/Game/Chat/Commands/GroupCommands.cs +++ b/Source/Game/Chat/Commands/GroupCommands.cs @@ -427,7 +427,7 @@ namespace Game.Chat // before GM float x, y, z; gmPlayer.GetClosePoint(out x, out y, out z, player.GetCombatReach()); - player.TeleportTo(gmPlayer.GetMapId(), x, y, z, player.GetOrientation()); + player.TeleportTo(gmPlayer.GetMapId(), x, y, z, player.GetOrientation(), 0, gmPlayer.GetInstanceId()); } return true; diff --git a/Source/Game/Chat/Commands/MiscCommands.cs b/Source/Game/Chat/Commands/MiscCommands.cs index 08874c184..118b99550 100644 --- a/Source/Game/Chat/Commands/MiscCommands.cs +++ b/Source/Game/Chat/Commands/MiscCommands.cs @@ -140,7 +140,7 @@ namespace Game.Chat float x, y, z; target.GetClosePoint(out x, out y, out z, _player.GetCombatReach(), 1.0f); - _player.TeleportTo(target.GetMapId(), x, y, z, _player.GetAbsoluteAngle(target), TeleportToOptions.GMMode); + _player.TeleportTo(target.GetMapId(), x, y, z, _player.GetAbsoluteAngle(target), TeleportToOptions.GMMode, target.GetInstanceId()); PhasingHandler.InheritPhaseShift(_player, target); _player.UpdateObjectVisibility(); } @@ -1856,7 +1856,7 @@ namespace Game.Chat // before GM float x, y, z; _player.GetClosePoint(out x, out y, out z, target.GetCombatReach()); - target.TeleportTo(_player.GetMapId(), x, y, z, target.GetOrientation()); + target.TeleportTo(_player.GetMapId(), x, y, z, target.GetOrientation(), 0, map.GetInstanceId()); PhasingHandler.InheritPhaseShift(target, _player); target.UpdateObjectVisibility(); } diff --git a/Source/Game/Entities/Player/Player.Fields.cs b/Source/Game/Entities/Player/Player.Fields.cs index 53f2c4e17..43613c208 100644 --- a/Source/Game/Entities/Player/Player.Fields.cs +++ b/Source/Game/Entities/Player/Player.Fields.cs @@ -95,6 +95,7 @@ namespace Game.Entities uint m_lastFallTime; float m_lastFallZ; WorldLocation teleportDest; + uint? m_teleport_instanceId; TeleportToOptions m_teleport_options; bool mSemaphoreTeleport_Near; bool mSemaphoreTeleport_Far; @@ -138,6 +139,7 @@ namespace Game.Entities // Player summoning long m_summon_expire; WorldLocation m_summon_location; + uint m_summon_instanceId; RestMgr _restMgr; @@ -225,6 +227,7 @@ namespace Game.Entities // Recall position WorldLocation m_recall_location; + uint m_recall_instanceId; WorldLocation homebind = new(); uint homebindAreaId; uint m_HomebindTimer; diff --git a/Source/Game/Entities/Player/Player.cs b/Source/Game/Entities/Player/Player.cs index 6400ad15d..09c030fde 100644 --- a/Source/Game/Entities/Player/Player.cs +++ b/Source/Game/Entities/Player/Player.cs @@ -1651,11 +1651,11 @@ namespace Game.Entities void SetCanDelayTeleport(bool setting) { m_bCanDelayTeleport = setting; } bool IsHasDelayedTeleport() { return m_bHasDelayedTeleport; } void SetDelayedTeleportFlag(bool setting) { m_bHasDelayedTeleport = setting; } - public bool TeleportTo(WorldLocation loc, TeleportToOptions options = 0) + public bool TeleportTo(WorldLocation loc, TeleportToOptions options = 0, uint? instanceId = null) { - return TeleportTo(loc.GetMapId(), loc.posX, loc.posY, loc.posZ, loc.Orientation, options); + return TeleportTo(loc.GetMapId(), loc.posX, loc.posY, loc.posZ, loc.Orientation, options, instanceId); } - public bool TeleportTo(uint mapid, float x, float y, float z, float orientation, TeleportToOptions options = 0) + public bool TeleportTo(uint mapid, float x, float y, float z, float orientation, TeleportToOptions options = 0, uint? instanceId = null) { if (!GridDefines.IsValidMapCoord(mapid, x, y, z, orientation)) { @@ -1721,7 +1721,7 @@ namespace Game.Entities if (duel != null && GetMapId() != mapid && GetMap().GetGameObject(m_playerData.DuelArbiter)) DuelComplete(DuelCompleteType.Fled); - if (GetMapId() == mapid) + if (GetMapId() == mapid && (!instanceId.HasValue || GetInstanceId() == instanceId)) { //lets reset far teleport flag if it wasn't reset during chained teleports SetSemaphoreTeleportFar(false); @@ -1734,6 +1734,7 @@ namespace Game.Entities SetSemaphoreTeleportNear(true); //lets save teleport destination for player teleportDest = new WorldLocation(mapid, x, y, z, orientation); + m_teleport_instanceId = null; m_teleport_options = options; return true; } @@ -1753,6 +1754,7 @@ namespace Game.Entities // this will be used instead of the current location in SaveToDB teleportDest = new WorldLocation(mapid, x, y, z, orientation); + m_teleport_instanceId = null; m_teleport_options = options; SetFallInformation(0, GetPositionZ()); @@ -1793,6 +1795,7 @@ namespace Game.Entities SetSemaphoreTeleportFar(true); //lets save teleport destination for player teleportDest = new WorldLocation(mapid, x, y, z, orientation); + m_teleport_instanceId = instanceId; m_teleport_options = options; return true; } @@ -1866,6 +1869,7 @@ namespace Game.Entities oldmap.RemovePlayerFromMap(this, false); teleportDest = new WorldLocation(mapid, x, y, z, orientation); + m_teleport_instanceId = instanceId; m_teleport_options = options; SetFallInformation(0, GetPositionZ()); // if the player is saved before worldportack (at logout for example) @@ -2079,6 +2083,7 @@ namespace Game.Entities m_summon_expire = GameTime.GetGameTime() + PlayerConst.MaxPlayerSummonDelay; m_summon_location = new WorldLocation(summoner); + m_summon_instanceId = summoner.GetInstanceId(); SummonRequest summonRequest = new(); summonRequest.SummonerGUID = summoner.GetGUID(); @@ -2166,8 +2171,7 @@ namespace Game.Entities UpdateCriteria(CriteriaType.AcceptSummon, 1); RemoveAurasWithInterruptFlags(SpellAuraInterruptFlags.Summon); - m_summon_location.SetOrientation(GetOrientation()); - TeleportTo(m_summon_location); + TeleportTo(m_summon_location, 0, m_summon_instanceId); broadcastSummonResponse(true); } @@ -5872,8 +5876,10 @@ namespace Game.Entities public void SaveRecallPosition() { m_recall_location = new WorldLocation(this); + m_recall_instanceId = GetInstanceId(); } - public void Recall() { TeleportTo(m_recall_location); } + + public void Recall() { TeleportTo(m_recall_location, 0, m_recall_instanceId); } public uint GetSaveTimer() { return m_nextSave; } void SetSaveTimer(uint timer) { m_nextSave = timer; } @@ -7615,10 +7621,17 @@ namespace Game.Entities { return teleportDest; } + + public uint? GetTeleportDestInstanceId() + { + return m_teleport_instanceId; + } + public WorldLocation GetHomebind() { return homebind; } + public WorldLocation GetRecall() { return m_recall_location; diff --git a/Source/Game/Handlers/MovementHandler.cs b/Source/Game/Handlers/MovementHandler.cs index 9944d4ab8..9a9efedf5 100644 --- a/Source/Game/Handlers/MovementHandler.cs +++ b/Source/Game/Handlers/MovementHandler.cs @@ -254,7 +254,7 @@ namespace Game player.m_InstanceValid = true; Map oldMap = player.GetMap(); - Map newMap = Global.MapMgr.CreateMap(loc.GetMapId(), player); + Map newMap = GetPlayer().GetTeleportDestInstanceId().HasValue ? Global.MapMgr.FindMap(loc.GetMapId(), GetPlayer().GetTeleportDestInstanceId().Value) : Global.MapMgr.CreateMap(loc.GetMapId(), GetPlayer()); if (player.IsInWorld) {