From c3df9bae16d8ba64131ce61a4bcaed3111c3f5be Mon Sep 17 00:00:00 2001 From: Hondacrx Date: Sun, 17 Nov 2024 13:51:42 -0500 Subject: [PATCH] Core/Position: Position constructor improvements Port From (https://github.com/TrinityCore/TrinityCore/commit/d6ae7030dac388bbdf79954bd235c98209b53630) --- Source/Game/Entities/Object/Position.cs | 34 ++++++++++++++++++++++--- Source/Game/Garrisons/Garrisons.cs | 14 ++++------ 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/Source/Game/Entities/Object/Position.cs b/Source/Game/Entities/Object/Position.cs index 5410aa1d5..6adcfa448 100644 --- a/Source/Game/Entities/Object/Position.cs +++ b/Source/Game/Entities/Object/Position.cs @@ -16,6 +16,21 @@ namespace Game.Entities public float posZ; public float Orientation; + public Position() { } + + public Position(float x = 0f, float y = 0f) + { + posX = x; + posY = y; + } + + public Position(float x = 0f, float y = 0f, float z = 0f) + { + posX = x; + posY = y; + posZ = z; + } + public Position(float x = 0f, float y = 0f, float z = 0f, float o = 0f) { posX = x; @@ -407,11 +422,24 @@ namespace Game.Entities public Position _newPosition = new(); - public WorldLocation(uint mapId = 0xFFFFFFFF, float x = 0, float y = 0, float z = 0, float o = 0) + public WorldLocation() + { + _mapId = 0xFFFFFFFF; + } + + public WorldLocation(uint mapId = 0xFFFFFFFF, float x = 0, float y = 0) : base(x, y) { _mapId = mapId; - Relocate(x, y, z, o); } + public WorldLocation(uint mapId = 0xFFFFFFFF, float x = 0, float y = 0, float z = 0) : base(x, y, z) + { + _mapId = mapId; + } + public WorldLocation(uint mapId = 0xFFFFFFFF, float x = 0, float y = 0, float z = 0, float o = 0) : base(x, y, z, o) + { + _mapId = mapId; + } + public WorldLocation(uint mapId, Position pos) { _mapId = mapId; @@ -440,7 +468,7 @@ namespace Game.Entities Relocate(loc); } - public void WorldRelocate(uint mapId = 0xFFFFFFFF, float x = 0.0f, float y = 0.0f, float z = 0.0f, float o = 0.0f) + public void WorldRelocate(uint mapId, float x, float y, float z, float o) { _mapId = mapId; Relocate(x, y, z, o); diff --git a/Source/Game/Garrisons/Garrisons.cs b/Source/Game/Garrisons/Garrisons.cs index 957185d3d..c53576bdf 100644 --- a/Source/Game/Garrisons/Garrisons.cs +++ b/Source/Game/Garrisons/Garrisons.cs @@ -266,20 +266,16 @@ namespace Game.Garrisons void Enter() { - WorldLocation loc = new(_siteLevel.MapID); - loc.Relocate(_owner); - _owner.TeleportTo(loc, TeleportToOptions.Seamless); + MapRecord map = CliDB.MapStorage.LookupByKey(_siteLevel.MapID); + if (map != null && _owner.GetMapId() == map.ParentMapID) + _owner.TeleportTo(new WorldLocation(_siteLevel.MapID, _owner), TeleportToOptions.Seamless); } void Leave() { MapRecord map = CliDB.MapStorage.LookupByKey(_siteLevel.MapID); - if (map != null) - { - WorldLocation loc = new((uint)map.ParentMapID); - loc.Relocate(_owner); - _owner.TeleportTo(loc, TeleportToOptions.Seamless); - } + if (map != null && _owner.GetMapId() == _siteLevel.MapID) + _owner.TeleportTo(new WorldLocation((uint)map.ParentMapID, _owner), TeleportToOptions.Seamless); } public uint GetFaction()