using QSB.Events; using QSB.Messaging; using QSB.Utility; namespace QSB.Tools { public class PlayerSignalscopeEvent : QSBEvent { public override MessageType Type => MessageType.SignalscopeActiveChange; public override void SetupListener() { GlobalMessenger.AddListener(EventNames.EquipSignalscope, var => SendEvent(CreateMessage(true))); GlobalMessenger.AddListener(EventNames.UnequipSignalscope, () => SendEvent(CreateMessage(false))); } private ToggleMessage CreateMessage(bool value) => new ToggleMessage { SenderId = LocalPlayerId, ToggleValue = value }; public override void OnReceiveRemote(ToggleMessage message) { var player = PlayerRegistry.GetPlayer(message.SenderId); player.UpdateState(State.Signalscope, message.ToggleValue); if (!IsInUniverse) { return; } player.Signalscope?.ChangeEquipState(message.ToggleValue); } public override void OnReceiveLocal(ToggleMessage message) { PlayerRegistry.LocalPlayer.UpdateState(State.Signalscope, message.ToggleValue); } } }