the bug is fixed

This commit is contained in:
JohnCorby 2021-11-18 22:23:39 -08:00
parent 1f422ef427
commit 17811547fa
3 changed files with 56 additions and 58 deletions

View File

@ -3,7 +3,6 @@ using QSB.Events;
using QSB.MeteorSync.WorldObjects; using QSB.MeteorSync.WorldObjects;
using QSB.Utility; using QSB.Utility;
using QSB.WorldSync; using QSB.WorldSync;
using UnityEngine;
using EventType = QSB.Events.EventType; using EventType = QSB.Events.EventType;
namespace QSB.MeteorSync.Events namespace QSB.MeteorSync.Events
@ -29,19 +28,21 @@ namespace QSB.MeteorSync.Events
ObjectId = qsbFragment.ObjectId, ObjectId = qsbFragment.ObjectId,
Integrity = qsbFragment.AttachedObject._integrity, Integrity = qsbFragment.AttachedObject._integrity,
OrigIntegrity = qsbFragment.AttachedObject._origIntegrity, OrigIntegrity = qsbFragment.AttachedObject._origIntegrity,
LeashLength = qsbFragment.LeashLength LeashLength = qsbFragment.LeashLength,
IsDetached = qsbFragment.IsDetached
}; };
if (qsbFragment.DetachableFragment != null && qsbFragment.DetachableFragment._isDetached) if (msg.IsDetached)
{ {
msg.IsThruWhiteHole = qsbFragment.IsThruWhiteHole; msg.IsThruWhiteHole = qsbFragment.IsThruWhiteHole;
var refBody = qsbFragment.RefBody;
var body = qsbFragment.Body; var body = qsbFragment.Body;
msg.Pos = refBody.transform.InverseTransformPoint(body.transform.position); var refBody = qsbFragment.RefBody;
msg.Rot = refBody.transform.InverseTransformRotation(body.transform.rotation); var pos = body.GetPosition();
msg.Vel = GetRelativeVelocity(body, refBody); msg.Pos = refBody.transform.InverseTransformPoint(pos);
msg.AngVel = body.GetRelativeAngularVelocity(refBody); msg.Rot = refBody.transform.InverseTransformRotation(body.GetRotation());
msg.Vel = body.GetVelocity() - refBody.GetPointVelocity(pos);
msg.AngVel = body.GetAngularVelocity() - refBody.GetAngularVelocity();
} }
return msg; return msg;
@ -60,18 +61,32 @@ namespace QSB.MeteorSync.Events
qsbFragment.LeashLength = msg.LeashLength; qsbFragment.LeashLength = msg.LeashLength;
qsbFragment.AttachedObject.CallOnTakeDamage(); qsbFragment.AttachedObject.CallOnTakeDamage();
if (qsbFragment.DetachableFragment != null && msg.Integrity <= 0) if (msg.IsDetached)
{ {
// the detach is delayed, so wait until that happens // the detach is delayed, so wait until that happens
QSBCore.UnityEvents.RunWhen(() => qsbFragment.DetachableFragment._isDetached, () => QSBCore.UnityEvents.RunWhen(() => qsbFragment.IsDetached, () =>
{ {
var body = qsbFragment.Body;
if (msg.IsThruWhiteHole && !qsbFragment.IsThruWhiteHole) if (msg.IsThruWhiteHole && !qsbFragment.IsThruWhiteHole)
{ {
qsbFragment.DetachableFragment.ChangeFragmentSector(MeteorManager.WhiteHoleVolume._whiteHoleSector, var whiteHoleVolume = MeteorManager.WhiteHoleVolume;
MeteorManager.WhiteHoleVolume._whiteHoleProxyShadowSuperGroup); var attachedFluidDetector = body.GetAttachedFluidDetector();
var attachedForceDetector = body.GetAttachedForceDetector();
if (attachedFluidDetector != null && attachedFluidDetector is ConstantFluidDetector constantFluidDetector)
{
constantFluidDetector.SetDetectableFluid(whiteHoleVolume._fluidVolume);
}
if (attachedForceDetector != null && attachedForceDetector is ConstantForceDetector constantForceDetector)
{
constantForceDetector.ClearAllFields();
}
qsbFragment.DetachableFragment.ChangeFragmentSector(whiteHoleVolume._whiteHoleSector,
whiteHoleVolume._whiteHoleProxyShadowSuperGroup);
qsbFragment.DetachableFragment.EndWarpScaling(); qsbFragment.DetachableFragment.EndWarpScaling();
qsbFragment.Body.gameObject.AddComponent<DebrisLeash>() body.gameObject.AddComponent<DebrisLeash>().Init(whiteHoleVolume._whiteHoleBody, qsbFragment.LeashLength);
.Init(MeteorManager.WhiteHoleVolume._whiteHoleBody, qsbFragment.LeashLength); whiteHoleVolume._ejectedBodyList.Add(body);
} }
else if (!msg.IsThruWhiteHole && qsbFragment.IsThruWhiteHole) else if (!msg.IsThruWhiteHole && qsbFragment.IsThruWhiteHole)
{ {
@ -79,41 +94,26 @@ namespace QSB.MeteorSync.Events
DebugLog.ToConsole($"{qsbFragment.LogName} is thru white hole, but msg is not. fuck", MessageType.Error); DebugLog.ToConsole($"{qsbFragment.LogName} is thru white hole, but msg is not. fuck", MessageType.Error);
return; return;
} }
if (qsbFragment.IsThruWhiteHole)
{
var debrisLeash = body.GetComponent<DebrisLeash>();
debrisLeash._deccelerating = false;
debrisLeash.enabled = true;
}
var refBody = qsbFragment.RefBody; var refBody = qsbFragment.RefBody;
var body = qsbFragment.Body; var pos = refBody.transform.TransformPoint(msg.Pos);
var targetPos = refBody.transform.TransformPoint(msg.Pos); body.SetPosition(pos);
var targetRot = refBody.transform.TransformRotation(msg.Rot); body.SetRotation(refBody.transform.TransformRotation(msg.Rot));
var targetVel = refBody.GetPointVelocity(targetPos) + msg.Vel; body.SetVelocity(msg.Vel + refBody.GetPointVelocity(pos));
var targetAngVel = refBody.GetAngularVelocity() + msg.AngVel; body.SetAngularVelocity(msg.AngVel + refBody.GetAngularVelocity());
body.MoveToPosition(targetPos);
body.MoveToRotation(targetRot);
SetVelocity(body, targetVel);
body.SetAngularVelocity(targetAngVel);
}); });
} }
} else if (!msg.IsDetached && qsbFragment.IsDetached)
// code yoink from transform sync lol
private static void SetVelocity(OWRigidbody rigidbody, Vector3 relativeVelocity)
{
var currentVelocity = rigidbody._currentVelocity;
if (rigidbody.RunningKinematicSimulation())
{ {
rigidbody._kinematicRigidbody.velocity = relativeVelocity + Locator.GetCenterOfTheUniverse().GetStaticFrameVelocity_Internal(); // should only happen if client is way too far ahead and they try to connect. we fail here.
DebugLog.ToConsole($"{qsbFragment.LogName} is detached, but msg is not. fuck", MessageType.Error);
} }
else
{
rigidbody._rigidbody.velocity = relativeVelocity + Locator.GetCenterOfTheUniverse().GetStaticFrameVelocity_Internal();
}
rigidbody._lastVelocity = currentVelocity;
rigidbody._currentVelocity = relativeVelocity;
} }
private static Vector3 GetRelativeVelocity(OWRigidbody body, OWRigidbody refBody)
=> body.GetVelocity() - refBody.GetPointVelocity(body.transform.position);
} }
} }

