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

30 lines
1016 B
C#

using QSB.EventsCore;
using QSB.WorldSync;
using QSB.WorldSync.Events;
namespace QSB.ElevatorSync.Events
{
public class ElevatorEvent : QSBEvent<BoolWorldObjectMessage>
{
public override EventType Type => EventType.Elevator;
public override void SetupListener() => GlobalMessenger<int, bool>.AddListener(EventNames.QSBStartLift, Handler);
public override void CloseListener() => GlobalMessenger<int, bool>.RemoveListener(EventNames.QSBStartLift, Handler);
private void Handler(int id, bool direction) => SendEvent(CreateMessage(id, direction));
private BoolWorldObjectMessage CreateMessage(int id, bool direction) => new BoolWorldObjectMessage
{
State = direction,
ObjectId = id
};
public override void OnReceiveRemote(BoolWorldObjectMessage message)
{
var elevator = WorldRegistry.GetObject<QSBElevator>(message.ObjectId);
elevator?.RemoteCall(message.State);
}
}
}