102 lines
3.1 KiB
C#
Raw Normal View History

using HarmonyLib;
2021-12-24 21:49:18 -08:00
using QSB.CampfireSync.Messages;
using QSB.CampfireSync.WorldObjects;
2022-04-01 21:51:03 +01:00
using QSB.ItemSync.WorldObjects.Items;
2021-12-24 21:49:18 -08:00
using QSB.Messaging;
2021-03-29 23:36:51 +01:00
using QSB.Patches;
using QSB.WorldSync;
2022-03-02 11:51:31 +00:00
using UnityEngine;
2021-03-29 23:36:51 +01:00
2022-03-02 19:46:33 -08:00
namespace QSB.CampfireSync.Patches;
[HarmonyPatch]
internal class CampfirePatches : QSBPatch
2021-03-29 23:36:51 +01:00
{
2022-03-02 19:46:33 -08:00
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
2022-03-02 19:46:33 -08:00
[HarmonyPrefix]
[HarmonyPatch(typeof(Campfire), nameof(Campfire.OnPressInteract))]
public static bool LightCampfireEvent(Campfire __instance)
{
var qsbCampfire = __instance.GetWorldObject<QSBCampfire>();
2022-04-01 21:51:03 +01:00
if (__instance._state != Campfire.State.LIT)
2022-03-02 19:46:33 -08:00
{
2022-04-01 21:51:03 +01:00
__instance.SetState(Campfire.State.LIT, false);
2022-03-02 19:46:33 -08:00
qsbCampfire.SendMessage(new CampfireStateMessage(Campfire.State.LIT));
Locator.GetFlashlight().TurnOff(false);
2022-04-01 21:51:03 +01:00
if (Locator.GetToolModeSwapper().GetItemCarryTool().GetHeldItemType() == ItemType.SlideReel)
{
__instance.SetDropSlideReelMode(true);
}
return false;
}
2022-03-02 11:51:31 +00:00
2022-04-01 21:51:03 +01:00
if (__instance._dropSlideReelMode)
{
var slideReelItem = (SlideReelItem)Locator.GetToolModeSwapper().GetItemCarryTool().GetHeldItem();
Locator.GetToolModeSwapper().GetItemCarryTool().DropItemInstantly(__instance._sector, __instance._burnedSlideReelSocket);
slideReelItem.Burn();
slideReelItem.GetWorldObject<QSBSlideReelItem>().SendMessage(new BurnSlideReelMessage(qsbCampfire));
__instance.SetDropSlideReelMode(false);
__instance._hasBurnedSlideReel = true;
__instance._oneShotAudio.PlayOneShot(AudioType.TH_Campfire_Ignite, 1f);
return false;
}
__instance.StartRoasting();
2022-03-02 19:46:33 -08:00
return false;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Campfire), nameof(Campfire.Update))]
public static bool UpdateReplacement(Campfire __instance)
{
var targetLitFraction = 0f;
switch (__instance._state)
2022-03-02 11:51:31 +00:00
{
2022-03-02 19:46:33 -08:00
case Campfire.State.UNLIT:
targetLitFraction = 0f;
break;
case Campfire.State.LIT:
targetLitFraction = 1f;
break;
case Campfire.State.SMOLDERING:
targetLitFraction = 0.4f;
break;
}
2022-03-02 11:51:31 +00:00
2022-03-02 19:46:33 -08:00
if (__instance._litFraction != targetLitFraction)
{
__instance.SetLitFraction(Mathf.MoveTowards(__instance._litFraction, targetLitFraction, Time.deltaTime));
}
2022-03-02 11:51:31 +00:00
2022-03-02 19:46:33 -08:00
if (__instance._canSleepHere)
{
__instance._sleepPrompt.SetVisibility(false);
if (__instance._interactVolumeFocus && !__instance._isPlayerSleeping && !__instance._isPlayerRoasting && OWInput.IsInputMode(InputMode.Character))
2022-03-02 11:51:31 +00:00
{
2022-03-02 19:46:33 -08:00
__instance._sleepPrompt.SetVisibility(true);
__instance._sleepPrompt.SetDisplayState(__instance.CanSleepHereNow() ? ScreenPrompt.DisplayState.Normal : ScreenPrompt.DisplayState.GrayedOut);
if (OWInput.IsNewlyPressed(InputLibrary.interactSecondary, InputMode.All) && __instance.CanSleepHereNow())
2022-03-02 11:51:31 +00:00
{
2022-03-02 19:46:33 -08:00
__instance.StartSleeping();
2022-03-02 11:51:31 +00:00
}
}
2022-03-02 19:46:33 -08:00
}
2022-03-02 11:51:31 +00:00
2023-02-08 22:09:48 +00:00
if (__instance._isPlayerSleeping && Time.timeSinceLevelLoad > __instance._fastForwardStartTime)
2022-03-02 19:46:33 -08:00
{
__instance._wakePrompt.SetVisibility(OWInput.IsInputMode(InputMode.None) && Time.timeSinceLevelLoad - __instance._fastForwardStartTime > __instance.GetWakePromptDelay());
if (__instance.ShouldWakeUp())
2022-03-02 11:51:31 +00:00
{
2022-03-02 19:46:33 -08:00
__instance.StopSleeping(false);
return false;
2022-03-02 11:51:31 +00:00
}
}
2022-03-02 19:46:33 -08:00
return false;
2021-03-29 23:36:51 +01:00
}
}