quantum-space-buddies/QSB/Tools/PlayerProbeEvent.cs
Mister_Nebula 4fc6d55537 test
2020-08-15 20:32:58 +01:00

41 lines
1.4 KiB
C#

using QSB.Events;
using QSB.Messaging;
namespace QSB.Tools
{
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)));
}
public override void CloseListener()
{
GlobalMessenger<SurveyorProbe>.RemoveListener(EventNames.LaunchProbe, probe => SendEvent(CreateMessage(true)));
GlobalMessenger<SurveyorProbe>.RemoveListener(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);
}
}
}