2022-05-27 19:07:05 -07:00
|
|
|
|
using Cysharp.Threading.Tasks;
|
2022-08-15 23:04:14 -07:00
|
|
|
|
using QSB.AuthoritySync;
|
2022-08-16 16:27:56 -07:00
|
|
|
|
using QSB.EchoesOfTheEye.LightSensorSync.Messages;
|
|
|
|
|
using QSB.Messaging;
|
2022-07-24 15:28:41 -07:00
|
|
|
|
using QSB.Utility;
|
2022-05-27 19:07:05 -07:00
|
|
|
|
using QSB.WorldSync;
|
2022-02-26 00:26:31 -08:00
|
|
|
|
using System;
|
2022-05-27 19:07:05 -07:00
|
|
|
|
using System.Threading;
|
2022-02-26 00:26:31 -08:00
|
|
|
|
|
2022-07-23 21:25:28 -07:00
|
|
|
|
/*
|
|
|
|
|
* For those who come here,
|
|
|
|
|
* leave while you still can.
|
|
|
|
|
*/
|
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
namespace QSB.EchoesOfTheEye.LightSensorSync.WorldObjects;
|
|
|
|
|
|
2022-08-15 16:39:57 -07:00
|
|
|
|
/// <summary>
|
2022-08-15 22:48:58 -07:00
|
|
|
|
/// BUG: this breaks in zone2.
|
2022-08-15 16:41:24 -07:00
|
|
|
|
/// the sector it's enabled in is bigger than the sector the zone2 walls are enabled in :(
|
|
|
|
|
/// maybe this can be fixed by making the collision group use the same sector.
|
2022-08-15 16:39:57 -07:00
|
|
|
|
/// </summary>
|
2022-08-15 23:17:50 -07:00
|
|
|
|
internal class QSBLightSensor : AuthWorldObject<SingleLightSensor>
|
2022-02-26 00:26:31 -08:00
|
|
|
|
{
|
2022-05-27 22:28:24 -07:00
|
|
|
|
internal bool _locallyIlluminated;
|
2022-08-16 16:13:46 -07:00
|
|
|
|
|
2022-03-06 23:13:48 -08:00
|
|
|
|
public Action OnDetectLocalLight;
|
|
|
|
|
public Action OnDetectLocalDarkness;
|
2022-03-02 19:46:33 -08:00
|
|
|
|
|
2022-08-15 23:04:14 -07:00
|
|
|
|
|
2022-08-15 23:17:50 -07:00
|
|
|
|
public override bool CanOwn => AttachedObject.enabled;
|
2022-05-27 15:03:30 -07:00
|
|
|
|
|
2022-05-27 19:15:04 -07:00
|
|
|
|
public override void SendInitialState(uint to)
|
|
|
|
|
{
|
2022-08-15 23:17:50 -07:00
|
|
|
|
base.SendInitialState(to);
|
2022-08-16 16:27:56 -07:00
|
|
|
|
|
|
|
|
|
this.SendMessage(new SetIlluminatedMessage(AttachedObject._illuminated) { To = to });
|
2022-08-16 17:05:13 -07:00
|
|
|
|
if (AttachedObject._illuminatingDreamLanternList != null)
|
|
|
|
|
{
|
|
|
|
|
this.SendMessage(new IlluminatingLanternsMessage(AttachedObject._illuminatingDreamLanternList) { To = to });
|
|
|
|
|
}
|
2022-05-27 19:15:04 -07:00
|
|
|
|
}
|
2022-05-27 19:07:05 -07:00
|
|
|
|
|
2022-07-24 14:32:11 +01:00
|
|
|
|
public override async UniTask Init(CancellationToken ct)
|
|
|
|
|
{
|
2022-08-15 23:34:12 -07:00
|
|
|
|
await base.Init(ct);
|
2022-07-24 14:32:11 +01:00
|
|
|
|
|
2022-08-15 22:48:58 -07:00
|
|
|
|
// do this stuff here instead of Start, since world objects won't be ready by that point
|
2022-07-24 15:28:41 -07:00
|
|
|
|
Delay.RunWhen(() => QSBWorldSync.AllObjectsReady, () =>
|
2022-07-24 14:32:11 +01:00
|
|
|
|
{
|
2022-07-24 15:28:41 -07:00
|
|
|
|
if (AttachedObject._sector != null)
|
2022-07-24 10:32:05 -07:00
|
|
|
|
{
|
2022-07-24 15:28:41 -07:00
|
|
|
|
if (AttachedObject._startIlluminated)
|
|
|
|
|
{
|
|
|
|
|
_locallyIlluminated = true;
|
|
|
|
|
OnDetectLocalLight?.Invoke();
|
|
|
|
|
}
|
2022-07-24 10:32:05 -07:00
|
|
|
|
}
|
2022-07-24 15:28:41 -07:00
|
|
|
|
});
|
2022-07-24 14:32:11 +01:00
|
|
|
|
}
|
2022-03-06 23:13:48 -08:00
|
|
|
|
}
|