2021-10-15 20:06:51 +00:00
|
|
|
|
using HarmonyLib;
|
2021-12-25 05:49:18 +00:00
|
|
|
|
using QSB.CampfireSync.Messages;
|
2021-10-15 20:06:51 +00:00
|
|
|
|
using QSB.CampfireSync.WorldObjects;
|
2021-12-25 05:49:18 +00:00
|
|
|
|
using QSB.Messaging;
|
2021-03-29 22:36:51 +00:00
|
|
|
|
using QSB.Patches;
|
|
|
|
|
using QSB.WorldSync;
|
2022-03-02 11:51:31 +00:00
|
|
|
|
using UnityEngine;
|
2021-03-29 22:36:51 +00:00
|
|
|
|
|
2022-02-27 12:40:44 +00:00
|
|
|
|
namespace QSB.CampfireSync.Patches
|
2021-03-29 22:36:51 +00:00
|
|
|
|
{
|
2022-02-27 12:40:44 +00:00
|
|
|
|
[HarmonyPatch]
|
|
|
|
|
internal class CampfirePatches : QSBPatch
|
2022-02-25 06:04:54 +00:00
|
|
|
|
{
|
2022-02-27 12:40:44 +00:00
|
|
|
|
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
|
|
|
|
|
|
|
|
|
|
[HarmonyPrefix]
|
|
|
|
|
[HarmonyPatch(typeof(Campfire), nameof(Campfire.OnPressInteract))]
|
|
|
|
|
public static bool LightCampfireEvent(Campfire __instance)
|
2022-02-25 06:04:54 +00:00
|
|
|
|
{
|
2022-02-27 12:40:44 +00:00
|
|
|
|
var qsbCampfire = __instance.GetWorldObject<QSBCampfire>();
|
|
|
|
|
if (__instance._state == Campfire.State.LIT)
|
|
|
|
|
{
|
|
|
|
|
qsbCampfire.StartRoasting();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
qsbCampfire.SetState(Campfire.State.LIT);
|
|
|
|
|
qsbCampfire.SendMessage(new CampfireStateMessage(Campfire.State.LIT));
|
|
|
|
|
Locator.GetFlashlight().TurnOff(false);
|
|
|
|
|
}
|
2022-02-25 06:04:54 +00:00
|
|
|
|
|
2022-02-27 12:40:44 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2022-03-02 11:51:31 +00:00
|
|
|
|
|
|
|
|
|
[HarmonyPrefix]
|
|
|
|
|
[HarmonyPatch(typeof(Campfire), nameof(Campfire.Update))]
|
|
|
|
|
public static bool UpdateReplacement(Campfire __instance)
|
|
|
|
|
{
|
|
|
|
|
var targetLitFraction = 0f;
|
|
|
|
|
switch (__instance._state)
|
|
|
|
|
{
|
|
|
|
|
case Campfire.State.UNLIT:
|
|
|
|
|
targetLitFraction = 0f;
|
|
|
|
|
break;
|
|
|
|
|
case Campfire.State.LIT:
|
|
|
|
|
targetLitFraction = 1f;
|
|
|
|
|
break;
|
|
|
|
|
case Campfire.State.SMOLDERING:
|
|
|
|
|
targetLitFraction = 0.4f;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (__instance._litFraction != targetLitFraction)
|
|
|
|
|
{
|
|
|
|
|
__instance.SetLitFraction(Mathf.MoveTowards(__instance._litFraction, targetLitFraction, Time.deltaTime));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (__instance._canSleepHere)
|
|
|
|
|
{
|
|
|
|
|
__instance._sleepPrompt.SetVisibility(false);
|
|
|
|
|
if (__instance._interactVolumeFocus && !__instance._isPlayerSleeping && !__instance._isPlayerRoasting && OWInput.IsInputMode(InputMode.Character))
|
|
|
|
|
{
|
|
|
|
|
__instance._sleepPrompt.SetVisibility(true);
|
|
|
|
|
__instance._sleepPrompt.SetDisplayState(__instance.CanSleepHereNow() ? ScreenPrompt.DisplayState.Normal : ScreenPrompt.DisplayState.GrayedOut);
|
|
|
|
|
if (OWInput.IsNewlyPressed(InputLibrary.interactSecondary, InputMode.All) && __instance.CanSleepHereNow())
|
|
|
|
|
{
|
|
|
|
|
__instance.StartSleeping();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (__instance._isPlayerSleeping)
|
|
|
|
|
{
|
|
|
|
|
__instance._wakePrompt.SetVisibility(OWInput.IsInputMode(InputMode.None) && Time.timeSinceLevelLoad - __instance._fastForwardStartTime > __instance.GetWakePromptDelay());
|
|
|
|
|
if (__instance.ShouldWakeUp())
|
|
|
|
|
{
|
|
|
|
|
__instance.StopSleeping(false);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2021-03-29 22:36:51 +00:00
|
|
|
|
}
|
2022-02-25 06:04:54 +00:00
|
|
|
|
}
|