using QSB.CampfireSync.WorldObjects; using QSB.Events; using QSB.WorldSync; using QSB.WorldSync.Events; namespace QSB.CampfireSync.Events { internal class CampfireStateEvent : QSBEvent> { public override EventType Type => EventType.CampfireState; public override void SetupListener() => GlobalMessenger.AddListener(EventNames.QSBCampfireState, Handler); public override void CloseListener() => GlobalMessenger.RemoveListener(EventNames.QSBCampfireState, Handler); private void Handler(int objId, Campfire.State state) => SendEvent(CreateMessage(objId, state)); private EnumWorldObjectMessage CreateMessage(int objId, Campfire.State state) => new EnumWorldObjectMessage { AboutId = LocalPlayerId, ObjectId = objId, EnumValue = state }; public override void OnReceiveRemote(bool server, EnumWorldObjectMessage message) { if (!QSBSceneManager.IsInUniverse) { return; } var campfireObj = QSBWorldSync.GetWorldFromId(message.ObjectId); campfireObj.SetState(message.EnumValue); } } }