quantum-space-buddies/QSB/Events/PlayerProbeEvent.cs
AmazingAlek 22b028ce26
Alek/overhaul thing (#153)
* probe.SetState
* sectormessage enum
2020-08-10 19:44:04 +02:00

34 lines
1.1 KiB
C#

using QSB.Messaging;
namespace QSB.Events
{
public class PlayerProbeEvent : QSBEvent<ToggleMessage>
{
public override MessageType Type => MessageType.ProbeActiveChange;
public override void SetupListener()
{
GlobalMessenger<SurveyorProbe>.AddListener(EventNames.LaunchProbe, probe => SendEvent(CreateMessage(true)));
GlobalMessenger<SurveyorProbe>.AddListener(EventNames.RetrieveProbe, probe => SendEvent(CreateMessage(false)));
}
private ToggleMessage CreateMessage(bool value) => new ToggleMessage
{
SenderId = LocalPlayerId,
ToggleValue = value
};
public override void OnReceiveRemote(ToggleMessage message)
{
var player = PlayerRegistry.GetPlayer(message.SenderId);
player.UpdateState(State.ProbeActive, message.ToggleValue);
player.Probe.SetState(message.ToggleValue);
}
public override void OnReceiveLocal(ToggleMessage message)
{
PlayerRegistry.LocalPlayer.UpdateState(State.ProbeActive, message.ToggleValue);
}
}
}