mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-18 13:23:05 +00:00
31 lines
1.1 KiB
C#
31 lines
1.1 KiB
C#
using QSB.CampfireSync.WorldObjects;
|
|
using QSB.Events;
|
|
using QSB.WorldSync;
|
|
using QSB.WorldSync.Events;
|
|
|
|
namespace QSB.CampfireSync.Events
|
|
{
|
|
internal class CampfireStateEvent : QSBEvent<EnumWorldObjectMessage<Campfire.State>>
|
|
{
|
|
public override bool RequireWorldObjectsReady => true;
|
|
|
|
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()
|
|
{
|
|
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);
|
|
}
|
|
}
|
|
}
|