1
0
mirror of https://github.com/misternebula/quantum-space-buddies.git synced 2025-03-13 10:13:50 +00:00

94 lines
2.5 KiB
C#
Raw Normal View History

2022-01-28 20:49:07 -08:00
using Cysharp.Threading.Tasks;
using QSB.Messaging;
using QSB.Player;
2021-12-25 23:45:40 -08:00
using QSB.Tools.ProbeLauncherTool.Messages;
using QSB.Tools.ProbeTool;
using QSB.WorldSync;
2022-01-28 20:49:07 -08:00
using System.Threading;
using UnityEngine;
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>
{
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;
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)
{
// Retrieval resets the probe owner ID
var probeOwnerID = _probeOwnerID;
2022-03-02 19:46:33 -08:00
if (AttachedObject._preLaunchProbeProxy.activeSelf)
{
2022-03-02 19:46:33 -08:00
this.SendMessage(new RetrieveProbeMessage(false));
}
2022-03-02 19:46:33 -08:00
else
{
this.SendMessage(new LaunchProbeMessage(false, probeOwnerID));
2022-03-02 19:46:33 -08:00
}
}
2022-03-02 19:46:33 -08:00
private void OnLaunchProbe(SurveyorProbe probe) =>
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)
{
_probeOwnerID = uint.MaxValue;
LaunchedProbe = null;
2022-03-02 19:46:33 -08:00
if (AttachedObject._preLaunchProbeProxy.activeSelf)
{
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);
}
2022-03-02 19:46:33 -08:00
}
2021-07-25 21:24:31 +01:00
public void LaunchProbe(bool playEffects, uint probeOwnerID)
2022-03-02 19:46:33 -08: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
}
}
public void ChangeMode()
{
AttachedObject._effects.PlayChangeModeClip();
}
public void TakeSnapshot()
{
// Not using PlaySnapshotClip because that uses Locator.GetPlayerAudioController() instead of owAudioSource for some reason
AttachedObject._effects._owAudioSource.PlayOneShot(AudioType.ToolProbeTakePhoto, 1f);
// If their probe is launched also play a snapshot from it
if (LaunchedProbe && LaunchedProbe.IsLaunched()) LaunchedProbe.TakeSnapshot();
}
}