29 lines
959 B
C#
Raw Normal View History

using QSB.ElevatorSync.WorldObjects;
using QSB.Events;
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-12-02 21:23:01 +00:00
public class ElevatorEvent : QSBEvent<BoolWorldObjectMessage>
{
public override EventType Type => EventType.Elevator;
2020-08-12 21:58:29 +02:00
2020-12-02 21:23:01 +00:00
public override void SetupListener() => GlobalMessenger<int, bool>.AddListener(EventNames.QSBStartLift, Handler);
public override void CloseListener() => GlobalMessenger<int, bool>.RemoveListener(EventNames.QSBStartLift, Handler);
2020-08-15 20:32:58 +01:00
2020-12-02 21:23:01 +00:00
private void Handler(int id, bool isGoingUp) => SendEvent(CreateMessage(id, isGoingUp));
2020-08-15 21:52:43 +02:00
2020-12-02 21:23:01 +00:00
private BoolWorldObjectMessage CreateMessage(int id, bool isGoingUp) => new BoolWorldObjectMessage
{
State = isGoingUp,
ObjectId = id
};
2020-08-12 21:58:29 +02: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
{
2021-02-24 10:45:25 +00:00
var elevator = QSBWorldSync.GetWorldFromId<QSBElevator>(message.ObjectId);
2020-12-02 21:23:01 +00:00
elevator?.RemoteCall(message.State);
}
}
2020-12-03 08:28:05 +00:00
}