resync event done

This commit is contained in:
JohnCorby 2021-11-15 00:29:36 -08:00
parent e4b54452a4
commit 558221491e
3 changed files with 43 additions and 31 deletions

View File

@ -1,4 +1,5 @@
using System; using System;
using OWML.Common;
using QSB.Events; using QSB.Events;
using QSB.MeteorSync.WorldObjects; using QSB.MeteorSync.WorldObjects;
using QSB.Utility; using QSB.Utility;
@ -33,20 +34,14 @@ namespace QSB.MeteorSync.Events
if (msg.Integrity <= 0) if (msg.Integrity <= 0)
{ {
var detachableFragment = qsbFragment.AttachedObject.GetRequiredComponent<DetachableFragment>(); msg.IsThruWhiteHole = qsbFragment.IsThruWhiteHole;
msg.IsThruWhitehole = detachableFragment._sector._parentSector == MeteorManager.WhiteHoleVolume._whiteHoleSector; var refBody = GetRefBody(msg.IsThruWhiteHole);
var body = qsbFragment.AttachedObject.transform.parent.parent.GetAttachedOWRigidbody();
var refBody = GetRefBody(msg.IsThruWhitehole); if (msg.IsThruWhiteHole)
var body = detachableFragment.transform.parent.parent.GetAttachedOWRigidbody();
if (!body.CompareTag("DetachedFragment"))
{ {
throw new Exception("HUGE BRUH MOMENT"); msg.LeashLength = qsbFragment.LeashLength;
}
if (msg.IsThruWhitehole)
{
msg.LeashLength = body.gameObject.GetRequiredComponent<DebrisLeash>()._leashLength;
} }
msg.Pos = refBody.transform.InverseTransformPoint(body.transform.position); msg.Pos = refBody.transform.InverseTransformPoint(body.transform.position);
@ -75,23 +70,26 @@ namespace QSB.MeteorSync.Events
// the detach is delay, so wait even more until that happens lol // the detach is delay, so wait even more until that happens lol
QSBCore.UnityEvents.FireInNUpdates(() => QSBCore.UnityEvents.FireInNUpdates(() =>
{ {
var detachableFragment = qsbFragment.AttachedObject.GetRequiredComponent<DetachableFragment>(); var refBody = GetRefBody(msg.IsThruWhiteHole);
var body = qsbFragment.AttachedObject.transform.parent.parent.GetAttachedOWRigidbody();
var refBody = GetRefBody(msg.IsThruWhitehole); if (msg.IsThruWhiteHole && !qsbFragment.IsThruWhiteHole)
var body = detachableFragment.transform.parent.parent.GetAttachedOWRigidbody();
if (!body.CompareTag("DetachedFragment"))
{ {
throw new Exception("HUGE BRUH MOMENT"); qsbFragment.DetachableFragment.ChangeFragmentSector(MeteorManager.WhiteHoleVolume._whiteHoleSector,
}
if (msg.IsThruWhitehole
&& detachableFragment._sector._parentSector != MeteorManager.WhiteHoleVolume._whiteHoleSector)
{
detachableFragment.ChangeFragmentSector(MeteorManager.WhiteHoleVolume._whiteHoleSector,
MeteorManager.WhiteHoleVolume._whiteHoleProxyShadowSuperGroup); MeteorManager.WhiteHoleVolume._whiteHoleProxyShadowSuperGroup);
body.gameObject.AddComponent<DebrisLeash>().Init(MeteorManager.WhiteHoleVolume._whiteHoleBody, body.gameObject.AddComponent<DebrisLeash>().Init(MeteorManager.WhiteHoleVolume._whiteHoleBody,
msg.LeashLength); msg.LeashLength);
} }
else if (msg.IsThruWhiteHole && qsbFragment.IsThruWhiteHole)
{
qsbFragment.LeashLength = msg.LeashLength;
}
else if (!msg.IsThruWhiteHole && qsbFragment.IsThruWhiteHole)
{
// should only happen if client is way too far ahead and they try to connect. we fail here.
DebugLog.ToConsole($"{qsbFragment.LogName} is thru white hole, but msg is not. goodbye", MessageType.Quit);
Application.Quit();
}
var targetPos = refBody.transform.TransformPoint(msg.Pos); var targetPos = refBody.transform.TransformPoint(msg.Pos);
var targetRot = refBody.transform.TransformRotation(msg.Rot); var targetRot = refBody.transform.TransformRotation(msg.Rot);
@ -106,16 +104,15 @@ namespace QSB.MeteorSync.Events
} }
private static OWRigidbody GetRefBody(bool isThruWhitehole) => private static OWRigidbody GetRefBody(bool isThruWhiteHole) =>
isThruWhitehole ? MeteorManager.WhiteHoleVolume._whiteHoleBody : Locator._brittleHollow._owRigidbody; isThruWhiteHole ? MeteorManager.WhiteHoleVolume._whiteHoleBody : Locator._brittleHollow._owRigidbody;
// code yoink from transform sync lol // code yoink from transform sync lol
private static void SetVelocity(OWRigidbody rigidbody, Vector3 relativeVelocity) private static void SetVelocity(OWRigidbody rigidbody, Vector3 relativeVelocity)
{ {
var isRunningKinematic = rigidbody.RunningKinematicSimulation();
var currentVelocity = rigidbody._currentVelocity; var currentVelocity = rigidbody._currentVelocity;
if (isRunningKinematic) if (rigidbody.RunningKinematicSimulation())
{ {
rigidbody._kinematicRigidbody.velocity = relativeVelocity + Locator.GetCenterOfTheUniverse().GetStaticFrameVelocity_Internal(); rigidbody._kinematicRigidbody.velocity = relativeVelocity + Locator.GetCenterOfTheUniverse().GetStaticFrameVelocity_Internal();
} }

View File

@ -13,7 +13,7 @@ namespace QSB.MeteorSync.Events
public Quaternion Rot; public Quaternion Rot;
public Vector3 Vel; public Vector3 Vel;
public Vector3 AngVel; public Vector3 AngVel;
public bool IsThruWhitehole; public bool IsThruWhiteHole;
public float LeashLength; public float LeashLength;
public override void Deserialize(QNetworkReader reader) public override void Deserialize(QNetworkReader reader)
@ -28,8 +28,8 @@ namespace QSB.MeteorSync.Events
Vel = reader.ReadVector3(); Vel = reader.ReadVector3();
AngVel = reader.ReadVector3(); AngVel = reader.ReadVector3();
IsThruWhitehole = reader.ReadBoolean(); IsThruWhiteHole = reader.ReadBoolean();
if (IsThruWhitehole) if (IsThruWhiteHole)
{ {
LeashLength = reader.ReadSingle(); LeashLength = reader.ReadSingle();
} }
@ -48,8 +48,8 @@ namespace QSB.MeteorSync.Events
writer.Write(Vel); writer.Write(Vel);
writer.Write(AngVel); writer.Write(AngVel);
writer.Write(IsThruWhitehole); writer.Write(IsThruWhiteHole);
if (IsThruWhitehole) if (IsThruWhiteHole)
{ {
writer.Write(LeashLength); writer.Write(LeashLength);
} }

View File

@ -8,6 +8,7 @@ namespace QSB.MeteorSync.WorldObjects
{ {
ObjectId = id; ObjectId = id;
AttachedObject = attachedObject; AttachedObject = attachedObject;
DetachableFragment = AttachedObject.GetRequiredComponent<DetachableFragment>();
} }
public override void OnRemoval() public override void OnRemoval()
@ -16,6 +17,20 @@ namespace QSB.MeteorSync.WorldObjects
} }
public DetachableFragment DetachableFragment;
public bool IsThruWhiteHole => DetachableFragment._sector._parentSector == MeteorManager.WhiteHoleVolume._whiteHoleSector;
public float LeashLength
{
get => AttachedObject.GetComponent<DebrisLeash>()._leashLength;
set
{
var debrisLeash = AttachedObject.GetComponent<DebrisLeash>();
debrisLeash._deccelerating = false;
debrisLeash._leashLength = value;
}
}
public void AddDamage(float damage) public void AddDamage(float damage)
{ {
AttachedObject.AddDamage(damage); AttachedObject.AddDamage(damage);