2022-01-29 04:49:07 +00:00
|
|
|
|
using Cysharp.Threading.Tasks;
|
|
|
|
|
using QSB.GeyserSync.Messages;
|
2021-12-25 05:23:40 +00:00
|
|
|
|
using QSB.Messaging;
|
2020-08-13 17:25:12 +00:00
|
|
|
|
using QSB.WorldSync;
|
2022-01-29 04:49:07 +00:00
|
|
|
|
using System.Threading;
|
2020-08-13 17:25:12 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
namespace QSB.GeyserSync.WorldObjects;
|
|
|
|
|
|
|
|
|
|
public class QSBGeyser : WorldObject<GeyserController>
|
2020-08-13 17:25:12 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
public override async UniTask Init(CancellationToken ct)
|
2020-12-02 21:29:53 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
if (QSBCore.IsHost)
|
2020-12-02 21:29:53 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
AttachedObject.OnGeyserActivateEvent += OnActivate;
|
|
|
|
|
AttachedObject.OnGeyserDeactivateEvent += OnDeactivate;
|
2020-12-02 21:29:53 +00:00
|
|
|
|
}
|
2022-03-03 03:46:33 +00:00
|
|
|
|
}
|
2020-08-13 17:25:12 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
public override void OnRemoval()
|
|
|
|
|
{
|
|
|
|
|
if (QSBCore.IsHost)
|
2022-01-26 04:20:16 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
AttachedObject.OnGeyserActivateEvent -= OnActivate;
|
|
|
|
|
AttachedObject.OnGeyserDeactivateEvent -= OnDeactivate;
|
2022-01-26 04:20:16 +00:00
|
|
|
|
}
|
2022-03-03 03:46:33 +00:00
|
|
|
|
}
|
2022-01-22 05:54:46 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
public override void SendInitialState(uint to) =>
|
|
|
|
|
this.SendMessage(new GeyserMessage(AttachedObject._isActive));
|
2020-08-13 17:25:12 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
private void OnActivate() => this.SendMessage(new GeyserMessage(true));
|
|
|
|
|
private void OnDeactivate() => this.SendMessage(new GeyserMessage(false));
|
2022-01-26 04:20:16 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
public void SetState(bool state)
|
|
|
|
|
{
|
|
|
|
|
if (AttachedObject._isActive == state)
|
2020-12-02 21:29:53 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2021-06-18 21:38:32 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
if (state)
|
|
|
|
|
{
|
|
|
|
|
AttachedObject.ActivateGeyser();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
AttachedObject.DeactivateGeyser();
|
2020-12-02 21:29:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-02-25 06:04:54 +00:00
|
|
|
|
}
|