quantum-space-buddies/QSB/GeyserSync/QSBGeyser.cs

38 lines
791 B
C#
Raw Normal View History

2020-12-14 16:24:52 +00:00
using QSB.Events;
2020-08-13 17:25:12 +00:00
using QSB.WorldSync;
2020-12-04 22:15:41 +00:00
using QuantumUNET;
2020-08-13 17:25:12 +00:00
namespace QSB.GeyserSync
{
2020-12-02 21:29:53 +00:00
public class QSBGeyser : WorldObject
{
private GeyserController _geyserController;
2020-08-13 17:25:12 +00:00
2020-12-02 21:29:53 +00:00
public void Init(GeyserController geyserController, int id)
{
ObjectId = id;
_geyserController = geyserController;
2020-08-13 17:25:12 +00:00
2020-12-02 21:29:53 +00:00
geyserController.OnGeyserActivateEvent += () => HandleEvent(true);
geyserController.OnGeyserDeactivateEvent += () => HandleEvent(false);
}
2020-08-13 17:25:12 +00:00
2020-12-02 21:29:53 +00:00
private void HandleEvent(bool state)
{
2020-12-23 12:58:45 +00:00
if (QNetworkServer.active)
2020-12-02 21:29:53 +00:00
{
GlobalMessenger<int, bool>.FireEvent(EventNames.QSBGeyserState, ObjectId, state);
}
}
2020-08-13 17:25:12 +00:00
2020-12-02 21:29:53 +00:00
public void SetState(bool state)
{
if (state)
{
_geyserController?.ActivateGeyser();
2020-12-11 23:13:13 +00:00
return;
2020-12-02 21:29:53 +00:00
}
2020-12-11 23:13:13 +00:00
_geyserController?.DeactivateGeyser();
2020-12-02 21:29:53 +00:00
}
}
2020-12-03 08:28:05 +00:00
}