56 lines
1.1 KiB
C#
Raw Normal View History

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