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
{
class PlayerProbeLauncherEvent : QSBEvent
{
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:17:00 +02:00
GlobalMessenger<ProbeLauncher>.AddListener("ProbeLauncherEquipped", var => SendEvent(PlayerRegistry.LocalPlayer.NetId, true));
GlobalMessenger<ProbeLauncher>.AddListener("ProbeLauncherUnequipped", var => SendEvent(PlayerRegistry.LocalPlayer.NetId, false));
2020-08-08 13:27:49 +01:00
}
public override void OnReceive(uint sender, object[] data)
{
var player = PlayerRegistry.GetPlayer(sender);
var tool = player.ProbeLauncher;
player.UpdateState(State.ProbeLauncher, (bool)data[0]);
if ((bool)data[0] == true)
{
tool.EquipTool();
}
else
{
tool.UnequipTool();
}
}
public override void OnReceiveLocal(object[] data)
{
var tool = PlayerRegistry.LocalPlayer.ProbeLauncher;
if ((bool)data[0] == true)
{
tool.EquipTool();
}
else
{
tool.UnequipTool();
}
}
}
}