quantum-space-buddies/QSB/ProbeSync/Events/PlayerProbeEvent.cs
Mister_Nebula 85a3f4770e cleanup
2021-07-12 22:02:50 +01:00

34 lines
956 B
C#

using QSB.Events;
using QSB.Messaging;
using QSB.Player;
namespace QSB.ProbeSync.Events
{
internal class PlayerProbeEvent : QSBEvent<EnumMessage<ProbeEvent>>
{
public override EventType Type => EventType.ProbeEvent;
public override void SetupListener()
=> GlobalMessenger<ProbeEvent>.AddListener(EventNames.QSBProbeEvent, Handler);
public override void CloseListener()
=> GlobalMessenger<ProbeEvent>.RemoveListener(EventNames.QSBProbeEvent, Handler);
private void Handler(ProbeEvent probeEvent) => SendEvent(CreateMessage(probeEvent));
private EnumMessage<ProbeEvent> CreateMessage(ProbeEvent probeEvent) => new EnumMessage<ProbeEvent>
{
AboutId = LocalPlayerId,
EnumValue = probeEvent
};
public override void OnReceiveRemote(bool server, EnumMessage<ProbeEvent> message)
{
var player = QSBPlayerManager.GetPlayer(message.AboutId);
var probe = player.Probe;
probe.HandleEvent(message.EnumValue);
}
}
}