2020-08-12 19:58:29 +00:00
|
|
|
|
using QSB.Events;
|
|
|
|
|
using QSB.Messaging;
|
2020-08-13 17:25:12 +00:00
|
|
|
|
using QSB.WorldSync;
|
2020-08-12 19:58:29 +00:00
|
|
|
|
|
|
|
|
|
namespace QSB.ElevatorSync
|
|
|
|
|
{
|
|
|
|
|
public class ElevatorEvent : QSBEvent<ElevatorMessage>
|
|
|
|
|
{
|
|
|
|
|
public override MessageType Type => MessageType.Elevator;
|
|
|
|
|
|
|
|
|
|
public override void SetupListener()
|
|
|
|
|
{
|
2020-08-12 20:22:52 +00:00
|
|
|
|
GlobalMessenger<ElevatorDirection, string>.AddListener(EventNames.QSBStartLift, (direction, elevatorName) => SendEvent(CreateMessage(direction, elevatorName)));
|
2020-08-12 19:58:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-12 20:22:52 +00:00
|
|
|
|
private ElevatorMessage CreateMessage(ElevatorDirection direction, string elevatorName) => new ElevatorMessage
|
2020-08-12 19:58:29 +00:00
|
|
|
|
{
|
|
|
|
|
SenderId = PlayerRegistry.LocalPlayer.NetId,
|
2020-08-12 20:22:52 +00:00
|
|
|
|
Direction = direction,
|
2020-08-13 17:34:25 +00:00
|
|
|
|
UniqueName = elevatorName
|
2020-08-12 19:58:29 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public override void OnReceiveRemote(ElevatorMessage message)
|
|
|
|
|
{
|
2020-08-13 16:44:27 +00:00
|
|
|
|
if (!IsInUniverse)
|
2020-08-12 19:58:29 +00:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-08-13 17:34:25 +00:00
|
|
|
|
WorldRegistry.GetObject<QSBElevator>(message.UniqueName).RemoteCall(message.Direction);
|
2020-08-12 19:58:29 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|