View File

@ -9,6 +9,7 @@ namespace QSB.MeteorSync.Events
public float Integrity; public float Integrity;
public float OrigIntegrity; public float OrigIntegrity;
public float LeashLength; public float LeashLength;
public bool IsDetached;
public bool IsThruWhiteHole; public bool IsThruWhiteHole;
public Vector3 Pos; public Vector3 Pos;
@ -22,7 +23,8 @@ namespace QSB.MeteorSync.Events
Integrity = reader.ReadSingle(); Integrity = reader.ReadSingle();
OrigIntegrity = reader.ReadSingle(); OrigIntegrity = reader.ReadSingle();
LeashLength = reader.ReadSingle(); LeashLength = reader.ReadSingle();
if (Integrity <= 0) IsDetached = reader.ReadBoolean();
if (IsDetached)
{ {
IsThruWhiteHole = reader.ReadBoolean(); IsThruWhiteHole = reader.ReadBoolean();
Pos = reader.ReadVector3(); Pos = reader.ReadVector3();
@ -38,7 +40,8 @@ namespace QSB.MeteorSync.Events
writer.Write(Integrity); writer.Write(Integrity);
writer.Write(OrigIntegrity); writer.Write(OrigIntegrity);
writer.Write(LeashLength); writer.Write(LeashLength);
if (Integrity <= 0) writer.Write(IsDetached);
if (IsDetached)
{ {
writer.Write(IsThruWhiteHole); writer.Write(IsThruWhiteHole);
writer.Write(Pos); writer.Write(Pos);

View File

@ -16,26 +16,21 @@ namespace QSB.MeteorSync.WorldObjects
if (QSBCore.IsHost) if (QSBCore.IsHost)
{ {
LeashLength = Random.Range(MeteorManager.WhiteHoleVolume._debrisDistMin, MeteorManager.WhiteHoleVolume._debrisDistMax); LeashLength = Random.Range(MeteorManager.WhiteHoleVolume._debrisDistMin, MeteorManager.WhiteHoleVolume._debrisDistMax);
// QSBCore.UnityEvents.FireOnNextUpdate(() =>
// {
// AttachedObject._integrity = 0;
// AttachedObject.CallOnTakeDamage();
// });
} }
} }
public DetachableFragment DetachableFragment; public DetachableFragment DetachableFragment;
public bool IsThruWhiteHole => DetachableFragment != null && DetachableFragment._sector != null && public bool IsDetached => DetachableFragment != null && DetachableFragment._isDetached;
public bool IsThruWhiteHole => IsDetached && DetachableFragment._sector != null &&
DetachableFragment._sector._parentSector == MeteorManager.WhiteHoleVolume._whiteHoleSector; DetachableFragment._sector._parentSector == MeteorManager.WhiteHoleVolume._whiteHoleSector;
public OWRigidbody RefBody => IsThruWhiteHole ? MeteorManager.WhiteHoleVolume._whiteHoleBody : Locator._brittleHollow._owRigidbody; public OWRigidbody RefBody => IsThruWhiteHole ? MeteorManager.WhiteHoleVolume._whiteHoleBody : Locator._brittleHollow._owRigidbody;
public OWRigidbody Body public OWRigidbody Body => IsDetached ? AttachedObject.transform.parent.parent.GetAttachedOWRigidbody() : null;
{
get
{
if (DetachableFragment != null && DetachableFragment._isDetached)
{
return AttachedObject.transform.parent.parent.GetAttachedOWRigidbody();
}
DebugLog.ToConsole($"{LogName} - trying to get rigidbody when not detached", MessageType.Error);
return null;
}
}
/// what the leash length will be when we eventually detach and fall thru white hole /// what the leash length will be when we eventually detach and fall thru white hole
public float LeashLength; public float LeashLength;