2020-08-13 13:32:58 +00:00
|
|
|
|
using QSB.Events;
|
|
|
|
|
using QSB.Messaging;
|
|
|
|
|
using QSB.WorldSync;
|
|
|
|
|
|
2020-11-03 17:56:48 +00:00
|
|
|
|
namespace QSB.GeyserSync.Events
|
2020-08-13 13:32:58 +00:00
|
|
|
|
{
|
2020-08-26 20:12:57 +00:00
|
|
|
|
public class GeyserEvent : QSBEvent<BoolWorldObjectMessage>
|
2020-08-13 13:32:58 +00:00
|
|
|
|
{
|
2020-08-22 17:08:25 +00:00
|
|
|
|
public override EventType Type => EventType.Geyser;
|
2020-08-13 13:32:58 +00:00
|
|
|
|
|
|
|
|
|
public override void SetupListener()
|
|
|
|
|
{
|
2020-08-15 19:52:43 +00:00
|
|
|
|
GlobalMessenger<int, bool>.AddListener(EventNames.QSBGeyserState, Handler);
|
2020-08-13 13:32:58 +00:00
|
|
|
|
}
|
2020-08-15 19:55:25 +00:00
|
|
|
|
|
2020-08-15 19:32:58 +00:00
|
|
|
|
public override void CloseListener()
|
|
|
|
|
{
|
2020-08-15 19:52:43 +00:00
|
|
|
|
GlobalMessenger<int, bool>.RemoveListener(EventNames.QSBGeyserState, Handler);
|
2020-08-15 19:32:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-15 19:52:43 +00:00
|
|
|
|
private void Handler(int id, bool state) => SendEvent(CreateMessage(id, state));
|
|
|
|
|
|
2020-08-26 20:12:57 +00:00
|
|
|
|
private BoolWorldObjectMessage CreateMessage(int id, bool state) => new BoolWorldObjectMessage
|
2020-08-13 13:32:58 +00:00
|
|
|
|
{
|
2020-08-17 17:13:11 +00:00
|
|
|
|
AboutId = LocalPlayerId,
|
2020-08-13 18:47:23 +00:00
|
|
|
|
ObjectId = id,
|
2020-08-13 13:32:58 +00:00
|
|
|
|
State = state
|
|
|
|
|
};
|
|
|
|
|
|
2020-08-26 20:12:57 +00:00
|
|
|
|
public override void OnReceiveRemote(BoolWorldObjectMessage message)
|
2020-08-13 13:32:58 +00:00
|
|
|
|
{
|
2020-08-13 18:47:23 +00:00
|
|
|
|
var geyser = WorldRegistry.GetObject<QSBGeyser>(message.ObjectId);
|
2020-08-16 20:39:21 +00:00
|
|
|
|
geyser?.SetState(message.State);
|
2020-08-13 13:32:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|