2022-02-25 00:21:21 -08:00
|
|
|
|
using Cysharp.Threading.Tasks;
|
2022-02-26 00:02:14 -08:00
|
|
|
|
using QSB.AuthoritySync;
|
|
|
|
|
using QSB.EchoesOfTheEye.LightSensorSync.WorldObjects;
|
2022-02-25 00:21:21 -08:00
|
|
|
|
using QSB.EchoesOfTheEye.RaftSync.TransformSync;
|
2022-04-01 14:08:08 -07:00
|
|
|
|
using QSB.ItemSync.WorldObjects;
|
2022-03-14 01:22:50 -07:00
|
|
|
|
using QSB.Utility.LinkedWorldObject;
|
2022-02-25 00:21:21 -08:00
|
|
|
|
using QSB.WorldSync;
|
2022-02-26 00:02:14 -08:00
|
|
|
|
using System.Linq;
|
2022-02-25 00:21:21 -08:00
|
|
|
|
using System.Threading;
|
2022-03-14 03:22:44 -07:00
|
|
|
|
using UnityEngine;
|
2022-02-25 00:21:21 -08:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
namespace QSB.EchoesOfTheEye.RaftSync.WorldObjects;
|
|
|
|
|
|
2022-04-01 14:08:08 -07:00
|
|
|
|
public class QSBRaft : LinkedWorldObject<RaftController, RaftTransformSync>, IQSBDropTarget
|
2022-02-25 00:21:21 -08:00
|
|
|
|
{
|
2022-04-01 14:08:08 -07:00
|
|
|
|
IItemDropTarget IQSBDropTarget.AttachedObject => AttachedObject;
|
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
public override bool ShouldDisplayDebug() => false;
|
2022-02-25 00:21:21 -08:00
|
|
|
|
|
2022-03-14 03:22:44 -07:00
|
|
|
|
protected override GameObject NetworkObjectPrefab => QSBNetworkManager.singleton.RaftPrefab;
|
2022-03-14 03:44:52 -07:00
|
|
|
|
protected override bool SpawnWithServerAuthority => false;
|
2022-02-25 00:21:21 -08:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
private QSBLightSensor[] _lightSensors;
|
2022-02-26 00:26:31 -08:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
public override async UniTask Init(CancellationToken ct)
|
|
|
|
|
{
|
2022-03-14 03:22:44 -07:00
|
|
|
|
await base.Init(ct);
|
2022-02-26 00:02:14 -08:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
await UniTask.WaitUntil(() => QSBWorldSync.AllObjectsAdded, cancellationToken: ct);
|
|
|
|
|
_lightSensors = AttachedObject._lightSensors.Select(x => x.GetWorldObject<QSBLightSensor>()).ToArray();
|
2022-02-26 00:26:31 -08:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
foreach (var lightSensor in _lightSensors)
|
|
|
|
|
{
|
|
|
|
|
lightSensor.OnDetectLocalLight += OnDetectLocalLight;
|
2022-02-26 00:02:14 -08:00
|
|
|
|
}
|
2022-03-02 19:46:33 -08:00
|
|
|
|
}
|
2022-02-25 00:21:21 -08:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
public override void OnRemoval()
|
|
|
|
|
{
|
2022-03-14 08:32:35 -07:00
|
|
|
|
base.OnRemoval();
|
2022-02-26 00:02:14 -08:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
foreach (var lightSensor in _lightSensors)
|
2022-02-26 00:02:14 -08:00
|
|
|
|
{
|
2022-03-02 19:46:33 -08:00
|
|
|
|
lightSensor.OnDetectLocalLight -= OnDetectLocalLight;
|
2022-02-26 00:02:14 -08:00
|
|
|
|
}
|
2022-03-02 19:46:33 -08:00
|
|
|
|
}
|
2022-02-26 00:02:14 -08:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
private void OnDetectLocalLight()
|
|
|
|
|
{
|
|
|
|
|
if (AttachedObject.IsPlayerRiding())
|
2022-02-26 00:02:14 -08:00
|
|
|
|
{
|
2022-03-14 01:22:50 -07:00
|
|
|
|
NetworkBehaviour.netIdentity.UpdateAuthQueue(AuthQueueAction.Force);
|
2022-02-26 00:02:14 -08:00
|
|
|
|
}
|
2022-02-25 00:21:21 -08:00
|
|
|
|
}
|
2022-03-02 19:46:33 -08:00
|
|
|
|
|
2022-03-11 08:43:38 -08:00
|
|
|
|
public override void SendInitialState(uint to)
|
|
|
|
|
{
|
2022-03-11 09:51:43 -08:00
|
|
|
|
// not really needed. things work fine without it
|
2022-03-02 19:46:33 -08:00
|
|
|
|
}
|
2022-03-11 05:57:48 -08:00
|
|
|
|
}
|