quantum-space-buddies/QSB/Events/PlayerProbeLauncherEvent.cs

37 lines
1.2 KiB
C#
Raw Normal View History

2020-08-09 09:17:00 +02:00
using QSB.Messaging;
2020-08-09 19:33:36 +01:00
using QSB.Utility;
2020-08-08 13:27:49 +01:00
namespace QSB.Events
{
2020-08-09 09:37:32 +02:00
class PlayerProbeLauncherEvent : QSBEvent<ToggleMessage>
2020-08-08 13:27:49 +01:00
{
2020-08-09 09:17:00 +02:00
public override MessageType Type => MessageType.ProbeLauncherActiveChange;
2020-08-08 13:27:49 +01:00
public override void SetupListener()
{
2020-08-09 13:48:55 +01:00
GlobalMessenger<ProbeLauncher>.AddListener("ProbeLauncherEquipped", var => SendEvent(
new ToggleMessage {
2020-08-10 14:40:06 +01:00
SenderId = LocalPlayerId,
2020-08-09 19:33:36 +01:00
ToggleValue = true
2020-08-09 13:48:55 +01:00
}));
GlobalMessenger<ProbeLauncher>.AddListener("ProbeLauncherUnequipped", var => SendEvent(
new ToggleMessage {
2020-08-10 14:40:06 +01:00
SenderId = LocalPlayerId,
2020-08-09 19:33:36 +01:00
ToggleValue = false
2020-08-09 13:48:55 +01:00
}));
2020-08-08 13:27:49 +01:00
}
2020-08-10 14:40:06 +01:00
public override void OnReceiveRemote(ToggleMessage message)
2020-08-08 13:27:49 +01:00
{
2020-08-09 12:19:51 +01:00
var player = PlayerRegistry.GetPlayer(message.SenderId);
2020-08-09 19:33:36 +01:00
player.UpdateState(State.ProbeLauncher, message.ToggleValue);
2020-08-10 12:16:07 +01:00
player.ProbeLauncher?.ChangeEquipState(message.ToggleValue);
2020-08-08 13:27:49 +01:00
}
2020-08-09 09:37:32 +02:00
public override void OnReceiveLocal(ToggleMessage message)
2020-08-08 13:27:49 +01:00
{
2020-08-09 22:10:47 +01:00
PlayerRegistry.LocalPlayer.UpdateState(State.ProbeLauncher, message.ToggleValue);
2020-08-08 13:27:49 +01:00
}
}
}