using QSB.Events; using QSB.Messaging; using QSB.Utility; namespace QSB.Tools { public class PlayerProbeLauncherEvent : QSBEvent { public override MessageType Type => MessageType.ProbeLauncherActiveChange; public override void SetupListener() { GlobalMessenger.AddListener(EventNames.ProbeLauncherEquipped, var => SendEvent(CreateMessage(true))); GlobalMessenger.AddListener(EventNames.ProbeLauncherUnequipped, var => SendEvent(CreateMessage(false))); } public override void CloseListener() { GlobalMessenger.RemoveListener(EventNames.ProbeLauncherEquipped, var => SendEvent(CreateMessage(true))); GlobalMessenger.RemoveListener(EventNames.ProbeLauncherUnequipped, var => 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.ProbeLauncher, message.ToggleValue); if (!IsInUniverse) { return; } player.ProbeLauncher?.ChangeEquipState(message.ToggleValue); } public override void OnReceiveLocal(ToggleMessage message) { PlayerRegistry.LocalPlayer.UpdateState(State.ProbeLauncher, message.ToggleValue); } } }