32 lines
999 B
C#
Raw Normal View History

2020-08-12 21:58:29 +02:00
using QSB.Events;
using QSB.Messaging;
namespace QSB.ElevatorSync
{
public class ElevatorEvent : QSBEvent<ElevatorMessage>
{
public override MessageType Type => MessageType.Elevator;
public override void SetupListener()
{
GlobalMessenger<ElevatorDirection, string>.AddListener(EventNames.QSBStartLift, (direction, elevatorName) => SendEvent(CreateMessage(direction, elevatorName)));
2020-08-12 21:58:29 +02:00
}
private ElevatorMessage CreateMessage(ElevatorDirection direction, string elevatorName) => new ElevatorMessage
2020-08-12 21:58:29 +02:00
{
SenderId = PlayerRegistry.LocalPlayer.NetId,
Direction = direction,
ElevatorName = elevatorName
2020-08-12 21:58:29 +02:00
};
public override void OnReceiveRemote(ElevatorMessage message)
{
2020-08-13 17:44:27 +01:00
if (!IsInUniverse)
2020-08-12 21:58:29 +02:00
{
return;
}
PlayerRegistry.GetElevatorController(message.ElevatorName).RemoteCall(message.Direction);
2020-08-12 21:58:29 +02:00
}
}
}