2022-04-16 09:08:59 +00:00
|
|
|
|
using QSB.Messaging;
|
2021-12-24 01:31:36 +00:00
|
|
|
|
using QSB.Player;
|
|
|
|
|
using QSB.Player.TransformSync;
|
2022-04-16 09:08:59 +00:00
|
|
|
|
using QSB.ShipSync;
|
|
|
|
|
using QSB.Tools.ProbeLauncherTool.WorldObjects;
|
2021-12-24 01:31:36 +00:00
|
|
|
|
using QSB.Utility;
|
2022-04-16 09:08:59 +00:00
|
|
|
|
using QSB.WorldSync;
|
2021-12-24 01:31:36 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
namespace QSB.Tools.ProbeLauncherTool.Messages;
|
|
|
|
|
|
2022-04-16 09:08:59 +00:00
|
|
|
|
public class EquipProbeLauncherMessage : QSBWorldObjectMessage<QSBProbeLauncher, bool>
|
2021-12-24 01:31:36 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
static EquipProbeLauncherMessage()
|
2021-12-24 01:31:36 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
GlobalMessenger<ProbeLauncher>.AddListener(OWEvents.ProbeLauncherEquipped, launcher => Handle(launcher, true));
|
|
|
|
|
GlobalMessenger<ProbeLauncher>.AddListener(OWEvents.ProbeLauncherUnequipped, launcher => Handle(launcher, false));
|
|
|
|
|
}
|
2021-12-24 01:31:36 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
private static void Handle(ProbeLauncher launcher, bool equipped)
|
|
|
|
|
{
|
2022-04-16 09:08:59 +00:00
|
|
|
|
if (PlayerTransformSync.LocalInstance == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var local = launcher == QSBPlayerManager.LocalPlayer.LocalProbeLauncher;
|
|
|
|
|
|
|
|
|
|
if (local)
|
2021-12-24 01:31:36 +00:00
|
|
|
|
{
|
2022-04-16 09:08:59 +00:00
|
|
|
|
new PlayerEquipLauncherMessage(equipped).Send();
|
|
|
|
|
return;
|
2021-12-24 01:31:36 +00:00
|
|
|
|
}
|
2022-04-16 09:08:59 +00:00
|
|
|
|
|
|
|
|
|
var worldObject = launcher.GetWorldObject<QSBProbeLauncher>();
|
|
|
|
|
worldObject.SendMessage(new EquipProbeLauncherMessage(equipped));
|
2022-03-03 03:46:33 +00:00
|
|
|
|
}
|
2021-12-24 01:31:36 +00:00
|
|
|
|
|
2022-03-11 01:57:50 +00:00
|
|
|
|
private EquipProbeLauncherMessage(bool equipped) : base(equipped) { }
|
2022-03-03 03:46:33 +00:00
|
|
|
|
|
|
|
|
|
public override void OnReceiveRemote()
|
|
|
|
|
{
|
2022-04-16 09:08:59 +00:00
|
|
|
|
DebugLog.DebugWrite($"{From} equip {WorldObject}");
|
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
var player = QSBPlayerManager.GetPlayer(From);
|
2022-04-16 09:32:25 +00:00
|
|
|
|
player.ProbeLauncherEquipped = Data ? WorldObject : null;
|
2022-04-16 09:08:59 +00:00
|
|
|
|
|
|
|
|
|
if (player.FlyingShip && WorldObject.AttachedObject == ShipManager.Instance.CockpitController.GetShipProbeLauncher())
|
|
|
|
|
{
|
|
|
|
|
ShipManager.Instance.UpdateProbeLauncher(Data);
|
|
|
|
|
}
|
2021-12-24 01:31:36 +00:00
|
|
|
|
}
|
2022-03-03 03:46:33 +00:00
|
|
|
|
|
2022-04-16 09:08:59 +00:00
|
|
|
|
public override void OnReceiveLocal()
|
|
|
|
|
{
|
2022-04-16 09:32:25 +00:00
|
|
|
|
QSBPlayerManager.LocalPlayer.ProbeLauncherEquipped = Data ? WorldObject : null;
|
2022-04-16 09:08:59 +00:00
|
|
|
|
}
|
2021-12-24 01:31:36 +00:00
|
|
|
|
}
|