29 lines
924 B
C#
Raw Normal View History

2020-12-14 16:24:52 +00:00
using QSB.Events;
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-11 13:14:58 +00:00
public override void SetupListener() => GlobalMessenger<int, bool>.AddListener(EventNames.QSBGeyserState, Handler);
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-11 22:42:21 +00:00
public override void OnReceiveRemote(bool server, BoolWorldObjectMessage message)
2020-12-02 21:23:01 +00:00
{
var geyser = QSBWorldSync.GetWorldObject<QSBGeyser>(message.ObjectId);
2020-12-02 21:23:01 +00:00
geyser?.SetState(message.State);
}
}
2020-12-03 08:28:05 +00:00
}