33 lines
1005 B
C#
Raw Normal View History

2020-11-03 21:42:14 +00:00
using QSB.EventsCore;
2020-11-28 19:19:56 +00:00
using QSB.Utility;
using QSB.WorldSync;
2020-11-03 22:18:22 +00:00
using QSB.WorldSync.Events;
2020-11-03 17:56:48 +00:00
namespace QSB.OrbSync.Events
{
2020-12-02 21:29:53 +00:00
public class OrbSlotEvent : QSBEvent<BoolWorldObjectMessage>
{
public override EventType Type => EventType.OrbSlot;
2020-12-02 21:29:53 +00:00
public override void SetupListener() => GlobalMessenger<int, bool>.AddListener(EventNames.QSBOrbSlot, Handler);
2020-12-02 21:29:53 +00:00
public override void CloseListener() => GlobalMessenger<int, bool>.RemoveListener(EventNames.QSBOrbSlot, Handler);
2020-12-02 21:29:53 +00:00
private void Handler(int id, bool state) => SendEvent(CreateMessage(id, state));
2020-12-02 21:29:53 +00:00
private BoolWorldObjectMessage CreateMessage(int id, bool state) => new BoolWorldObjectMessage
{
AboutId = LocalPlayerId,
ObjectId = id,
State = state
};
2020-12-02 21:29:53 +00:00
public override void OnReceiveRemote(BoolWorldObjectMessage message)
{
DebugLog.DebugWrite($"receive slot {message.ObjectId} to {message.State}");
var orbSlot = WorldRegistry.GetObject<QSBOrbSlot>(message.ObjectId);
orbSlot?.SetState(message.State);
}
}
}