diff --git a/QSB/Utility/DebugActions.cs b/QSB/Utility/DebugActions.cs index bed3e1a7..fe3400c1 100644 --- a/QSB/Utility/DebugActions.cs +++ b/QSB/Utility/DebugActions.cs @@ -56,22 +56,10 @@ namespace QSB.Utility if (Keyboard.current[Key.Numpad1].wasPressedThisFrame) { - var otherPlayer = QSBPlayerManager.PlayerList.FirstOrDefault(x => x.PlayerId != QSBPlayerManager.LocalPlayerId); - if (otherPlayer != null && otherPlayer.Body != null) + var otherPlayer = QSBPlayerManager.PlayerList.FirstOrDefault(x => x != QSBPlayerManager.LocalPlayer); + if (otherPlayer != null) { - var playerBody = Locator.GetPlayerBody(); - playerBody.WarpToPositionRotation(otherPlayer.Body.transform.position, otherPlayer.Body.transform.rotation); - var parentBody = otherPlayer.TransformSync?.ReferenceSector?.AttachedObject?.GetOWRigidbody(); - if (parentBody != null) - { - playerBody.SetVelocity(parentBody.GetVelocity()); - playerBody.SetAngularVelocity(parentBody.GetAngularVelocity()); - } - else - { - playerBody.SetVelocity(Vector3.zero); - playerBody.SetAngularVelocity(Vector3.zero); - } + new DebugRequestTeleportInfoMessage(otherPlayer.PlayerId).Send(); } } @@ -92,7 +80,7 @@ namespace QSB.Utility if (Keyboard.current[Key.Numpad5].wasPressedThisFrame) { - new DebugMessage(DebugMessageEnum.TriggerSupernova).Send(); + new DebugTriggerSupernovaMessage().Send(); } if (Keyboard.current[Key.Numpad7].wasPressedThisFrame) diff --git a/QSB/Utility/Extensions.cs b/QSB/Utility/Extensions.cs index 72829c87..ad2ea87a 100644 --- a/QSB/Utility/Extensions.cs +++ b/QSB/Utility/Extensions.cs @@ -73,7 +73,7 @@ namespace QSB.Utility return; } - QNetworkServer.SpawnWithClientAuthority(go, QSBPlayerManager.LocalPlayer.TransformSync.gameObject); + QNetworkServer.SpawnWithClientAuthority(go, QNetworkServer.localConnection); } #endregion diff --git a/QSB/Utility/Messages/DebugMessage.cs b/QSB/Utility/Messages/DebugMessage.cs deleted file mode 100644 index e3332e87..00000000 --- a/QSB/Utility/Messages/DebugMessage.cs +++ /dev/null @@ -1,21 +0,0 @@ -using QSB.Messaging; - -namespace QSB.Utility.Messages -{ - public class DebugMessage : QSBEnumMessage - { - public DebugMessage(DebugMessageEnum type) => Value = type; - - public override void OnReceiveLocal() => OnReceiveRemote(); - - public override void OnReceiveRemote() - { - switch (Value) - { - case DebugMessageEnum.TriggerSupernova: - TimeLoop.SetSecondsRemaining(0f); - break; - } - } - } -} diff --git a/QSB/Utility/Messages/DebugMessageEnum.cs b/QSB/Utility/Messages/DebugMessageEnum.cs deleted file mode 100644 index 6ab9f289..00000000 --- a/QSB/Utility/Messages/DebugMessageEnum.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace QSB.Utility.Messages -{ - public enum DebugMessageEnum - { - TriggerSupernova - } -} \ No newline at end of file diff --git a/QSB/Utility/Messages/DebugTeleportInfoMessage.cs b/QSB/Utility/Messages/DebugTeleportInfoMessage.cs new file mode 100644 index 00000000..b0bccc9b --- /dev/null +++ b/QSB/Utility/Messages/DebugTeleportInfoMessage.cs @@ -0,0 +1,65 @@ +using QSB.Messaging; +using QSB.Player; +using QSB.Player.TransformSync; +using QuantumUNET.Transport; +using UnityEngine; + +namespace QSB.Utility.Messages +{ + public class DebugRequestTeleportInfoMessage : QSBMessage + { + public DebugRequestTeleportInfoMessage(uint to) => To = to; + + public override void OnReceiveRemote() => new DebugTeleportInfoMessage(From).Send(); + } + + public class DebugTeleportInfoMessage : QSBMessage + { + private float DegreesY; + private Vector3 Vel; + private Vector3 AngVel; + + public DebugTeleportInfoMessage(uint to) + { + To = to; + + var body = Locator.GetPlayerBody(); + var refBody = PlayerTransformSync.LocalInstance.ReferenceSector.AttachedObject.GetOWRigidbody(); + + DegreesY = Locator.GetPlayerCameraController().GetDegreesY(); + Vel = refBody.ToRelVel(body.GetVelocity(), body.GetPosition()); + AngVel = refBody.ToRelAngVel(body.GetAngularVelocity()); + } + + public override void Serialize(QNetworkWriter writer) + { + base.Serialize(writer); + writer.Write(DegreesY); + writer.Write(Vel); + writer.Write(AngVel); + } + + public override void Deserialize(QNetworkReader reader) + { + base.Deserialize(reader); + DegreesY = reader.ReadSingle(); + Vel = reader.ReadVector3(); + AngVel = reader.ReadVector3(); + } + + public override void OnReceiveRemote() + { + var otherPlayer = QSBPlayerManager.GetPlayer(From); + + var body = Locator.GetPlayerBody(); + var refBody = otherPlayer.TransformSync.ReferenceSector.AttachedObject.GetOWRigidbody(); + + var pos = otherPlayer.Body.transform.position; + var rot = otherPlayer.Body.transform.rotation; + body.WarpToPositionRotation(pos, rot); + Locator.GetPlayerCameraController().SetDegreesY(DegreesY); + body.SetVelocity(refBody.FromRelVel(Vel, pos)); + body.SetAngularVelocity(refBody.FromRelAngVel(AngVel)); + } + } +} diff --git a/QSB/Utility/Messages/DebugTriggerSupernovaMessage.cs b/QSB/Utility/Messages/DebugTriggerSupernovaMessage.cs new file mode 100644 index 00000000..702c5478 --- /dev/null +++ b/QSB/Utility/Messages/DebugTriggerSupernovaMessage.cs @@ -0,0 +1,10 @@ +using QSB.Messaging; + +namespace QSB.Utility.Messages +{ + public class DebugTriggerSupernovaMessage : QSBMessage + { + public override void OnReceiveLocal() => OnReceiveRemote(); + public override void OnReceiveRemote() => TimeLoop.SetSecondsRemaining(0); + } +}