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

45 lines
1.6 KiB
C#
Raw Normal View History

2020-11-03 21:42:14 +00:00
using QSB.EventsCore;
2020-08-13 21:46:16 +02:00
using QSB.Messaging;
2020-11-03 21:33:48 +00:00
using QSB.Player;
2020-08-08 13:27:49 +01:00
2020-11-03 17:56:48 +00:00
namespace QSB.Tools.Events
2020-08-08 13:27:49 +01:00
{
2020-08-10 18:17:54 +02:00
public class PlayerProbeLauncherEvent : QSBEvent<ToggleMessage>
2020-08-08 13:27:49 +01:00
{
2020-08-22 18:08:25 +01:00
public override EventType Type => EventType.ProbeLauncherActiveChange;
2020-08-08 13:27:49 +01:00
public override void SetupListener()
{
2020-08-15 21:52:43 +02:00
GlobalMessenger<ProbeLauncher>.AddListener(EventNames.ProbeLauncherEquipped, HandleEquip);
GlobalMessenger<ProbeLauncher>.AddListener(EventNames.ProbeLauncherUnequipped, HandleUnequip);
2020-08-08 13:27:49 +01:00
}
2020-08-15 20:32:58 +01:00
public override void CloseListener()
{
2020-08-15 21:52:43 +02:00
GlobalMessenger<ProbeLauncher>.RemoveListener(EventNames.ProbeLauncherEquipped, HandleEquip);
GlobalMessenger<ProbeLauncher>.RemoveListener(EventNames.ProbeLauncherUnequipped, HandleUnequip);
2020-08-15 20:32:58 +01:00
}
2020-08-15 21:52:43 +02:00
private void HandleEquip(ProbeLauncher var) => SendEvent(CreateMessage(true));
private void HandleUnequip(ProbeLauncher var) => SendEvent(CreateMessage(false));
2020-08-10 18:17:54 +02:00
private ToggleMessage CreateMessage(bool value) => new ToggleMessage
{
2020-08-17 16:51:56 +01:00
AboutId = LocalPlayerId,
2020-08-10 18:17:54 +02:00
ToggleValue = value
};
2020-08-10 14:40:06 +01:00
public override void OnReceiveRemote(ToggleMessage message)
2020-08-08 13:27:49 +01:00
{
2020-11-03 21:18:40 +00:00
var player = QSBPlayerManager.GetPlayer(message.AboutId);
2020-08-17 18:58:45 +02:00
player.UpdateState(State.ProbeLauncher, message.ToggleValue);
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-11-03 21:18:40 +00:00
QSBPlayerManager.LocalPlayer.UpdateState(State.ProbeLauncher, message.ToggleValue);
2020-08-08 13:27:49 +01:00
}
}
}