2022-01-28 20:49:07 -08:00
|
|
|
|
using Cysharp.Threading.Tasks;
|
|
|
|
|
using QSB.Messaging;
|
2022-08-27 14:06:28 -04:00
|
|
|
|
using QSB.Player;
|
2021-12-25 23:45:40 -08:00
|
|
|
|
using QSB.Tools.ProbeLauncherTool.Messages;
|
2022-08-27 14:06:28 -04:00
|
|
|
|
using QSB.Tools.ProbeTool;
|
2021-07-24 21:25:29 +01:00
|
|
|
|
using QSB.WorldSync;
|
2022-01-28 20:49:07 -08:00
|
|
|
|
using System.Threading;
|
2022-08-27 14:06:28 -04:00
|
|
|
|
using UnityEngine;
|
2021-07-24 21:25:29 +01:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
namespace QSB.Tools.ProbeLauncherTool.WorldObjects;
|
|
|
|
|
|
2022-04-16 10:08:59 +01:00
|
|
|
|
public class QSBProbeLauncher : WorldObject<ProbeLauncher>
|
2021-07-24 21:25:29 +01:00
|
|
|
|
{
|
2022-08-27 14:06:28 -04:00
|
|
|
|
private uint _probeOwnerID = uint.MaxValue;
|
|
|
|
|
protected QSBProbe LaunchedProbe { get; private set; }
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2022-08-27 14:06:28 -04:00
|
|
|
|
// Retrieval resets the probe owner ID
|
|
|
|
|
var probeOwnerID = _probeOwnerID;
|
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
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
|
|
|
|
|
{
|
2022-08-27 14:06:28 -04:00
|
|
|
|
this.SendMessage(new LaunchProbeMessage(false, probeOwnerID));
|
2022-03-02 19:46:33 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-25 21:08:04 -08:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
private void OnLaunchProbe(SurveyorProbe probe) =>
|
2022-08-27 14:06:28 -04:00
|
|
|
|
this.SendMessage(new LaunchProbeMessage(true, QSBPlayerManager.LocalPlayerId));
|
2021-12-25 23:45:40 -08:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
public void RetrieveProbe(bool playEffects)
|
|
|
|
|
{
|
2022-08-27 14:06:28 -04:00
|
|
|
|
_probeOwnerID = uint.MaxValue;
|
|
|
|
|
LaunchedProbe = null;
|
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
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-08-27 14:06:28 -04:00
|
|
|
|
public void LaunchProbe(bool playEffects, uint probeOwnerID)
|
2022-03-02 19:46:33 -08:00
|
|
|
|
{
|
2022-08-27 14:06:28 -04:00
|
|
|
|
_probeOwnerID = probeOwnerID;
|
|
|
|
|
LaunchedProbe = QSBPlayerManager.GetPlayer(_probeOwnerID)?.Probe;
|
|
|
|
|
|
|
|
|
|
if (LaunchedProbe == null) Debug.LogError($"Could not find probe owner with ID {_probeOwnerID}");
|
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
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-08-27 02:05:15 -04:00
|
|
|
|
|
|
|
|
|
public void ChangeMode()
|
|
|
|
|
{
|
|
|
|
|
AttachedObject._effects.PlayChangeModeClip();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void TakeSnapshot()
|
|
|
|
|
{
|
|
|
|
|
// Not using PlaySnapshotClip because that uses Locator.GetPlayerAudioController() instead of owAudioSource for some reason
|
2022-08-27 14:06:28 -04:00
|
|
|
|
AttachedObject._effects._owAudioSource.PlayOneShot(AudioType.ToolProbeTakePhoto, 1f);
|
|
|
|
|
|
|
|
|
|
// If their probe is launched also play a snapshot from it
|
|
|
|
|
if (LaunchedProbe && LaunchedProbe.IsLaunched()) LaunchedProbe.TakeSnapshot();
|
2022-08-27 02:05:15 -04:00
|
|
|
|
}
|
2022-02-24 22:04:54 -08:00
|
|
|
|
}
|