diff --git a/EXILED/Exiled.API/Features/Generator.cs b/EXILED/Exiled.API/Features/Generator.cs index b19369208d..ef1603ed81 100644 --- a/EXILED/Exiled.API/Features/Generator.cs +++ b/EXILED/Exiled.API/Features/Generator.cs @@ -21,7 +21,7 @@ namespace Exiled.API.Features /// /// Wrapper class for . /// - public class Generator : IWrapper, IWorldSpace + public class Generator : IWrapper, IWorldSpace, IStructureSync { /// /// A of on the map. @@ -36,6 +36,7 @@ public class Generator : IWrapper, IWorldSpace internal Generator(Scp079Generator scp079Generator) { Base = scp079Generator; + PositionSync = scp079Generator.GetComponent(); Scp079GeneratorToGenerator.Add(scp079Generator, this); } @@ -201,14 +202,34 @@ public Player LastActivator } /// - /// Gets the generator position. + /// Gets or sets the position of the generator. /// - public Vector3 Position => Base.transform.position; + public Vector3 Position + { + get => Base.transform.position; + set + { + Base.transform.position = value; + PositionSync.Network_position = value; + } + } /// - /// Gets the generator rotation. + /// Gets or sets the rotation of the generator. /// - public Quaternion Rotation => Base.transform.rotation; + /// The setter only works in the y-axis (left to right) due to base game limitations. + public Quaternion Rotation + { + get => Base.transform.rotation; + set + { + Base.transform.rotation = Quaternion.Euler(0, value.eulerAngles.y, 0); + PositionSync.Network_rotationY = (sbyte)Mathf.RoundToInt(value.eulerAngles.y / 5.625F); + } + } + + /// + public StructurePositionSync PositionSync { get; } /// /// Gets or sets the required permissions to interact with the generator. diff --git a/EXILED/Exiled.API/Features/Lockers/Locker.cs b/EXILED/Exiled.API/Features/Lockers/Locker.cs index 734f849fb2..2a7d77fefb 100644 --- a/EXILED/Exiled.API/Features/Lockers/Locker.cs +++ b/EXILED/Exiled.API/Features/Lockers/Locker.cs @@ -27,7 +27,7 @@ namespace Exiled.API.Features.Lockers /// /// The in-game Locker. /// - public class Locker : IWrapper, IWorldSpace + public class Locker : IWrapper, IWorldSpace, IStructureSync { /// /// A containing all known s and their corresponding . @@ -41,6 +41,7 @@ public class Locker : IWrapper, IWorldSpace public Locker(BaseLocker locker) { Base = locker; + PositionSync = locker.GetComponent(); BaseToExiledLockers.Add(locker, this); Chambers = locker.Chambers.Select(x => new Chamber(x, this)).ToList(); @@ -72,11 +73,35 @@ public Locker(BaseLocker locker) /// public Transform Transform => Base.transform; - /// - public Vector3 Position => Base.transform.position; + /// + /// Gets or sets the position of the locker. + /// + public Vector3 Position + { + get => Base.transform.position; + set + { + Base.transform.position = value; + PositionSync.Network_position = value; + } + } - /// - public Quaternion Rotation => Base.transform.rotation; + /// + /// Gets or sets the rotation of the locker. + /// + /// The setter only works in the y-axis (left to right) due to base game limitations. + public Quaternion Rotation + { + get => Base.transform.rotation; + set + { + Base.transform.rotation = Quaternion.Euler(0, value.eulerAngles.y, 0); + PositionSync.Network_rotationY = (sbyte)Mathf.RoundToInt(value.eulerAngles.y / 5.625F); + } + } + + /// + public StructurePositionSync PositionSync { get; } /// /// Gets the in which the is located. diff --git a/EXILED/Exiled.API/Features/Workstation.cs b/EXILED/Exiled.API/Features/Workstation.cs index 7e7978a7ff..4272933a0d 100644 --- a/EXILED/Exiled.API/Features/Workstation.cs +++ b/EXILED/Exiled.API/Features/Workstation.cs @@ -15,13 +15,14 @@ namespace Exiled.API.Features using Exiled.API.Enums; using Exiled.API.Interfaces; using InventorySystem.Items.Firearms.Attachments; + using MapGeneration.Distributors; using Mirror; using UnityEngine; /// /// A wrapper class for . /// - public class Workstation : IWrapper, IWorldSpace + public class Workstation : IWrapper, IWorldSpace, IStructureSync { /// /// A dictionary mapping to . @@ -36,6 +37,7 @@ internal Workstation(WorkstationController workstationController) { WorkstationControllerToWorkstation.Add(workstationController, this); Base = workstationController; + PositionSync = workstationController.GetComponent(); } /// @@ -73,29 +75,31 @@ internal Workstation(WorkstationController workstationController) /// public Vector3 Position { - get => Transform.position; + get => Base.transform.position; set { - NetworkServer.UnSpawn(GameObject); - Transform.position = value; - NetworkServer.Spawn(GameObject); + Base.transform.position = value; + PositionSync.Network_position = value; } } /// - /// Gets or sets the rotation of the workstation. + /// Gets or sets the position of the workstation. /// + /// The setter only works in the y-axis (left to right) due to base game limitations. public Quaternion Rotation { - get => Transform.rotation; + get => Base.transform.rotation; set { - NetworkServer.UnSpawn(GameObject); - Transform.rotation = value; - NetworkServer.Spawn(GameObject); + Base.transform.rotation = Quaternion.Euler(0, value.eulerAngles.y, 0); + PositionSync.Network_rotationY = (sbyte)Mathf.RoundToInt(value.eulerAngles.y / 5.625F); } } + /// + public StructurePositionSync PositionSync { get; } + /// /// Gets or sets the status of the workstation. /// diff --git a/EXILED/Exiled.API/Interfaces/IStructureSync.cs b/EXILED/Exiled.API/Interfaces/IStructureSync.cs new file mode 100644 index 0000000000..92b6c6e1fe --- /dev/null +++ b/EXILED/Exiled.API/Interfaces/IStructureSync.cs @@ -0,0 +1,22 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) ExMod Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +namespace Exiled.API.Interfaces +{ + using MapGeneration.Distributors; + + /// + /// Represents an object with a . + /// + public interface IStructureSync + { + /// + /// Gets the of this structure. + /// + public StructurePositionSync PositionSync { get; } + } +} \ No newline at end of file