quantum-space-buddies/QSB/MeteorSync/Events/MeteorPreLaunchEvent.cs
2021-12-05 11:03:09 +00:00

32 lines
1013 B
C#

using QSB.Events;
using QSB.MeteorSync.WorldObjects;
using QSB.WorldSync;
using QSB.WorldSync.Events;
namespace QSB.MeteorSync.Events
{
public class MeteorPreLaunchEvent : QSBEvent<WorldObjectMessage>
{
public override bool RequireWorldObjectsReady => true;
public override void SetupListener()
=> GlobalMessenger<QSBMeteorLauncher>.AddListener(EventNames.QSBMeteorPreLaunch, Handler);
public override void CloseListener()
=> GlobalMessenger<QSBMeteorLauncher>.RemoveListener(EventNames.QSBMeteorPreLaunch, Handler);
private void Handler(QSBMeteorLauncher qsbMeteorLauncher) => SendEvent(CreateMessage(qsbMeteorLauncher));
private WorldObjectMessage CreateMessage(QSBMeteorLauncher qsbMeteorLauncher) => new()
{
ObjectId = qsbMeteorLauncher.ObjectId
};
public override void OnReceiveRemote(bool isHost, WorldObjectMessage message)
{
var qsbMeteorLauncher = QSBWorldSync.GetWorldFromId<QSBMeteorLauncher>(message.ObjectId);
qsbMeteorLauncher.PreLaunchMeteor();
}
}
}