mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-18 13:23:05 +00:00
34 lines
1.1 KiB
C#
34 lines
1.1 KiB
C#
using QSB.Events;
|
|
using QSB.MeteorSync.WorldObjects;
|
|
using QSB.WorldSync;
|
|
|
|
namespace QSB.MeteorSync.Events
|
|
{
|
|
public class MeteorLaunchEvent : QSBEvent<MeteorLaunchMessage>
|
|
{
|
|
public override bool RequireWorldObjectsReady => true;
|
|
|
|
public override void SetupListener()
|
|
=> GlobalMessenger<QSBMeteorLauncher>.AddListener(EventNames.QSBMeteorLaunch, Handler);
|
|
|
|
public override void CloseListener()
|
|
=> GlobalMessenger<QSBMeteorLauncher>.RemoveListener(EventNames.QSBMeteorLaunch, Handler);
|
|
|
|
private void Handler(QSBMeteorLauncher qsbMeteorLauncher) =>
|
|
SendEvent(CreateMessage(qsbMeteorLauncher));
|
|
|
|
private MeteorLaunchMessage CreateMessage(QSBMeteorLauncher qsbMeteorLauncher) => new()
|
|
{
|
|
ObjectId = qsbMeteorLauncher.ObjectId,
|
|
MeteorId = qsbMeteorLauncher.MeteorId,
|
|
LaunchSpeed = qsbMeteorLauncher.LaunchSpeed,
|
|
};
|
|
|
|
public override void OnReceiveRemote(bool isHost, MeteorLaunchMessage message)
|
|
{
|
|
var qsbMeteorLauncher = QSBWorldSync.GetWorldFromId<QSBMeteorLauncher>(message.ObjectId);
|
|
qsbMeteorLauncher.LaunchMeteor(message.MeteorId, message.LaunchSpeed);
|
|
}
|
|
}
|
|
}
|