From eca53e91d1a559d81c3740e0378774c57ba89654 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sat, 13 Nov 2021 21:15:01 -0800 Subject: [PATCH] make sure integrity/origintegrity are synced on join --- QSB/MeteorSync/Events/FragmentDamageEvent.cs | 2 +- QSB/MeteorSync/Events/FragmentResyncEvent.cs | 52 +++++++++---------- .../Events/FragmentResyncMessage.cs | 39 +++++++------- QSB/MeteorSync/Events/MeteorLaunchEvent.cs | 2 +- QSB/MeteorSync/Events/MeteorPreLaunchEvent.cs | 2 +- QSB/MeteorSync/MeteorManager.cs | 8 +-- QSB/MeteorSync/Patches/MeteorServerPatches.cs | 2 +- .../TransformSync/MeteorTransformSync.cs | 4 +- QSB/MeteorSync/WorldObjects/QSBFragment.cs | 8 ++- QSB/MeteorSync/WorldObjects/QSBMeteor.cs | 2 +- .../WorldObjects/QSBMeteorLauncher.cs | 5 ++ 11 files changed, 70 insertions(+), 56 deletions(-) diff --git a/QSB/MeteorSync/Events/FragmentDamageEvent.cs b/QSB/MeteorSync/Events/FragmentDamageEvent.cs index 624a8006..f58f1850 100644 --- a/QSB/MeteorSync/Events/FragmentDamageEvent.cs +++ b/QSB/MeteorSync/Events/FragmentDamageEvent.cs @@ -26,7 +26,7 @@ namespace QSB.MeteorSync.Events public override void OnReceiveRemote(bool isHost, FragmentDamageMessage message) { - if (!QSBCore.WorldObjectsReady) + if (!MeteorManager.Ready) { return; } diff --git a/QSB/MeteorSync/Events/FragmentResyncEvent.cs b/QSB/MeteorSync/Events/FragmentResyncEvent.cs index 77c77839..c33c9fb8 100644 --- a/QSB/MeteorSync/Events/FragmentResyncEvent.cs +++ b/QSB/MeteorSync/Events/FragmentResyncEvent.cs @@ -22,48 +22,48 @@ namespace QSB.MeteorSync.Events private FragmentResyncMessage CreateMessage(QSBFragment qsbFragment) { - return new FragmentResyncMessage(); var msg = new FragmentResyncMessage { ObjectId = qsbFragment.ObjectId, - Integrity = qsbFragment.AttachedObject.GetIntegrity() + Integrity = qsbFragment.AttachedObject._integrity, + OrigIntegrity = qsbFragment.AttachedObject._origIntegrity }; - if (msg.Integrity <= 0) - { - var refBody = Locator._brittleHollow.GetOWRigidbody(); - var body = qsbFragment.AttachedObject.GetAttachedOWRigidbody(); - msg.Pos = refBody.transform.InverseTransformPoint(body.transform.position); - msg.Rot = refBody.transform.InverseTransformRotation(body.transform.rotation); - msg.Vel = GetRelativeVelocity(body, refBody); - msg.AngVel = body.GetRelativeAngularVelocity(refBody); - } + // if (msg.Integrity <= 0) + // { + // var refBody = Locator._brittleHollow.GetOWRigidbody(); + // var body = qsbFragment.AttachedObject.GetAttachedOWRigidbody(); + // msg.Pos = refBody.transform.InverseTransformPoint(body.transform.position); + // msg.Rot = refBody.transform.InverseTransformRotation(body.transform.rotation); + // msg.Vel = GetRelativeVelocity(body, refBody); + // msg.AngVel = body.GetRelativeAngularVelocity(refBody); + // } return msg; } public override void OnReceiveRemote(bool isHost, FragmentResyncMessage msg) { - return; - if (!MeteorManager.MeteorsReady) + if (!MeteorManager.Ready) { return; } var qsbFragment = QSBWorldSync.GetWorldFromId(msg.ObjectId); qsbFragment.AttachedObject._integrity = msg.Integrity; - if (msg.Integrity <= 0) - { - var refBody = Locator._brittleHollow.GetOWRigidbody(); - var body = qsbFragment.AttachedObject.GetAttachedOWRigidbody(); - var targetPos = refBody.transform.TransformPoint(msg.Pos); - var targetRot = refBody.transform.TransformRotation(msg.Rot); - var targetVel = refBody.GetPointVelocity(targetPos) + msg.Vel; - var targetAngVel = refBody.GetAngularVelocity() + msg.AngVel; - body.MoveToPosition(targetPos); - body.MoveToRotation(targetRot); - SetVelocity(body, targetVel); - body.SetAngularVelocity(targetAngVel); - } + qsbFragment.AttachedObject._origIntegrity = msg.OrigIntegrity; + // if (msg.Integrity <= 0) + // { + // var refBody = Locator._brittleHollow.GetOWRigidbody(); + // var body = qsbFragment.AttachedObject.GetAttachedOWRigidbody(); + // var targetPos = refBody.transform.TransformPoint(msg.Pos); + // var targetRot = refBody.transform.TransformRotation(msg.Rot); + // var targetVel = refBody.GetPointVelocity(targetPos) + msg.Vel; + // var targetAngVel = refBody.GetAngularVelocity() + msg.AngVel; + // body.MoveToPosition(targetPos); + // body.MoveToRotation(targetRot); + // SetVelocity(body, targetVel); + // body.SetAngularVelocity(targetAngVel); + // } } diff --git a/QSB/MeteorSync/Events/FragmentResyncMessage.cs b/QSB/MeteorSync/Events/FragmentResyncMessage.cs index ef8d25e1..d2f149aa 100644 --- a/QSB/MeteorSync/Events/FragmentResyncMessage.cs +++ b/QSB/MeteorSync/Events/FragmentResyncMessage.cs @@ -7,35 +7,38 @@ namespace QSB.MeteorSync.Events public class FragmentResyncMessage : WorldObjectMessage { public float Integrity; - public Vector3 Pos; - public Quaternion Rot; - public Vector3 Vel; - public Vector3 AngVel; + public float OrigIntegrity; + // public Vector3 Pos; + // public Quaternion Rot; + // public Vector3 Vel; + // public Vector3 AngVel; public override void Deserialize(QNetworkReader reader) { base.Deserialize(reader); Integrity = reader.ReadSingle(); - if (Integrity <= 0) - { - Pos = reader.ReadVector3(); - Rot = reader.ReadQuaternion(); - Vel = reader.ReadVector3(); - AngVel = reader.ReadVector3(); - } + OrigIntegrity = reader.ReadSingle(); + // if (Integrity <= 0) + // { + // Pos = reader.ReadVector3(); + // Rot = reader.ReadQuaternion(); + // Vel = reader.ReadVector3(); + // AngVel = reader.ReadVector3(); + // } } public override void Serialize(QNetworkWriter writer) { base.Serialize(writer); writer.Write(Integrity); - if (Integrity <= 0) - { - writer.Write(Pos); - writer.Write(Rot); - writer.Write(Vel); - writer.Write(AngVel); - } + writer.Write(OrigIntegrity); + // if (Integrity <= 0) + // { + // writer.Write(Pos); + // writer.Write(Rot); + // writer.Write(Vel); + // writer.Write(AngVel); + // } } } } diff --git a/QSB/MeteorSync/Events/MeteorLaunchEvent.cs b/QSB/MeteorSync/Events/MeteorLaunchEvent.cs index 9ddc64f5..5bc089f9 100644 --- a/QSB/MeteorSync/Events/MeteorLaunchEvent.cs +++ b/QSB/MeteorSync/Events/MeteorLaunchEvent.cs @@ -27,7 +27,7 @@ namespace QSB.MeteorSync.Events public override void OnReceiveRemote(bool isHost, MeteorLaunchMessage message) { - if (!QSBCore.WorldObjectsReady) + if (!MeteorManager.Ready) { return; } diff --git a/QSB/MeteorSync/Events/MeteorPreLaunchEvent.cs b/QSB/MeteorSync/Events/MeteorPreLaunchEvent.cs index 085ce3d0..df4d3a09 100644 --- a/QSB/MeteorSync/Events/MeteorPreLaunchEvent.cs +++ b/QSB/MeteorSync/Events/MeteorPreLaunchEvent.cs @@ -25,7 +25,7 @@ namespace QSB.MeteorSync.Events public override void OnReceiveRemote(bool isHost, WorldObjectMessage message) { - if (!QSBCore.WorldObjectsReady) + if (!MeteorManager.Ready) { return; } diff --git a/QSB/MeteorSync/MeteorManager.cs b/QSB/MeteorSync/MeteorManager.cs index 2736cd24..c20d5fd6 100644 --- a/QSB/MeteorSync/MeteorManager.cs +++ b/QSB/MeteorSync/MeteorManager.cs @@ -5,17 +5,17 @@ namespace QSB.MeteorSync { public class MeteorManager : WorldObjectManager { - public static bool MeteorsReady; + public static bool Ready; protected override void RebuildWorldObjects(OWScene scene) { - QSBWorldSync.Init(); - QSBWorldSync.Init(); // wait a bit because meteors get created late QSBCore.UnityEvents.FireInNUpdates(() => { + QSBWorldSync.Init(); QSBWorldSync.Init(); - MeteorsReady = true; + QSBWorldSync.Init(); + Ready = true; }, 10); } } diff --git a/QSB/MeteorSync/Patches/MeteorServerPatches.cs b/QSB/MeteorSync/Patches/MeteorServerPatches.cs index 4b366b28..9d925bea 100644 --- a/QSB/MeteorSync/Patches/MeteorServerPatches.cs +++ b/QSB/MeteorSync/Patches/MeteorServerPatches.cs @@ -146,7 +146,7 @@ namespace QSB.MeteorSync.Patches { var qsbFragment = QSBWorldSync.GetWorldFromUnity(__instance); QSBEventManager.FireEvent(EventNames.QSBFragmentDamage, qsbFragment, damage); - DebugLog.DebugWrite($"{qsbFragment.LogName} - damage {damage}"); + DebugLog.DebugWrite($"{qsbFragment.LogName} - damage {damage} {__instance._integrity} / {__instance._origIntegrity}"); } } } diff --git a/QSB/MeteorSync/TransformSync/MeteorTransformSync.cs b/QSB/MeteorSync/TransformSync/MeteorTransformSync.cs index 1e449e1a..200617e3 100644 --- a/QSB/MeteorSync/TransformSync/MeteorTransformSync.cs +++ b/QSB/MeteorSync/TransformSync/MeteorTransformSync.cs @@ -8,7 +8,7 @@ namespace QSB.MeteorSync.TransformSync { public class MeteorTransformSync : UnsectoredRigidbodySync { - public override bool IsReady => MeteorManager.MeteorsReady; + public override bool IsReady => MeteorManager.Ready; public override bool UseInterpolation => false; private QSBMeteor _qsbMeteor; @@ -68,7 +68,7 @@ namespace QSB.MeteorSync.TransformSync protected override void OnRenderObject() { - if (!QSBCore.WorldObjectsReady + if (!MeteorManager.Ready || !QSBCore.DebugMode || !QSBCore.ShowLinesInDebug || !IsReady diff --git a/QSB/MeteorSync/WorldObjects/QSBFragment.cs b/QSB/MeteorSync/WorldObjects/QSBFragment.cs index 3806e030..74652efd 100644 --- a/QSB/MeteorSync/WorldObjects/QSBFragment.cs +++ b/QSB/MeteorSync/WorldObjects/QSBFragment.cs @@ -11,10 +11,16 @@ namespace QSB.MeteorSync.WorldObjects AttachedObject = attachedObject; } + public override void OnRemoval() + { + MeteorManager.Ready = false; + } + + public void AddDamage(float damage) { AttachedObject.AddDamage(damage); - DebugLog.DebugWrite($"{LogName} - damage {damage}"); + DebugLog.DebugWrite($"{LogName} - damage {damage} {AttachedObject._integrity} / {AttachedObject._origIntegrity}"); } } } diff --git a/QSB/MeteorSync/WorldObjects/QSBMeteor.cs b/QSB/MeteorSync/WorldObjects/QSBMeteor.cs index 621a5aab..4762ed63 100644 --- a/QSB/MeteorSync/WorldObjects/QSBMeteor.cs +++ b/QSB/MeteorSync/WorldObjects/QSBMeteor.cs @@ -28,7 +28,7 @@ namespace QSB.MeteorSync.WorldObjects QNetworkServer.Destroy(TransformSync.gameObject); } - MeteorManager.MeteorsReady = false; + MeteorManager.Ready = false; } } } diff --git a/QSB/MeteorSync/WorldObjects/QSBMeteorLauncher.cs b/QSB/MeteorSync/WorldObjects/QSBMeteorLauncher.cs index e6775683..b926a63c 100644 --- a/QSB/MeteorSync/WorldObjects/QSBMeteorLauncher.cs +++ b/QSB/MeteorSync/WorldObjects/QSBMeteorLauncher.cs @@ -11,6 +11,11 @@ namespace QSB.MeteorSync.WorldObjects AttachedObject = attachedObject; } + public override void OnRemoval() + { + MeteorManager.Ready = false; + } + public int MeteorId; public float LaunchSpeed;