quantum-space-buddies/QSB/Tools/PlayerProbeEvent.cs

35 lines
1.1 KiB
C#
Raw Normal View History

2020-08-13 21:46:16 +02:00
using QSB.Events;
using QSB.Messaging;
2020-08-10 14:40:06 +01:00
2020-08-13 21:46:16 +02:00
namespace QSB.Tools
2020-08-10 14:40:06 +01:00
{
2020-08-10 18:17:54 +02:00
public class PlayerProbeEvent : QSBEvent<ToggleMessage>
2020-08-10 14:40:06 +01:00
{
public override MessageType Type => MessageType.ProbeActiveChange;
public override void SetupListener()
{
2020-08-10 19:24:28 +02:00
GlobalMessenger<SurveyorProbe>.AddListener(EventNames.LaunchProbe, probe => SendEvent(CreateMessage(true)));
GlobalMessenger<SurveyorProbe>.AddListener(EventNames.RetrieveProbe, probe => SendEvent(CreateMessage(false)));
2020-08-10 14:40:06 +01:00
}
2020-08-10 18:17:54 +02:00
private ToggleMessage CreateMessage(bool value) => new ToggleMessage
{
SenderId = LocalPlayerId,
ToggleValue = value
};
2020-08-10 14:40:06 +01:00
public override void OnReceiveRemote(ToggleMessage message)
{
var player = PlayerRegistry.GetPlayer(message.SenderId);
player.UpdateState(State.ProbeActive, message.ToggleValue);
player.Probe.SetState(message.ToggleValue);
2020-08-10 14:40:06 +01:00
}
public override void OnReceiveLocal(ToggleMessage message)
{
2020-08-10 16:49:22 +01:00
PlayerRegistry.LocalPlayer.UpdateState(State.ProbeActive, message.ToggleValue);
2020-08-10 14:40:06 +01:00
}
}
}