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

44 lines
1.3 KiB
C#
Raw Normal View History

2020-08-09 09:17:00 +02:00
using QSB.Messaging;
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 09:37:32 +02:00
GlobalMessenger<ProbeLauncher>.AddListener("ProbeLauncherEquipped", var => SendEvent(new ToggleMessage { On = true }));
GlobalMessenger<ProbeLauncher>.AddListener("ProbeLauncherUnequipped", var => SendEvent(new ToggleMessage { On = false }));
2020-08-08 13:27:49 +01:00
}
2020-08-09 09:37:32 +02:00
public override void OnReceive(uint sender, ToggleMessage message)
2020-08-08 13:27:49 +01:00
{
var player = PlayerRegistry.GetPlayer(sender);
var tool = player.ProbeLauncher;
2020-08-09 09:37:32 +02:00
player.UpdateState(State.ProbeLauncher, message.On);
if (message.On)
2020-08-08 13:27:49 +01:00
{
tool.EquipTool();
}
else
{
tool.UnequipTool();
}
}
2020-08-09 09:37:32 +02:00
public override void OnReceiveLocal(ToggleMessage message)
2020-08-08 13:27:49 +01:00
{
var tool = PlayerRegistry.LocalPlayer.ProbeLauncher;
2020-08-09 09:37:32 +02:00
if (message.On)
2020-08-08 13:27:49 +01:00
{
tool.EquipTool();
}
else
{
tool.UnequipTool();
}
}
}
}