quantum-space-buddies/QSB/GeyserSync/WorldObjects/QSBGeyser.cs
Mister_Nebula 53974485c9
Spiral sync (#242)
* add stuff

* extract patches

* extract worldobjects (#241)

* add spiral sync

* cleanup

* cleanup

* fix

* rename

* add computers

* remove qnet flagshelper

* Update README.md

* cleanup
2020-12-31 12:10:55 +00:00

35 lines
770 B
C#

using QSB.Events;
using QSB.WorldSync;
using QuantumUNET;
namespace QSB.GeyserSync.WorldObjects
{
public class QSBGeyser : WorldObject<GeyserController>
{
public override void Init(GeyserController geyserController, int id)
{
ObjectId = id;
AttachedObject = geyserController;
AttachedObject.OnGeyserActivateEvent += () => HandleEvent(true);
AttachedObject.OnGeyserDeactivateEvent += () => HandleEvent(false);
}
private void HandleEvent(bool state)
{
if (QNetworkServer.active)
{
GlobalMessenger<int, bool>.FireEvent(EventNames.QSBGeyserState, ObjectId, state);
}
}
public void SetState(bool state)
{
if (state)
{
AttachedObject?.ActivateGeyser();
return;
}
AttachedObject?.DeactivateGeyser();
}
}
}