using QSB.Events; using QSB.Messaging; namespace QSB.Tools { public class PlayerProbeLauncherEvent : QSBEvent { public override MessageType Type => MessageType.ProbeLauncherActiveChange; public override void SetupListener() { GlobalMessenger.AddListener(EventNames.ProbeLauncherEquipped, HandleEquip); GlobalMessenger.AddListener(EventNames.ProbeLauncherUnequipped, HandleUnequip); } public override void CloseListener() { GlobalMessenger.RemoveListener(EventNames.ProbeLauncherEquipped, HandleEquip); GlobalMessenger.RemoveListener(EventNames.ProbeLauncherUnequipped, HandleUnequip); } private void HandleEquip(ProbeLauncher var) => SendEvent(CreateMessage(true)); private void HandleUnequip(ProbeLauncher var) => SendEvent(CreateMessage(false)); private ToggleMessage CreateMessage(bool value) => new ToggleMessage { AboutId = LocalPlayerId, ToggleValue = value }; public override void OnReceiveRemote(ToggleMessage message) { var player = PlayerRegistry.GetPlayer(message.AboutId); player.UpdateState(State.ProbeLauncher, message.ToggleValue); player.ProbeLauncher?.ChangeEquipState(message.ToggleValue); } public override void OnReceiveLocal(ToggleMessage message) { PlayerRegistry.LocalPlayer.UpdateState(State.ProbeLauncher, message.ToggleValue); } } }