quantum-space-buddies/QSB/Events/PlayerProbeLauncherEvent.cs
2020-08-10 14:40:06 +01:00

37 lines
1.2 KiB
C#

using QSB.Messaging;
using QSB.Utility;
namespace QSB.Events
{
class PlayerProbeLauncherEvent : QSBEvent<ToggleMessage>
{
public override MessageType Type => MessageType.ProbeLauncherActiveChange;
public override void SetupListener()
{
GlobalMessenger<ProbeLauncher>.AddListener("ProbeLauncherEquipped", var => SendEvent(
new ToggleMessage {
SenderId = LocalPlayerId,
ToggleValue = true
}));
GlobalMessenger<ProbeLauncher>.AddListener("ProbeLauncherUnequipped", var => SendEvent(
new ToggleMessage {
SenderId = LocalPlayerId,
ToggleValue = false
}));
}
public override void OnReceiveRemote(ToggleMessage message)
{
var player = PlayerRegistry.GetPlayer(message.SenderId);
player.UpdateState(State.ProbeLauncher, message.ToggleValue);
player.ProbeLauncher?.ChangeEquipState(message.ToggleValue);
}
public override void OnReceiveLocal(ToggleMessage message)
{
PlayerRegistry.LocalPlayer.UpdateState(State.ProbeLauncher, message.ToggleValue);
}
}
}