quantum-space-buddies/QSB/EyeOfTheUniverse/InstrumentSync/Event/GatherInstrumentEvent.cs
2021-12-20 17:53:11 -08:00

30 lines
1.0 KiB
C#

using QSB.Events;
using QSB.EyeOfTheUniverse.InstrumentSync.WorldObjects;
using QSB.WorldSync;
using QSB.WorldSync.Events;
namespace QSB.EyeOfTheUniverse.InstrumentSync.Event
{
internal class GatherInstrumentEvent : QSBEvent<WorldObjectMessage>
{
public override bool RequireWorldObjectsReady => true;
public override void SetupListener() => GlobalMessenger<QSBQuantumInstrument>.AddListener(EventNames.QSBGatherInstrument, Handler);
public override void CloseListener() => GlobalMessenger<QSBQuantumInstrument>.RemoveListener(EventNames.QSBGatherInstrument, Handler);
private void Handler(QSBQuantumInstrument instrument) => SendEvent(CreateMessage(instrument));
private BoolWorldObjectMessage CreateMessage(QSBQuantumInstrument instrument) => new()
{
AboutId = LocalPlayerId,
ObjectId = instrument.ObjectId
};
public override void OnReceiveRemote(bool isHost, WorldObjectMessage message)
{
var qsbObj = QSBWorldSync.GetWorldFromId<QSBQuantumInstrument>(message.ObjectId);
qsbObj.AttachedObject.Gather();
}
}
}