2022-01-28 20:49:07 -08:00
|
|
|
|
using Cysharp.Threading.Tasks;
|
|
|
|
|
using QSB.Messaging;
|
2021-12-25 23:45:40 -08:00
|
|
|
|
using QSB.Tools.ProbeLauncherTool.Messages;
|
2021-07-24 21:25:29 +01:00
|
|
|
|
using QSB.WorldSync;
|
2022-01-28 20:49:07 -08:00
|
|
|
|
using System.Threading;
|
2021-07-24 21:25:29 +01:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
namespace QSB.Tools.ProbeLauncherTool.WorldObjects;
|
|
|
|
|
|
|
|
|
|
internal class QSBProbeLauncher : WorldObject<ProbeLauncher>
|
2021-07-24 21:25:29 +01:00
|
|
|
|
{
|
2022-03-02 19:46:33 -08:00
|
|
|
|
public override async UniTask Init(CancellationToken ct) =>
|
|
|
|
|
AttachedObject.OnLaunchProbe += OnLaunchProbe;
|
2021-07-24 21:25:29 +01:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
public override void OnRemoval() =>
|
|
|
|
|
AttachedObject.OnLaunchProbe -= OnLaunchProbe;
|
2021-12-25 23:45:40 -08:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
public override void SendInitialState(uint to)
|
|
|
|
|
{
|
|
|
|
|
if (AttachedObject._preLaunchProbeProxy.activeSelf)
|
2022-01-25 21:08:04 -08:00
|
|
|
|
{
|
2022-03-02 19:46:33 -08:00
|
|
|
|
this.SendMessage(new RetrieveProbeMessage(false));
|
2022-01-25 21:08:04 -08:00
|
|
|
|
}
|
2022-03-02 19:46:33 -08:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
this.SendMessage(new LaunchProbeMessage(false));
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-25 21:08:04 -08:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
private void OnLaunchProbe(SurveyorProbe probe) =>
|
|
|
|
|
this.SendMessage(new LaunchProbeMessage(true));
|
2021-12-25 23:45:40 -08:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
public void RetrieveProbe(bool playEffects)
|
|
|
|
|
{
|
|
|
|
|
if (AttachedObject._preLaunchProbeProxy.activeSelf)
|
2021-07-24 21:25:29 +01:00
|
|
|
|
{
|
2022-03-02 19:46:33 -08:00
|
|
|
|
return;
|
|
|
|
|
}
|
2022-01-25 21:23:31 -08:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
AttachedObject._preLaunchProbeProxy.SetActive(true);
|
|
|
|
|
if (playEffects)
|
|
|
|
|
{
|
|
|
|
|
AttachedObject._effects.PlayRetrievalClip();
|
|
|
|
|
AttachedObject._probeRetrievalEffect.WarpObjectIn(AttachedObject._probeRetrievalLength);
|
2021-07-24 21:25:29 +01:00
|
|
|
|
}
|
2022-03-02 19:46:33 -08:00
|
|
|
|
}
|
2021-07-25 21:24:31 +01:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
public void LaunchProbe(bool playEffects)
|
|
|
|
|
{
|
|
|
|
|
if (!AttachedObject._preLaunchProbeProxy.activeSelf)
|
2021-07-25 21:24:31 +01:00
|
|
|
|
{
|
2022-03-02 19:46:33 -08:00
|
|
|
|
return;
|
|
|
|
|
}
|
2022-01-25 21:23:31 -08:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
AttachedObject._preLaunchProbeProxy.SetActive(false);
|
2021-07-25 21:24:31 +01:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
if (playEffects)
|
|
|
|
|
{
|
|
|
|
|
// TODO : make this do underwater stuff correctly
|
|
|
|
|
AttachedObject._effects.PlayLaunchClip(false);
|
|
|
|
|
AttachedObject._effects.PlayLaunchParticles(false);
|
2021-07-25 21:24:31 +01:00
|
|
|
|
}
|
2021-07-24 21:25:29 +01:00
|
|
|
|
}
|
2022-02-24 22:04:54 -08:00
|
|
|
|
}
|