2020-11-03 21:42:14 +00:00
|
|
|
|
using QSB.EventsCore;
|
2020-08-13 19:25:12 +02:00
|
|
|
|
using QSB.WorldSync;
|
2020-11-03 22:18:22 +00:00
|
|
|
|
using QSB.WorldSync.Events;
|
2020-08-12 21:58:29 +02:00
|
|
|
|
|
2020-11-03 17:56:48 +00:00
|
|
|
|
namespace QSB.ElevatorSync.Events
|
2020-08-12 21:58:29 +02:00
|
|
|
|
{
|
2020-11-03 21:18:40 +00:00
|
|
|
|
public class ElevatorEvent : QSBEvent<BoolWorldObjectMessage>
|
2020-08-12 21:58:29 +02:00
|
|
|
|
{
|
2020-08-22 18:08:25 +01:00
|
|
|
|
public override EventType Type => EventType.Elevator;
|
2020-08-12 21:58:29 +02:00
|
|
|
|
|
2020-11-03 21:18:40 +00:00
|
|
|
|
public override void SetupListener() => GlobalMessenger<int, bool>.AddListener(EventNames.QSBStartLift, Handler);
|
2020-08-15 21:55:25 +02:00
|
|
|
|
|
2020-11-03 21:18:40 +00:00
|
|
|
|
public override void CloseListener() => GlobalMessenger<int, bool>.RemoveListener(EventNames.QSBStartLift, Handler);
|
2020-08-15 20:32:58 +01:00
|
|
|
|
|
2020-11-03 21:18:40 +00:00
|
|
|
|
private void Handler(int id, bool direction) => SendEvent(CreateMessage(id, direction));
|
2020-08-15 21:52:43 +02:00
|
|
|
|
|
2020-11-03 21:18:40 +00:00
|
|
|
|
private BoolWorldObjectMessage CreateMessage(int id, bool direction) => new BoolWorldObjectMessage
|
2020-08-12 21:58:29 +02:00
|
|
|
|
{
|
2020-11-03 21:18:40 +00:00
|
|
|
|
State = direction,
|
2020-08-13 20:47:23 +02:00
|
|
|
|
ObjectId = id
|
2020-08-12 21:58:29 +02:00
|
|
|
|
};
|
|
|
|
|
|
2020-11-03 21:18:40 +00:00
|
|
|
|
public override void OnReceiveRemote(BoolWorldObjectMessage message)
|
2020-08-12 21:58:29 +02:00
|
|
|
|
{
|
2020-08-16 22:39:21 +02:00
|
|
|
|
var elevator = WorldRegistry.GetObject<QSBElevator>(message.ObjectId);
|
2020-11-03 21:18:40 +00:00
|
|
|
|
elevator?.RemoteCall(message.State);
|
2020-08-12 21:58:29 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|