2020-09-02 11:17:04 +01:00
|
|
|
|
using OWML.Common;
|
2021-07-10 20:35:07 +01:00
|
|
|
|
using OWML.Utils;
|
2021-05-15 14:10:51 +01:00
|
|
|
|
using QSB.SectorSync;
|
2021-08-14 15:03:01 +01:00
|
|
|
|
using QSB.Syncs.Sectored.Transforms;
|
2021-05-03 20:27:52 +01:00
|
|
|
|
using QSB.Tools;
|
2021-07-26 22:55:09 +01:00
|
|
|
|
using QSB.Tools.ProbeLauncherTool;
|
2020-08-23 10:07:43 +02:00
|
|
|
|
using QSB.Utility;
|
2021-07-11 16:18:47 +01:00
|
|
|
|
using QSB.WorldSync;
|
2020-08-07 20:39:07 +01:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2021-04-11 17:05:02 +01:00
|
|
|
|
namespace QSB.ProbeSync.TransformSync
|
2020-08-07 20:39:07 +01:00
|
|
|
|
{
|
2021-04-28 00:22:08 +01:00
|
|
|
|
public class PlayerProbeSync : SectoredTransformSync
|
2020-12-14 21:20:53 +00:00
|
|
|
|
{
|
2021-07-11 16:18:47 +01:00
|
|
|
|
protected override float DistanceLeeway => 10f;
|
|
|
|
|
public override bool UseInterpolation => true;
|
|
|
|
|
public override bool IgnoreDisabledAttachedObject => true;
|
|
|
|
|
|
2021-04-20 08:36:07 +01:00
|
|
|
|
public static PlayerProbeSync LocalInstance { get; private set; }
|
2021-04-21 16:49:30 +01:00
|
|
|
|
|
2021-07-12 22:02:50 +01:00
|
|
|
|
public override void OnStartAuthority() => LocalInstance = this;
|
2021-04-20 08:36:07 +01:00
|
|
|
|
|
2021-07-07 23:54:09 +01:00
|
|
|
|
protected override Component InitLocalTransform()
|
2020-12-14 21:20:53 +00:00
|
|
|
|
{
|
2021-08-21 19:53:37 +01:00
|
|
|
|
QSBCore.UnityEvents.RunWhen(() => WorldObjectManager.AllReady, () => SectorSync.Init(Locator.GetProbe().GetSectorDetector(), TargetType.Probe));
|
2020-12-14 21:41:56 +01:00
|
|
|
|
|
2021-07-04 16:03:45 +01:00
|
|
|
|
var body = Locator.GetProbe().transform;
|
2020-12-14 21:20:53 +00:00
|
|
|
|
Player.ProbeBody = body.gameObject;
|
2020-12-14 21:41:56 +01:00
|
|
|
|
|
2021-07-04 16:03:45 +01:00
|
|
|
|
if (Player.Body == null)
|
|
|
|
|
{
|
|
|
|
|
DebugLog.ToConsole($"Warning - Player.Body is null!", MessageType.Warning);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var listener = Player.Body.AddComponent<ProbeListener>();
|
|
|
|
|
listener.Init(Locator.GetProbe());
|
|
|
|
|
|
2021-07-26 22:55:09 +01:00
|
|
|
|
var launcherListener = Player.Body.AddComponent<ProbeLauncherListener>();
|
|
|
|
|
launcherListener.Init(Player.LocalProbeLauncher);
|
|
|
|
|
|
2021-05-15 11:25:47 +01:00
|
|
|
|
return body;
|
2020-12-14 21:20:53 +00:00
|
|
|
|
}
|
2020-12-14 21:41:56 +01:00
|
|
|
|
|
2021-07-07 23:54:09 +01:00
|
|
|
|
protected override Component InitRemoteTransform()
|
2020-12-14 21:20:53 +00:00
|
|
|
|
{
|
2021-07-03 21:51:13 +01:00
|
|
|
|
var probe = Locator.GetProbe().transform;
|
2020-12-14 21:41:56 +01:00
|
|
|
|
|
2020-12-14 21:20:53 +00:00
|
|
|
|
if (probe == null)
|
|
|
|
|
{
|
|
|
|
|
DebugLog.ToConsole("Error - Probe is null!", MessageType.Error);
|
|
|
|
|
return default;
|
|
|
|
|
}
|
2020-12-14 21:41:56 +01:00
|
|
|
|
|
2021-07-13 22:20:15 +01:00
|
|
|
|
var body = probe.gameObject.activeSelf
|
|
|
|
|
? probe.InstantiateInactive()
|
|
|
|
|
: Instantiate(probe);
|
|
|
|
|
|
2020-12-14 21:20:53 +00:00
|
|
|
|
body.name = "RemoteProbeTransform";
|
2020-12-14 21:41:56 +01:00
|
|
|
|
|
2020-12-14 21:20:53 +00:00
|
|
|
|
PlayerToolsManager.CreateProbe(body, Player);
|
2020-12-14 21:41:56 +01:00
|
|
|
|
|
2020-12-14 21:20:53 +00:00
|
|
|
|
Player.ProbeBody = body.gameObject;
|
2020-12-14 21:41:56 +01:00
|
|
|
|
|
2021-05-15 11:25:47 +01:00
|
|
|
|
return body;
|
2020-12-14 21:20:53 +00:00
|
|
|
|
}
|
2020-12-14 21:41:56 +01:00
|
|
|
|
|
2021-07-11 16:18:47 +01:00
|
|
|
|
protected override bool UpdateTransform()
|
2021-07-10 20:35:07 +01:00
|
|
|
|
{
|
2021-07-11 16:18:47 +01:00
|
|
|
|
if (!base.UpdateTransform())
|
2021-07-10 20:35:07 +01:00
|
|
|
|
{
|
2021-07-11 16:18:47 +01:00
|
|
|
|
return false;
|
2021-07-10 20:35:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (HasAuthority)
|
|
|
|
|
{
|
|
|
|
|
if (!AttachedObject.gameObject.activeInHierarchy)
|
|
|
|
|
{
|
|
|
|
|
var probeOWRigidbody = Locator.GetProbe().GetComponent<SurveyorProbe>().GetOWRigidbody();
|
|
|
|
|
if (probeOWRigidbody == null)
|
|
|
|
|
{
|
|
|
|
|
DebugLog.ToConsole($"Warning - Could not find OWRigidbody of local probe.", MessageType.Warning);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var probeLauncher = Player.LocalProbeLauncher;
|
2021-07-25 00:27:52 +01:00
|
|
|
|
// TODO : make this sync to the *active* probe launcher's _launcherTransform
|
2021-07-10 20:35:07 +01:00
|
|
|
|
var launcherTransform = probeLauncher.GetValue<Transform>("_launcherTransform");
|
|
|
|
|
probeOWRigidbody.SetPosition(launcherTransform.position);
|
|
|
|
|
probeOWRigidbody.SetRotation(launcherTransform.rotation);
|
|
|
|
|
|
|
|
|
|
_intermediaryTransform.EncodePosition(AttachedObject.transform.position);
|
|
|
|
|
_intermediaryTransform.EncodeRotation(AttachedObject.transform.rotation);
|
|
|
|
|
|
|
|
|
|
var currentReferenceSector = ReferenceSector;
|
|
|
|
|
var playerReferenceSector = Player.TransformSync.ReferenceSector;
|
|
|
|
|
|
|
|
|
|
if (currentReferenceSector != playerReferenceSector)
|
|
|
|
|
{
|
|
|
|
|
SetReferenceSector(playerReferenceSector);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-11 16:18:47 +01:00
|
|
|
|
return true;
|
2021-07-10 20:35:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-17 09:51:47 +01:00
|
|
|
|
public override bool IsReady => Locator.GetProbe() != null;
|
2020-12-14 21:20:53 +00:00
|
|
|
|
}
|
2020-12-03 08:28:05 +00:00
|
|
|
|
}
|