quantum-space-buddies/QSB/GeyserSync/Events/GeyserEvent.cs

35 lines
1017 B
C#
Raw Normal View History

2020-12-14 16:24:52 +00:00
using QSB.Events;
using QSB.GeyserSync.WorldObjects;
2020-08-13 13:32:58 +00:00
using QSB.WorldSync;
2020-11-03 22:18:22 +00:00
using QSB.WorldSync.Events;
2020-08-13 13:32:58 +00:00
2020-11-03 17:56:48 +00:00
namespace QSB.GeyserSync.Events
2020-08-13 13:32:58 +00:00
{
2020-12-02 21:23:01 +00:00
public class GeyserEvent : QSBEvent<BoolWorldObjectMessage>
{
public override EventType Type => EventType.Geyser;
2020-08-13 13:32:58 +00: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 19:32:58 +00:00
2020-12-02 21:23:01 +00:00
private void Handler(int id, bool state) => SendEvent(CreateMessage(id, state));
2020-08-15 19:52:43 +00: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 13:32:58 +00:00
2021-08-08 18:53:55 +00:00
public override void OnReceiveRemote(bool isHost, BoolWorldObjectMessage message)
2020-12-02 21:23:01 +00:00
{
2021-05-08 15:57:01 +00:00
if (!QSBCore.WorldObjectsReady)
{
return;
}
2021-06-18 21:38:32 +00:00
2021-02-24 10:45:25 +00:00
var geyser = QSBWorldSync.GetWorldFromId<QSBGeyser>(message.ObjectId);
2020-12-02 21:23:01 +00:00
geyser?.SetState(message.State);
}
}
2020-12-03 08:28:05 +00:00
}