quantum-space-buddies/QSB/GeyserSync/Events/GeyserEvent.cs
Mister_Nebula 66d804ad5c cleanup
2020-11-03 22:18:22 +00:00

37 lines
1.1 KiB
C#

using QSB.EventsCore;
using QSB.WorldSync;
using QSB.WorldSync.Events;
namespace QSB.GeyserSync.Events
{
public class GeyserEvent : QSBEvent<BoolWorldObjectMessage>
{
public override EventType Type => EventType.Geyser;
public override void SetupListener()
{
GlobalMessenger<int, bool>.AddListener(EventNames.QSBGeyserState, Handler);
}
public override void CloseListener()
{
GlobalMessenger<int, bool>.RemoveListener(EventNames.QSBGeyserState, Handler);
}
private void Handler(int id, bool state) => SendEvent(CreateMessage(id, state));
private BoolWorldObjectMessage CreateMessage(int id, bool state) => new BoolWorldObjectMessage
{
AboutId = LocalPlayerId,
ObjectId = id,
State = state
};
public override void OnReceiveRemote(BoolWorldObjectMessage message)
{
var geyser = WorldRegistry.GetObject<QSBGeyser>(message.ObjectId);
geyser?.SetState(message.State);
}
}
}