Mister_Nebula 53974485c9
Spiral sync (#242)
* add stuff

* extract patches

* extract worldobjects (#241)

* add spiral sync

* cleanup

* cleanup

* fix

* rename

* add computers

* remove qnet flagshelper

* Update README.md

* cleanup
2020-12-31 12:10:55 +00:00

29 lines
959 B
C#

using QSB.ElevatorSync.WorldObjects;
using QSB.Events;
using QSB.WorldSync;
using QSB.WorldSync.Events;
namespace QSB.ElevatorSync.Events
{
public class ElevatorEvent : QSBEvent<BoolWorldObjectMessage>
{
public override EventType Type => EventType.Elevator;
public override void SetupListener() => GlobalMessenger<int, bool>.AddListener(EventNames.QSBStartLift, Handler);
public override void CloseListener() => GlobalMessenger<int, bool>.RemoveListener(EventNames.QSBStartLift, Handler);
private void Handler(int id, bool isGoingUp) => SendEvent(CreateMessage(id, isGoingUp));
private BoolWorldObjectMessage CreateMessage(int id, bool isGoingUp) => new BoolWorldObjectMessage
{
State = isGoingUp,
ObjectId = id
};
public override void OnReceiveRemote(bool server, BoolWorldObjectMessage message)
{
var elevator = QSBWorldSync.GetWorldObject<QSBElevator>(message.ObjectId);
elevator?.RemoteCall(message.State);
}
}
}