diff --git a/QSB/CampfireSync/Events/CampfireStateEvent.cs b/QSB/CampfireSync/Events/CampfireStateEvent.cs new file mode 100644 index 00000000..691fe578 --- /dev/null +++ b/QSB/CampfireSync/Events/CampfireStateEvent.cs @@ -0,0 +1,30 @@ +using QSB.CampfireSync.WorldObjects; +using QSB.Events; +using QSB.WorldSync; +using QSB.WorldSync.Events; + +namespace QSB.CampfireSync.Events +{ + 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) + { + var campfireObj = QSBWorldSync.GetWorldFromId(message.ObjectId); + campfireObj.SetState(message.EnumValue); + } + } +} diff --git a/QSB/CampfireSync/Events/CampfireStateMessage.cs b/QSB/CampfireSync/Events/CampfireStateMessage.cs deleted file mode 100644 index a0c0d959..00000000 --- a/QSB/CampfireSync/Events/CampfireStateMessage.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace QSB.CampfireSync.Events -{ - class CampfireStateMessage - { - } -} diff --git a/QSB/CampfireSync/Patches/CampfirePatches.cs b/QSB/CampfireSync/Patches/CampfirePatches.cs new file mode 100644 index 00000000..783a1672 --- /dev/null +++ b/QSB/CampfireSync/Patches/CampfirePatches.cs @@ -0,0 +1,32 @@ +using QSB.CampfireSync.WorldObjects; +using QSB.Events; +using QSB.Patches; +using QSB.WorldSync; +using System; + +namespace QSB.CampfireSync.Patches +{ + class CampfirePatches : QSBPatch + { + public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; + + public override void DoPatches() => QSBCore.HarmonyHelper.AddPrefix("OnPressInteract", typeof(CampfirePatches), nameof(Campfire_OnPressInteract)); + public override void DoUnpatches() => QSBCore.HarmonyHelper.Unpatch("OnPressInteract"); + + public static bool Campfire_OnPressInteract(Campfire __instance, Campfire.State ____state) + { + var qsbCampfire = QSBWorldSync.GetWorldFromUnity(__instance); + if (____state == Campfire.State.LIT) + { + qsbCampfire.StartRoasting(); + } + else + { + qsbCampfire.SetState(Campfire.State.LIT); + QSBEventManager.FireEvent(EventNames.QSBCampfireState, qsbCampfire.ObjectId, Campfire.State.LIT); + Locator.GetFlashlight().TurnOff(false); + } + return false; + } + } +} diff --git a/QSB/CampfireSync/WorldObjects/QSBCampfire.cs b/QSB/CampfireSync/WorldObjects/QSBCampfire.cs index 93e2ab27..5c50fe39 100644 --- a/QSB/CampfireSync/WorldObjects/QSBCampfire.cs +++ b/QSB/CampfireSync/WorldObjects/QSBCampfire.cs @@ -1,4 +1,5 @@ using QSB.WorldSync; +using System.Reflection; namespace QSB.CampfireSync.WorldObjects { @@ -10,6 +11,12 @@ namespace QSB.CampfireSync.WorldObjects AttachedObject = campfire; } + public void StartRoasting() + => AttachedObject + .GetType() + .GetMethod("StartRoasting", BindingFlags.NonPublic | BindingFlags.Instance) + .Invoke(AttachedObject, null); + public void SetState(Campfire.State newState) => AttachedObject.SetState(newState); } diff --git a/QSB/Events/EventNames.cs b/QSB/Events/EventNames.cs index a9bd1f13..71260176 100644 --- a/QSB/Events/EventNames.cs +++ b/QSB/Events/EventNames.cs @@ -57,5 +57,6 @@ public static string QSBPlayerKick = "QSBPlayerKick"; public static string QSBEnterPlatform = "QSBEnterPlatform"; public static string QSBExitPlatform = "QSBExitPlatform"; + public static string QSBCampfireState = "QSBCampfireState"; } } \ No newline at end of file diff --git a/QSB/Events/EventType.cs b/QSB/Events/EventType.cs index 6d8651e8..3ab5dfef 100644 --- a/QSB/Events/EventType.cs +++ b/QSB/Events/EventType.cs @@ -39,6 +39,13 @@ SocketItem, MoveToCarry, StartStatue, - PlayerKick + PlayerKick, + CampfireState, + Roasting, + MarshmallowToss, + MarshmallowBurn, + MarshmallowRemove, + MarshmallowShrivel, + MarshmallowSpawn } } \ No newline at end of file diff --git a/QSB/Events/QSBEventManager.cs b/QSB/Events/QSBEventManager.cs index ce9d65fc..3bf6e185 100644 --- a/QSB/Events/QSBEventManager.cs +++ b/QSB/Events/QSBEventManager.cs @@ -1,5 +1,6 @@ using OWML.Common; using QSB.Animation.Events; +using QSB.CampfireSync.Events; using QSB.ConversationSync.Events; using QSB.DeathSync.Events; using QSB.ElevatorSync.Events; @@ -63,6 +64,7 @@ namespace QSB.Events new SocketItemEvent(), new MoveToCarryEvent(), new StartStatueEvent(), + new CampfireStateEvent(), // Conversation/dialogue/exploration new ConversationEvent(), new ConversationStartEndEvent(), diff --git a/QSB/Patches/QSBPatchManager.cs b/QSB/Patches/QSBPatchManager.cs index 96192fee..4780328c 100644 --- a/QSB/Patches/QSBPatchManager.cs +++ b/QSB/Patches/QSBPatchManager.cs @@ -1,4 +1,5 @@ using OWML.Common; +using QSB.CampfireSync.Patches; using QSB.ConversationSync.Patches; using QSB.DeathSync.Patches; using QSB.ElevatorSync.Patches; @@ -45,7 +46,8 @@ namespace QSB.Patches new ItemPatches(), new StatuePatches(), new GeyserPatches(), - new PoolPatches() + new PoolPatches(), + new CampfirePatches() }; DebugLog.DebugWrite("Patch Manager ready.", MessageType.Success); diff --git a/QSB/QSB.csproj b/QSB/QSB.csproj index ef7c3873..947d119a 100644 --- a/QSB/QSB.csproj +++ b/QSB/QSB.csproj @@ -108,7 +108,8 @@ - + + diff --git a/QSB/manifest.json b/QSB/manifest.json index 112fda3d..cfd60e4a 100644 --- a/QSB/manifest.json +++ b/QSB/manifest.json @@ -4,6 +4,6 @@ "name": "Quantum Space Buddies", "description": "Adds online multiplayer to the game.", "uniqueName": "Raicuparta.QuantumSpaceBuddies", - "version": "0.9.1", + "version": "0.10.0", "owmlVersion": "1.1.8" } \ No newline at end of file