76 lines
2.1 KiB
C#
Raw Normal View History

2020-12-14 16:24:52 +00:00
using QSB.Events;
2020-12-14 16:28:03 +00:00
using QSB.Messaging;
2020-11-03 21:33:48 +00:00
using QSB.Player;
using QSB.Utility;
2020-08-08 13:27:49 +01:00
namespace QSB.Tools.ProbeLauncherTool.Messages
2020-08-08 13:27:49 +01:00
{
2021-07-26 22:55:09 +01:00
public class EquipProbeLauncherEvent : QSBEvent<ToggleMessage>
2020-12-02 21:23:01 +00:00
{
public override bool RequireWorldObjectsReady => false;
private bool _nonPlayerLauncherEquipped;
2020-12-02 21:23:01 +00:00
public override void SetupListener()
{
GlobalMessenger<ProbeLauncher>.AddListener(EventNames.ProbeLauncherEquipped, HandleEquip);
GlobalMessenger<ProbeLauncher>.AddListener(EventNames.ProbeLauncherUnequipped, HandleUnequip);
}
2020-08-08 13:27:49 +01:00
2020-12-02 21:23:01 +00:00
public override void CloseListener()
{
GlobalMessenger<ProbeLauncher>.RemoveListener(EventNames.ProbeLauncherEquipped, HandleEquip);
GlobalMessenger<ProbeLauncher>.RemoveListener(EventNames.ProbeLauncherUnequipped, HandleUnequip);
}
2020-08-15 20:32:58 +01:00
private void HandleEquip(ProbeLauncher var)
{
if (var != QSBPlayerManager.LocalPlayer.LocalProbeLauncher)
{
_nonPlayerLauncherEquipped = true;
return;
}
2021-08-22 17:17:46 +01:00
if (_nonPlayerLauncherEquipped)
{
DebugLog.ToConsole($"Warning - Trying to equip player launcher whilst non player launcher is still equipped?", OWML.Common.MessageType.Warning);
return;
}
2021-08-22 17:17:46 +01:00
SendEvent(CreateMessage(true));
}
private void HandleUnequip(ProbeLauncher var)
{
if (var != QSBPlayerManager.LocalPlayer.LocalProbeLauncher)
{
_nonPlayerLauncherEquipped = false;
return;
}
2021-08-22 17:17:46 +01:00
if (_nonPlayerLauncherEquipped)
{
DebugLog.ToConsole($"Warning - Trying to de-equip player launcher whilst non player launcher is still equipped?", OWML.Common.MessageType.Warning);
return;
}
2021-08-22 17:17:46 +01:00
SendEvent(CreateMessage(false));
}
2020-08-15 21:52:43 +02:00
2021-11-20 19:49:50 +00:00
private ToggleMessage CreateMessage(bool value) => new()
2020-12-02 21:23:01 +00:00
{
AboutId = LocalPlayerId,
ToggleValue = value
};
2020-08-10 18:17:54 +02:00
2020-12-11 22:42:21 +00:00
public override void OnReceiveRemote(bool server, ToggleMessage message)
2020-12-02 21:23:01 +00:00
{
var player = QSBPlayerManager.GetPlayer(message.AboutId);
player.ProbeLauncherEquipped = message.ToggleValue;
2020-12-02 21:23:01 +00:00
player.ProbeLauncher?.ChangeEquipState(message.ToggleValue);
}
2020-08-08 13:27:49 +01:00
2020-12-14 21:20:53 +00:00
public override void OnReceiveLocal(bool server, ToggleMessage message) =>
QSBPlayerManager.LocalPlayer.ProbeLauncherEquipped = message.ToggleValue;
2020-12-14 21:20:53 +00:00
}
2020-12-03 08:28:05 +00:00
}