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

33 lines
1018 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.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();
}
}
}