quantum-space-buddies/QSB/Tools/ProbeLauncherTool/Messages/LaunchProbeEvent.cs

33 lines
994 B
C#
Raw Normal View History

2021-07-25 20:24:31 +00:00
using QSB.Events;
using QSB.Tools.ProbeLauncherTool.WorldObjects;
using QSB.WorldSync;
using QSB.WorldSync.Events;
namespace QSB.Tools.ProbeLauncherTool.Messages
2021-07-25 20:24:31 +00:00
{
2021-08-09 10:49:58 +00:00
internal class LaunchProbeEvent : QSBEvent<WorldObjectMessage>
2021-07-25 20:24:31 +00:00
{
public override bool RequireWorldObjectsReady => true;
2021-07-25 20:24:31 +00:00
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));
2021-11-20 19:49:50 +00:00
private BoolWorldObjectMessage CreateMessage(QSBProbeLauncher launcher) => new()
2021-07-25 20:24:31 +00:00
{
AboutId = LocalPlayerId,
ObjectId = launcher.ObjectId
};
public override void OnReceiveRemote(bool server, WorldObjectMessage message)
{
var worldObject = message.ObjectId.GetWorldObject<QSBProbeLauncher>();
2021-07-25 20:24:31 +00:00
worldObject.LaunchProbe();
}
}
}