add campfire sync

This commit is contained in:
Mister_Nebula 2021-03-29 23:36:51 +01:00
parent 14d7c9422e
commit fe968e9510
10 changed files with 86 additions and 15 deletions

View File

@ -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<EnumWorldObjectMessage<Campfire.State>>
{
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);
}
}
}

View File

@ -1,11 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace QSB.CampfireSync.Events
{
class CampfireStateMessage
{
}
}

View File

@ -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<Campfire>("OnPressInteract", typeof(CampfirePatches), nameof(Campfire_OnPressInteract));
public override void DoUnpatches() => QSBCore.HarmonyHelper.Unpatch<Campfire>("OnPressInteract");
public static bool Campfire_OnPressInteract(Campfire __instance, Campfire.State ____state)
{
var qsbCampfire = QSBWorldSync.GetWorldFromUnity<QSBCampfire, Campfire>(__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;
}
}
}

View File

@ -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);
}

View File

@ -57,5 +57,6 @@
public static string QSBPlayerKick = "QSBPlayerKick";
public static string QSBEnterPlatform = "QSBEnterPlatform";
public static string QSBExitPlatform = "QSBExitPlatform";
public static string QSBCampfireState = "QSBCampfireState";
}
}

View File

@ -39,6 +39,13 @@
SocketItem,
MoveToCarry,
StartStatue,
PlayerKick
PlayerKick,
CampfireState,
Roasting,
MarshmallowToss,
MarshmallowBurn,
MarshmallowRemove,
MarshmallowShrivel,
MarshmallowSpawn
}
}

View File

@ -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(),

View File

@ -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);

View File

@ -108,7 +108,8 @@
<Compile Include="Animation\CrouchSync.cs" />
<Compile Include="Animation\PlayerHeadRotationSync.cs" />
<Compile Include="CampfireSync\CampfireManager.cs" />
<Compile Include="CampfireSync\Events\CampfireStateMessage.cs" />
<Compile Include="CampfireSync\Events\CampfireStateEvent.cs" />
<Compile Include="CampfireSync\Patches\CampfirePatches.cs" />
<Compile Include="CampfireSync\WorldObjects\QSBCampfire.cs" />
<Compile Include="ConversationSync\Events\DialogueConditionEvent.cs" />
<Compile Include="ConversationSync\Events\DialogueConditionMessage.cs" />

View File

@ -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"
}