148 lines
4.8 KiB
C#
Raw Normal View History

using HarmonyLib;
2021-12-25 22:53:36 -08:00
using QSB.Messaging;
2021-03-30 17:28:05 +01:00
using QSB.Patches;
2021-12-25 22:53:36 -08:00
using QSB.RoastingSync.Messages;
2021-03-30 17:28:05 +01:00
using UnityEngine;
namespace QSB.RoastingSync.Patches
{
[HarmonyPatch]
2021-03-31 10:30:51 +01:00
internal class RoastingPatches : QSBPatch
2021-03-30 17:28:05 +01:00
{
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
[HarmonyPrefix]
[HarmonyPatch(typeof(Marshmallow), nameof(Marshmallow.SpawnMallow))]
2021-03-30 17:28:05 +01:00
public static bool Marshmallow_SpawnMallow()
{
2021-12-25 22:53:36 -08:00
new MarshmallowEventMessage(MarshmallowMessageType.Replace).Send();
2021-03-30 17:28:05 +01:00
return true;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Marshmallow), nameof(Marshmallow.Burn))]
2021-03-30 17:28:05 +01:00
public static bool Marshmallow_Burn(
Marshmallow __instance
)
2021-03-30 17:28:05 +01:00
{
if (__instance._mallowState == Marshmallow.MallowState.Default)
2021-03-30 17:28:05 +01:00
{
__instance._fireRenderer.enabled = true;
__instance._toastedFraction = 1f;
__instance._initBurnTime = Time.time;
__instance._mallowState = Marshmallow.MallowState.Burning;
__instance._audioController.PlayMarshmallowCatchFire();
2021-12-25 22:53:36 -08:00
new MarshmallowEventMessage(MarshmallowMessageType.Burn).Send();
2021-03-30 17:28:05 +01:00
}
2021-06-18 22:38:32 +01:00
2021-03-30 17:28:05 +01:00
return false;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Marshmallow), nameof(Marshmallow.Shrivel))]
2021-03-30 17:28:05 +01:00
public static bool Marshmallow_Shrivel(
Marshmallow __instance
)
2021-03-30 17:28:05 +01:00
{
if (__instance._mallowState == Marshmallow.MallowState.Burning)
2021-03-30 17:28:05 +01:00
{
__instance._initShrivelTime = Time.time;
__instance._mallowState = Marshmallow.MallowState.Shriveling;
2021-12-25 22:53:36 -08:00
new MarshmallowEventMessage(MarshmallowMessageType.Shrivel).Send();
2021-03-30 17:28:05 +01:00
}
2021-06-18 22:38:32 +01:00
2021-03-30 17:28:05 +01:00
return false;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Marshmallow), nameof(Marshmallow.RemoveMallow))]
2021-03-30 17:28:05 +01:00
public static bool Marshmallow_RemoveMallow(
Marshmallow __instance)
{
__instance._smokeParticles.Stop();
__instance._fireRenderer.enabled = false;
__instance._mallowRenderer.enabled = false;
__instance._mallowState = Marshmallow.MallowState.Gone;
2021-03-30 17:28:05 +01:00
__instance.enabled = false;
2021-12-25 22:53:36 -08:00
new MarshmallowEventMessage(MarshmallowMessageType.Remove).Send();
2021-03-30 17:28:05 +01:00
return false;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(RoastingStickController), nameof(RoastingStickController.UpdateMarshmallowInput))]
2021-03-30 17:28:05 +01:00
public static bool RoastingStickController_UpdateMarshmallowInput(
RoastingStickController __instance
)
2021-03-30 17:28:05 +01:00
{
var changePromptText = false;
var showRemovePrompt = false;
2021-03-31 10:30:51 +01:00
var text = string.Empty;
if (__instance._extendFraction == 0f)
2021-03-30 17:28:05 +01:00
{
if (__instance._marshmallow.IsEdible())
2021-03-30 17:28:05 +01:00
{
text = UITextLibrary.GetString(UITextType.RoastingEatPrompt);
changePromptText = true;
if (__instance._marshmallow.IsBurned())
2021-03-30 17:28:05 +01:00
{
showRemovePrompt = true;
2021-10-12 15:31:02 +01:00
if (OWInput.IsNewlyPressed(InputLibrary.cancel, InputMode.Roasting))
2021-03-30 17:28:05 +01:00
{
__instance._marshmallow.Remove();
2021-03-30 17:28:05 +01:00
Locator.GetPlayerAudioController().PlayMarshmallowToss();
var spawnedMarshmallow = Object.Instantiate(__instance._mallowBodyPrefab, __instance._stickTransform.position, __instance._stickTransform.rotation);
2021-03-30 17:28:05 +01:00
var rigidbody = spawnedMarshmallow.GetComponent<OWRigidbody>();
rigidbody.SetVelocity(__instance._campfire.GetAttachedOWRigidbody().GetPointVelocity(__instance._stickTransform.position) + __instance._stickTransform.forward * 3f);
rigidbody.SetAngularVelocity(__instance._stickTransform.right * 10f);
var burntColor = __instance._marshmallow.GetBurntColor();
2021-03-30 17:28:05 +01:00
spawnedMarshmallow.GetComponentInChildren<MeshRenderer>().material.color = burntColor;
2021-12-25 22:53:36 -08:00
new MarshmallowEventMessage(MarshmallowMessageType.Toss).Send();
2021-03-30 17:28:05 +01:00
}
}
2021-06-18 22:38:32 +01:00
if (OWInput.IsNewlyPressed(InputLibrary.interact, InputMode.Roasting) && __instance._marshmallow.IsEdible())
2021-03-30 17:28:05 +01:00
{
__instance._marshmallow.Eat();
2021-03-30 17:28:05 +01:00
}
}
else if (__instance._marshmallow.GetState() == Marshmallow.MallowState.Burning)
2021-03-30 17:28:05 +01:00
{
text = UITextLibrary.GetString(UITextType.RoastingExtinguishPrompt);
changePromptText = true;
if (OWInput.IsNewlyPressed(InputLibrary.interact, InputMode.Roasting))
{
__instance._marshmallow.Extinguish();
2021-12-25 22:53:36 -08:00
new MarshmallowEventMessage(MarshmallowMessageType.Extinguish).Send();
2021-03-30 17:28:05 +01:00
}
}
else if (__instance._marshmallow.GetState() == Marshmallow.MallowState.Gone)
2021-03-30 17:28:05 +01:00
{
text = UITextLibrary.GetString(UITextType.RoastingReplacePrompt);
changePromptText = true;
if (OWInput.IsNewlyPressed(InputLibrary.interact, InputMode.Roasting))
{
__instance._marshmallow.SpawnMallow(true);
2021-03-30 17:28:05 +01:00
}
}
if (changePromptText && __instance._promptText != text)
2021-03-30 17:28:05 +01:00
{
__instance._promptText = text;
__instance._mallowPrompt.SetText(__instance._promptText);
2021-03-30 17:28:05 +01:00
}
if (OWInput.IsNewlyPressed(InputLibrary.cancel, InputMode.Roasting))
{
__instance._campfire.StopRoasting();
2021-03-30 17:28:05 +01:00
return false;
}
}
__instance._showMallowPrompt = changePromptText;
__instance._showRemovePrompt = showRemovePrompt;
2021-03-30 17:28:05 +01:00
return false;
}
}
}