mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-17 01:13:05 +00:00
make sure integrity/origintegrity are synced on join
This commit is contained in:
parent
bc40e74d3b
commit
eca53e91d1
@ -26,7 +26,7 @@ namespace QSB.MeteorSync.Events
|
||||
|
||||
public override void OnReceiveRemote(bool isHost, FragmentDamageMessage message)
|
||||
{
|
||||
if (!QSBCore.WorldObjectsReady)
|
||||
if (!MeteorManager.Ready)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -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<QSBFragment>(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);
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
@ -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);
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ namespace QSB.MeteorSync.Events
|
||||
|
||||
public override void OnReceiveRemote(bool isHost, MeteorLaunchMessage message)
|
||||
{
|
||||
if (!QSBCore.WorldObjectsReady)
|
||||
if (!MeteorManager.Ready)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ namespace QSB.MeteorSync.Events
|
||||
|
||||
public override void OnReceiveRemote(bool isHost, WorldObjectMessage message)
|
||||
{
|
||||
if (!QSBCore.WorldObjectsReady)
|
||||
if (!MeteorManager.Ready)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -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<QSBMeteorLauncher, MeteorLauncher>();
|
||||
QSBWorldSync.Init<QSBFragment, FragmentIntegrity>();
|
||||
// wait a bit because meteors get created late
|
||||
QSBCore.UnityEvents.FireInNUpdates(() =>
|
||||
{
|
||||
QSBWorldSync.Init<QSBMeteorLauncher, MeteorLauncher>();
|
||||
QSBWorldSync.Init<QSBMeteor, MeteorController>();
|
||||
MeteorsReady = true;
|
||||
QSBWorldSync.Init<QSBFragment, FragmentIntegrity>();
|
||||
Ready = true;
|
||||
}, 10);
|
||||
}
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ namespace QSB.MeteorSync.Patches
|
||||
{
|
||||
var qsbFragment = QSBWorldSync.GetWorldFromUnity<QSBFragment>(__instance);
|
||||
QSBEventManager.FireEvent(EventNames.QSBFragmentDamage, qsbFragment, damage);
|
||||
DebugLog.DebugWrite($"{qsbFragment.LogName} - damage {damage}");
|
||||
DebugLog.DebugWrite($"{qsbFragment.LogName} - damage {damage} {__instance._integrity} / {__instance._origIntegrity}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ namespace QSB.MeteorSync.WorldObjects
|
||||
QNetworkServer.Destroy(TransformSync.gameObject);
|
||||
}
|
||||
|
||||
MeteorManager.MeteorsReady = false;
|
||||
MeteorManager.Ready = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,11 @@ namespace QSB.MeteorSync.WorldObjects
|
||||
AttachedObject = attachedObject;
|
||||
}
|
||||
|
||||
public override void OnRemoval()
|
||||
{
|
||||
MeteorManager.Ready = false;
|
||||
}
|
||||
|
||||
|
||||
public int MeteorId;
|
||||
public float LaunchSpeed;
|
||||
|
Loading…
Reference in New Issue
Block a user