33 lines
966 B
C#
Raw Normal View History

2020-08-12 21:58:29 +02:00
using QSB.Events;
using QSB.Messaging;
2020-08-13 19:25:12 +02:00
using QSB.WorldSync;
2020-08-12 21:58:29 +02:00
namespace QSB.ElevatorSync
{
public class ElevatorEvent : QSBEvent<ElevatorMessage>
{
public override MessageType Type => MessageType.Elevator;
public override void SetupListener()
{
2020-08-13 20:43:47 +02:00
GlobalMessenger<int, ElevatorDirection>.AddListener(EventNames.QSBStartLift, (id, direction) => SendEvent(CreateMessage(id, direction)));
2020-08-12 21:58:29 +02:00
}
2020-08-13 20:43:47 +02:00
private ElevatorMessage CreateMessage(int id, ElevatorDirection direction) => new ElevatorMessage
2020-08-12 21:58:29 +02:00
{
SenderId = PlayerRegistry.LocalPlayer.NetId,
Direction = direction,
2020-08-13 20:47:23 +02:00
ObjectId = id
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;
}
2020-08-13 20:47:23 +02:00
WorldRegistry.GetObject<QSBElevator>(message.ObjectId).RemoteCall(message.Direction);
2020-08-12 21:58:29 +02:00
}
}
}