using QSB.Events; using QSB.Messaging; using QSB.Player; using QSB.Utility; using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace QSB.ProbeSync.Events { class PlayerProbeEvent : QSBEvent> { public override EventType Type => EventType.ProbeEvent; public override void SetupListener() { GlobalMessenger.AddListener(EventNames.QSBProbeEvent, Handler); } public override void CloseListener() { GlobalMessenger.RemoveListener(EventNames.QSBProbeEvent, Handler); } private void Handler(ProbeEvent probeEvent) => SendEvent(CreateMessage(probeEvent)); private EnumMessage CreateMessage(ProbeEvent probeEvent) => new EnumMessage { AboutId = LocalPlayerId, EnumValue = probeEvent }; public override void OnReceiveRemote(bool server, EnumMessage message) { DebugLog.DebugWrite($"recieve probe event type:{message.EnumValue} from:{message.AboutId}"); var player = QSBPlayerManager.GetPlayer(message.AboutId); var probe = player.Probe; switch (message.EnumValue) { case ProbeEvent.Anchor: case ProbeEvent.Unanchor: case ProbeEvent.Launch: player.PlayerStates.ProbeActive = true; probe.SetState(true); break; case ProbeEvent.Destroy: case ProbeEvent.Retrieve: player.PlayerStates.ProbeActive = false; probe.SetState(false); break; } probe.HandleEvent(message.EnumValue); } } }