add launch probe event

This commit is contained in:
Mister_Nebula 2021-07-25 21:24:31 +01:00
parent d822b74e93
commit 84544a6834
8 changed files with 63 additions and 4 deletions

View File

@ -79,5 +79,6 @@
public static string QSBProbeEvent = "QSBProbeEvent";
public static string QSBProbeStartRetrieve = "QSBProbeStartRetrieve";
public static string QSBRetrieveProbe = "QSBRetrieveProbe";
public static string QSBLaunchProbe = "QSBLaunchProbe";
}
}

View File

@ -117,5 +117,6 @@
// Probe Launcher
RetrieveProbe,
ProbeLauncherActiveChange,
LaunchProbe
}
}

View File

@ -59,6 +59,7 @@ namespace QSB.Events
new PlayerRespawnEvent(),
new ProbeStartRetrieveEvent(),
new RetrieveProbeEvent(),
new LaunchProbeEvent(),
// World Objects
new ElevatorEvent(),
new GeyserEvent(),

View File

@ -272,6 +272,7 @@
<Compile Include="Syncs\RigidbodySync\SectoredRigidbodySync.cs" />
<Compile Include="Syncs\SyncBase.cs" />
<Compile Include="TimeSync\Patches\TimePatches.cs" />
<Compile Include="Tools\ProbeLauncherTool\Events\LaunchProbeEvent.cs" />
<Compile Include="Tools\ProbeLauncherTool\Events\RetrieveProbeEvent.cs" />
<Compile Include="Tools\ProbeLauncherTool\Patches\LauncherPatches.cs" />
<Compile Include="Tools\ProbeLauncherTool\ProbeLauncherManager.cs" />

View File

@ -0,0 +1,32 @@
using QSB.Events;
using QSB.Tools.ProbeLauncherTool.WorldObjects;
using QSB.WorldSync;
using QSB.WorldSync.Events;
namespace QSB.Tools.ProbeLauncherTool.Events
{
class LaunchProbeEvent : QSBEvent<WorldObjectMessage>
{
public override EventType Type => EventType.LaunchProbe;
public override void SetupListener()
=> GlobalMessenger<QSBProbeLauncher>.AddListener(EventNames.QSBLaunchProbe, Handler);
public override void CloseListener()
=> GlobalMessenger<QSBProbeLauncher>.RemoveListener(EventNames.QSBLaunchProbe, Handler);
private void Handler(QSBProbeLauncher launcher) => SendEvent(CreateMessage(launcher));
private BoolWorldObjectMessage CreateMessage(QSBProbeLauncher launcher) => new BoolWorldObjectMessage
{
AboutId = LocalPlayerId,
ObjectId = launcher.ObjectId
};
public override void OnReceiveRemote(bool server, WorldObjectMessage message)
{
var worldObject = QSBWorldSync.GetWorldFromId<QSBProbeLauncher>(message.ObjectId);
worldObject.LaunchProbe();
}
}
}

View File

@ -1,7 +1,6 @@
using QSB.Events;
using QSB.TimeSync.Events;
using QSB.Tools.ProbeLauncherTool.WorldObjects;
using QSB.Utility;
using QSB.WorldSync;
using QSB.WorldSync.Events;
@ -28,7 +27,6 @@ namespace QSB.Tools.ProbeLauncherTool.Events
public override void OnReceiveRemote(bool server, BoolWorldObjectMessage message)
{
DebugLog.DebugWrite($"receive retrieve event id:{message.ObjectId} playEffects:{message.State}");
var worldObject = QSBWorldSync.GetWorldFromId<QSBProbeLauncher>(message.ObjectId);
worldObject.RetrieveProbe(message.State);
}

View File

@ -15,6 +15,8 @@ namespace QSB.Tools.ProbeLauncherTool.Patches
public override void DoPatches()
{
Prefix(nameof(ProbeLauncher_RetrieveProbe));
Postfix(nameof(ProbeLauncherEffects_PlayRetrievalClip));
Postfix(nameof(ProbeLauncherEffects_PlayLaunchClip));
}
public static bool ProbeLauncher_RetrieveProbe(
@ -66,5 +68,18 @@ namespace QSB.Tools.ProbeLauncherTool.Patches
return false;
}
// TODO : ehhhh idk about this. maybe copy each sound source so we have a 2d version (for local) and a 3d version (for remote)?
// this would probably be a whole qsb version on it's own
public static void ProbeLauncherEffects_PlayRetrievalClip(OWAudioSource ____owAudioSource)
{
____owAudioSource.GetAudioSource().spatialBlend = 1f;
}
public static void ProbeLauncherEffects_PlayLaunchClip(OWAudioSource ____owAudioSource)
{
____owAudioSource.GetAudioSource().spatialBlend = 1f;
}
}
}

View File

@ -1,4 +1,5 @@
using OWML.Utils;
using QSB.Events;
using QSB.ProbeSync;
using QSB.Utility;
using QSB.WorldSync;
@ -21,12 +22,12 @@ namespace QSB.Tools.ProbeLauncherTool.WorldObjects
_preLaunchProbeProxy = AttachedObject.GetValue<GameObject>("_preLaunchProbeProxy");
_effects = AttachedObject.GetValue<ProbeLauncherEffects>("_effects");
_probeRetrievalEffect = AttachedObject.GetValue<SingularityWarpEffect>("_probeRetrievalEffect");
AttachedObject.OnLaunchProbe += (SurveyorProbe probe) => QSBEventManager.FireEvent(EventNames.QSBLaunchProbe, this);
}
public void RetrieveProbe(bool playEffects)
{
DebugLog.DebugWrite($"{ObjectId} ({AttachedObject.name}) RETRIEVE");
_preLaunchProbeProxy.SetActive(true);
if (playEffects)
{
@ -34,5 +35,14 @@ namespace QSB.Tools.ProbeLauncherTool.WorldObjects
_probeRetrievalEffect.WarpObjectIn(_probeRetrievalLength);
}
}
public void LaunchProbe()
{
_preLaunchProbeProxy.SetActive(false);
// TODO : make this do underwater stuff correctly
_effects.PlayLaunchClip(false);
_effects.PlayLaunchParticles(false);
}
}
}