mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-18 13:23:05 +00:00
44 lines
1.5 KiB
C#
44 lines
1.5 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, HandleLaunch);
|
|
GlobalMessenger<SurveyorProbe>.AddListener(EventNames.RetrieveProbe, HandleRetrieve);
|
|
}
|
|
|
|
public override void CloseListener()
|
|
{
|
|
GlobalMessenger<SurveyorProbe>.RemoveListener(EventNames.LaunchProbe, HandleLaunch);
|
|
GlobalMessenger<SurveyorProbe>.RemoveListener(EventNames.RetrieveProbe, HandleRetrieve);
|
|
}
|
|
|
|
private void HandleLaunch(SurveyorProbe probe) => SendEvent(CreateMessage(true));
|
|
private void HandleRetrieve(SurveyorProbe 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);
|
|
}
|
|
}
|
|
}
|