37 lines
929 B
C#
Raw Normal View History

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