2022-05-27 19:07:05 -07:00
|
|
|
|
using Cysharp.Threading.Tasks;
|
|
|
|
|
using QSB.Player;
|
|
|
|
|
using QSB.WorldSync;
|
2022-02-26 00:26:31 -08:00
|
|
|
|
using System;
|
2022-05-27 19:07:05 -07:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading;
|
2022-02-26 00:26:31 -08:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
namespace QSB.EchoesOfTheEye.LightSensorSync.WorldObjects;
|
|
|
|
|
|
|
|
|
|
internal class QSBLightSensor : WorldObject<SingleLightSensor>
|
2022-02-26 00:26:31 -08:00
|
|
|
|
{
|
2022-05-26 21:23:05 -07:00
|
|
|
|
public bool LocallyIlluminated;
|
2022-02-26 00:26:31 -08:00
|
|
|
|
|
2022-03-06 23:13:48 -08:00
|
|
|
|
public Action OnDetectLocalLight;
|
|
|
|
|
public Action OnDetectLocalDarkness;
|
2022-03-02 19:46:33 -08:00
|
|
|
|
|
2022-05-27 19:07:05 -07:00
|
|
|
|
internal bool _clientIlluminated;
|
2022-05-27 19:11:04 -07:00
|
|
|
|
private readonly List<uint> _illuminatedBy = new();
|
2022-05-27 15:03:30 -07:00
|
|
|
|
|
2022-05-27 15:03:30 -07:00
|
|
|
|
public override void SendInitialState(uint to) { }
|
2022-05-27 19:07:05 -07:00
|
|
|
|
|
|
|
|
|
public override async UniTask Init(CancellationToken ct) => QSBPlayerManager.OnRemovePlayer += OnPlayerLeave;
|
|
|
|
|
public override void OnRemoval() => QSBPlayerManager.OnRemovePlayer -= OnPlayerLeave;
|
|
|
|
|
|
|
|
|
|
private void OnPlayerLeave(PlayerInfo player) =>
|
2022-05-27 19:11:04 -07:00
|
|
|
|
SetIlluminated(player.PlayerId, false);
|
|
|
|
|
|
|
|
|
|
public void SetIlluminated(uint playerId, bool illuminated)
|
|
|
|
|
{
|
|
|
|
|
// var illuminated = __instance._illuminated;
|
|
|
|
|
// if (!illuminated && __instance._illuminated)
|
|
|
|
|
// {
|
|
|
|
|
// __instance.OnDetectLight.Invoke();
|
|
|
|
|
// }
|
|
|
|
|
// else if (illuminated && !__instance._illuminated)
|
|
|
|
|
// {
|
|
|
|
|
// __instance.OnDetectDarkness.Invoke();
|
|
|
|
|
// }
|
|
|
|
|
}
|
2022-03-06 23:13:48 -08:00
|
|
|
|
}
|