2021-10-20 17:29:49 +01:00
|
|
|
|
using OWML.Common;
|
|
|
|
|
using QSB.Syncs.Unsectored.Transforms;
|
2021-04-28 10:02:16 +01:00
|
|
|
|
using QSB.Utility;
|
|
|
|
|
using QSB.WorldSync;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace QSB.OrbSync.TransformSync
|
|
|
|
|
{
|
2021-08-14 15:03:01 +01:00
|
|
|
|
internal class NomaiOrbTransformSync : UnsectoredTransformSync
|
2021-04-28 10:02:16 +01:00
|
|
|
|
{
|
2021-11-20 19:49:50 +00:00
|
|
|
|
public static List<NomaiOrbTransformSync> OrbTransformSyncs = new();
|
2021-04-28 10:02:16 +01:00
|
|
|
|
|
2021-12-10 22:13:39 +00:00
|
|
|
|
public override bool IsPlayerObject => false;
|
|
|
|
|
|
2021-04-28 10:02:16 +01:00
|
|
|
|
private int _index => OrbTransformSyncs.IndexOf(this);
|
|
|
|
|
|
2021-05-19 11:52:39 +01:00
|
|
|
|
public override void OnStartClient() => OrbTransformSyncs.Add(this);
|
2021-04-28 10:02:16 +01:00
|
|
|
|
|
|
|
|
|
protected override void OnDestroy()
|
|
|
|
|
{
|
|
|
|
|
OrbTransformSyncs.Remove(this);
|
2021-08-19 17:34:21 +01:00
|
|
|
|
base.OnDestroy();
|
2021-04-28 10:02:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Init()
|
|
|
|
|
{
|
2021-10-25 16:31:15 +01:00
|
|
|
|
if (!OrbTransformSyncs.Contains(this))
|
|
|
|
|
{
|
|
|
|
|
OrbTransformSyncs.Add(this);
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-28 10:02:16 +01:00
|
|
|
|
base.Init();
|
2021-10-24 10:47:25 +01:00
|
|
|
|
|
|
|
|
|
if (AttachedObject == null)
|
|
|
|
|
{
|
|
|
|
|
DebugLog.ToConsole($"Error - Trying to init orb with null AttachedObject.", MessageType.Error);
|
2021-10-25 16:31:15 +01:00
|
|
|
|
return;
|
2021-10-24 10:47:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-09 15:54:16 +01:00
|
|
|
|
var originalParent = AttachedObject.GetAttachedOWRigidbody().GetOrigParent();
|
|
|
|
|
if (originalParent == Locator.GetRootTransform())
|
|
|
|
|
{
|
2021-11-10 21:51:14 -08:00
|
|
|
|
DebugLog.DebugWrite($"{LogName} with AttachedObject {AttachedObject.name} had it's original parent as SolarSystemRoot - Disabling...");
|
2021-10-20 17:29:49 +01:00
|
|
|
|
enabled = false;
|
|
|
|
|
OrbTransformSyncs[_index] = null;
|
2021-07-09 15:54:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SetReferenceTransform(originalParent);
|
2021-04-28 10:02:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-07 22:12:41 +01:00
|
|
|
|
private Transform GetTransform()
|
2021-05-08 12:53:09 +01:00
|
|
|
|
{
|
2021-05-18 15:22:21 +01:00
|
|
|
|
if (_index == -1)
|
|
|
|
|
{
|
2021-10-24 10:47:25 +01:00
|
|
|
|
DebugLog.ToConsole($"Error - Index cannot be found. OrbTransformSyncs count : {OrbTransformSyncs.Count}", MessageType.Error);
|
2021-05-18 15:22:21 +01:00
|
|
|
|
return null;
|
|
|
|
|
}
|
2021-06-18 22:38:32 +01:00
|
|
|
|
|
2021-05-08 12:53:09 +01:00
|
|
|
|
if (QSBWorldSync.OldOrbList == null || QSBWorldSync.OldOrbList.Count <= _index)
|
|
|
|
|
{
|
2021-10-20 17:29:49 +01:00
|
|
|
|
DebugLog.ToConsole($"Error - OldOrbList is null or does not contain index {_index}.", MessageType.Error);
|
2021-05-08 12:53:09 +01:00
|
|
|
|
return null;
|
|
|
|
|
}
|
2021-06-18 22:38:32 +01:00
|
|
|
|
|
2021-05-08 16:57:01 +01:00
|
|
|
|
if (QSBWorldSync.OldOrbList[_index] == null)
|
|
|
|
|
{
|
2021-10-20 17:29:49 +01:00
|
|
|
|
DebugLog.ToConsole($"Error - OldOrbList index {_index} is null.", MessageType.Error);
|
2021-05-08 16:57:01 +01:00
|
|
|
|
return null;
|
|
|
|
|
}
|
2021-06-18 22:38:32 +01:00
|
|
|
|
|
2021-07-07 22:12:41 +01:00
|
|
|
|
return QSBWorldSync.OldOrbList[_index].transform;
|
2021-05-08 12:53:09 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-13 12:42:27 -08:00
|
|
|
|
protected override Transform InitLocalTransform() => GetTransform();
|
|
|
|
|
protected override Transform InitRemoteTransform() => GetTransform();
|
2021-04-28 10:02:16 +01:00
|
|
|
|
|
2021-08-19 17:34:21 +01:00
|
|
|
|
protected override float DistanceLeeway => 1f;
|
2021-12-04 09:51:27 +00:00
|
|
|
|
public override bool IsReady => WorldObjectManager.AllObjectsReady;
|
2021-12-13 14:38:20 -08:00
|
|
|
|
public override bool UseInterpolation => true;
|
2021-04-28 10:02:16 +01:00
|
|
|
|
}
|
|
|
|
|
}
|