using QSB.Events; using QSB.Messaging; using QSB.Player; namespace QSB.ProbeSync.Events { public class PlayerProbeEvent : QSBEvent { public override EventType Type => EventType.ProbeActiveChange; public override void SetupListener() { GlobalMessenger.AddListener(EventNames.LaunchProbe, HandleLaunch); GlobalMessenger.AddListener(EventNames.RetrieveProbe, HandleRetrieve); } public override void CloseListener() { GlobalMessenger.RemoveListener(EventNames.LaunchProbe, HandleLaunch); GlobalMessenger.RemoveListener(EventNames.RetrieveProbe, HandleRetrieve); } private void HandleLaunch(SurveyorProbe probe) => SendEvent(CreateMessage(true)); private void HandleRetrieve(SurveyorProbe probe) => SendEvent(CreateMessage(false)); private ToggleMessage CreateMessage(bool value) => new ToggleMessage { AboutId = LocalPlayerId, ToggleValue = value }; public override void OnReceiveRemote(bool server, ToggleMessage message) { var player = QSBPlayerManager.GetPlayer(message.AboutId); player.PlayerStates.ProbeActive = message.ToggleValue; player.Probe?.SetState(message.ToggleValue); } public override void OnReceiveLocal(bool server, ToggleMessage message) => QSBPlayerManager.LocalPlayer.PlayerStates.ProbeActive = message.ToggleValue; } }