30 lines
998 B
C#
Raw Normal View History

2020-12-14 16:24:52 +00:00
using QSB.Events;
using QSB.OrbSync.WorldObjects;
using QSB.WorldSync;
2020-11-03 17:56:48 +00:00
namespace QSB.OrbSync.Events
{
2020-12-07 18:49:51 +00:00
public class OrbSlotEvent : QSBEvent<OrbSlotMessage>
2020-12-02 21:29:53 +00:00
{
public override EventType Type => EventType.OrbSlot;
2020-12-07 18:49:51 +00:00
public override void SetupListener() => GlobalMessenger<int, int, bool>.AddListener(EventNames.QSBOrbSlot, Handler);
public override void CloseListener() => GlobalMessenger<int, int, bool>.RemoveListener(EventNames.QSBOrbSlot, Handler);
2020-12-07 18:49:51 +00:00
private void Handler(int slotId, int orbId, bool slotState) => SendEvent(CreateMessage(slotId, orbId, slotState));
2020-12-07 18:49:51 +00:00
private OrbSlotMessage CreateMessage(int slotId, int orbId, bool slotState) => new OrbSlotMessage
2020-12-02 21:29:53 +00:00
{
AboutId = LocalPlayerId,
2020-12-07 18:49:51 +00:00
SlotId = slotId,
OrbId = orbId,
SlotState = slotState
2020-12-02 21:29:53 +00:00
};
2020-12-11 22:42:21 +00:00
public override void OnReceiveRemote(bool server, OrbSlotMessage message)
2020-12-02 21:29:53 +00:00
{
2021-02-24 10:45:25 +00:00
var orbSlot = QSBWorldSync.GetWorldFromId<QSBOrbSlot>(message.SlotId);
2020-12-07 18:49:51 +00:00
orbSlot?.SetState(message.SlotState, message.OrbId);
2020-12-02 21:29:53 +00:00
}
}
2020-12-03 08:28:05 +00:00
}