quantum-space-buddies/QSB/CampfireSync/Events/CampfireStateEvent.cs

31 lines
1.1 KiB
C#
Raw Normal View History

2021-03-29 22:36:51 +00:00
using QSB.CampfireSync.WorldObjects;
using QSB.Events;
using QSB.WorldSync;
using QSB.WorldSync.Events;
namespace QSB.CampfireSync.Events
{
2021-03-29 22:37:36 +00:00
internal class CampfireStateEvent : QSBEvent<EnumWorldObjectMessage<Campfire.State>>
2021-03-29 22:36:51 +00:00
{
public override EventType Type => EventType.CampfireState;
public override void SetupListener() => GlobalMessenger<int, Campfire.State>.AddListener(EventNames.QSBCampfireState, Handler);
public override void CloseListener() => GlobalMessenger<int, Campfire.State>.RemoveListener(EventNames.QSBCampfireState, Handler);
private void Handler(int objId, Campfire.State state) => SendEvent(CreateMessage(objId, state));
private EnumWorldObjectMessage<Campfire.State> CreateMessage(int objId, Campfire.State state) => new EnumWorldObjectMessage<Campfire.State>
{
AboutId = LocalPlayerId,
ObjectId = objId,
EnumValue = state
};
public override void OnReceiveRemote(bool server, EnumWorldObjectMessage<Campfire.State> message)
{
var campfireObj = QSBWorldSync.GetWorldFromId<QSBCampfire>(message.ObjectId);
campfireObj.SetState(message.EnumValue);
}
}
}