using QSB.Events; using QSB.Messaging; using QSB.WorldSync; namespace QSB.ElevatorSync { public class ElevatorEvent : QSBEvent { public override MessageType Type => MessageType.Elevator; public override void SetupListener() { GlobalMessenger.AddListener(EventNames.QSBStartLift, Handler); } public override void CloseListener() { GlobalMessenger.RemoveListener(EventNames.QSBStartLift, Handler); } private void Handler(int id, ElevatorDirection direction) => SendEvent(CreateMessage(id, direction)); private ElevatorMessage CreateMessage(int id, ElevatorDirection direction) => new ElevatorMessage { SenderId = PlayerRegistry.LocalPlayer.NetId, Direction = direction, ObjectId = id }; public override void OnReceiveRemote(ElevatorMessage message) { if (!QSBSceneManager.IsInUniverse) { return; } var elevator = WorldRegistry.GetObject(message.ObjectId); elevator?.RemoteCall(message.Direction); } } }