2020-09-02 11:17:04 +01:00
|
|
|
|
using OWML.Common;
|
2020-11-03 21:33:48 +00:00
|
|
|
|
using QSB.Player;
|
2020-09-02 11:17:04 +01:00
|
|
|
|
using QSB.Tools;
|
2021-04-11 17:05:02 +01:00
|
|
|
|
using QSB.TransformSync;
|
2020-08-23 10:07:43 +02:00
|
|
|
|
using QSB.Utility;
|
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-11 17:05:02 +01:00
|
|
|
|
public class PlayerProbeSync : SyncObjectTransformSync
|
2020-12-14 21:20:53 +00:00
|
|
|
|
{
|
|
|
|
|
private Transform _disabledSocket;
|
2020-12-14 21:41:56 +01:00
|
|
|
|
|
2020-12-14 21:48:41 +01:00
|
|
|
|
private Transform GetProbe() =>
|
2020-12-14 21:20:53 +00:00
|
|
|
|
Locator.GetProbe().transform.Find("CameraPivot").Find("Geometry");
|
2020-12-14 21:41:56 +01:00
|
|
|
|
|
2020-12-14 21:20:53 +00:00
|
|
|
|
protected override Transform InitLocalTransform()
|
|
|
|
|
{
|
2021-03-09 19:45:00 +00:00
|
|
|
|
SectorSync.SetSectorDetector(Locator.GetProbe().GetSectorDetector());
|
2020-12-14 21:20:53 +00:00
|
|
|
|
var body = GetProbe();
|
2020-12-14 21:41:56 +01:00
|
|
|
|
|
2020-12-22 09:13:08 +00:00
|
|
|
|
SetSocket(Player.CameraBody.transform);
|
2020-12-14 21:20:53 +00:00
|
|
|
|
Player.ProbeBody = body.gameObject;
|
2020-12-14 21:41:56 +01:00
|
|
|
|
|
2020-12-14 21:20:53 +00:00
|
|
|
|
return body;
|
|
|
|
|
}
|
2020-12-14 21:41:56 +01:00
|
|
|
|
|
2020-12-14 21:20:53 +00:00
|
|
|
|
protected override Transform InitRemoteTransform()
|
|
|
|
|
{
|
|
|
|
|
var probe = GetProbe();
|
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
|
|
|
|
|
2020-12-14 21:20:53 +00:00
|
|
|
|
var body = probe.InstantiateInactive();
|
|
|
|
|
body.name = "RemoteProbeTransform";
|
2020-12-14 21:41:56 +01:00
|
|
|
|
|
2020-12-14 21:20:53 +00:00
|
|
|
|
Destroy(body.GetComponentInChildren<ProbeAnimatorController>());
|
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
|
|
|
|
|
2021-03-13 10:17:52 +00:00
|
|
|
|
QSBCore.UnityEvents.RunWhen(
|
2020-12-19 21:15:44 +00:00
|
|
|
|
() => Player.ProbeLauncher != null,
|
|
|
|
|
() => SetSocket(Player.ProbeLauncher.ToolGameObject.transform));
|
2020-12-14 21:20:53 +00:00
|
|
|
|
Player.ProbeBody = body.gameObject;
|
2020-12-14 21:41:56 +01:00
|
|
|
|
|
2020-12-14 21:20:53 +00:00
|
|
|
|
return body;
|
|
|
|
|
}
|
2020-12-14 21:41:56 +01:00
|
|
|
|
|
2021-03-25 20:56:26 +00:00
|
|
|
|
private void SetSocket(Transform socket)
|
|
|
|
|
{
|
|
|
|
|
DebugLog.DebugWrite($"Set DisabledSocket of id:{PlayerId}.");
|
|
|
|
|
_disabledSocket = socket;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-14 21:41:56 +01:00
|
|
|
|
|
2020-12-14 21:20:53 +00:00
|
|
|
|
protected override void UpdateTransform()
|
|
|
|
|
{
|
|
|
|
|
base.UpdateTransform();
|
|
|
|
|
if (Player == null)
|
|
|
|
|
{
|
|
|
|
|
DebugLog.ToConsole($"Player is null for {AttachedNetId}!", MessageType.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (_disabledSocket == null)
|
|
|
|
|
{
|
2021-03-25 20:56:26 +00:00
|
|
|
|
DebugLog.ToConsole($"DisabledSocket is null for {PlayerId}! (ProbeLauncher null? : {Player.ProbeLauncher == null})", MessageType.Error);
|
2020-12-14 21:20:53 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2020-12-23 22:43:05 +00:00
|
|
|
|
if (Player.GetState(State.ProbeActive) || ReferenceSector?.AttachedObject == null)
|
2020-12-14 21:20:53 +00:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (HasAuthority)
|
|
|
|
|
{
|
|
|
|
|
transform.position = ReferenceSector.Transform.InverseTransformPoint(_disabledSocket.position);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (SyncedTransform.position == Vector3.zero)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
SyncedTransform.localPosition = ReferenceSector.Transform.InverseTransformPoint(_disabledSocket.position);
|
|
|
|
|
}
|
2020-12-14 21:41:56 +01:00
|
|
|
|
|
2020-12-14 21:20:53 +00:00
|
|
|
|
public override bool IsReady => Locator.GetProbe() != null
|
|
|
|
|
&& Player != null
|
|
|
|
|
&& QSBPlayerManager.PlayerExists(Player.PlayerId)
|
|
|
|
|
&& Player.IsReady
|
|
|
|
|
&& NetId.Value != uint.MaxValue
|
|
|
|
|
&& NetId.Value != 0U;
|
|
|
|
|
}
|
2020-12-03 08:28:05 +00:00
|
|
|
|
}
|