better debug teleport

This commit is contained in:
JohnCorby 2021-12-29 00:57:06 -08:00
parent efcbb6730b
commit 800d4a86bb
6 changed files with 80 additions and 45 deletions

View File

@ -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)

View File

@ -73,7 +73,7 @@ namespace QSB.Utility
return;
}
QNetworkServer.SpawnWithClientAuthority(go, QSBPlayerManager.LocalPlayer.TransformSync.gameObject);
QNetworkServer.SpawnWithClientAuthority(go, QNetworkServer.localConnection);
}
#endregion

View File

@ -1,21 +0,0 @@
using QSB.Messaging;
namespace QSB.Utility.Messages
{
public class DebugMessage : QSBEnumMessage<DebugMessageEnum>
{
public DebugMessage(DebugMessageEnum type) => Value = type;
public override void OnReceiveLocal() => OnReceiveRemote();
public override void OnReceiveRemote()
{
switch (Value)
{
case DebugMessageEnum.TriggerSupernova:
TimeLoop.SetSecondsRemaining(0f);
break;
}
}
}
}

View File

@ -1,7 +0,0 @@
namespace QSB.Utility.Messages
{
public enum DebugMessageEnum
{
TriggerSupernova
}
}

View File

@ -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));
}
}
}

View File

@ -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);
}
}