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

33 lines
910 B
C#

using QSB.Events;
using QSB.Messaging;
using QSB.Player;
namespace QSB.ProbeSync.Events
{
internal class ProbeStartRetrieveEvent : QSBEvent<FloatMessage>
{
public override EventType Type => EventType.ProbeStartRetrieve;
public override void SetupListener()
=> GlobalMessenger<float>.AddListener(EventNames.QSBProbeStartRetrieve, Handler);
public override void CloseListener()
=> GlobalMessenger<float>.RemoveListener(EventNames.QSBProbeStartRetrieve, Handler);
private void Handler(float duration) => SendEvent(CreateMessage(duration));
private FloatMessage CreateMessage(float duration) => new FloatMessage
{
AboutId = LocalPlayerId,
Value = duration
};
public override void OnReceiveRemote(bool server, FloatMessage message)
{
var player = QSBPlayerManager.GetPlayer(message.AboutId);
var probe = player.Probe;
probe.OnStartRetrieve(message.Value);
}
}
}