RacesOfValheim/JotunnModStub/Furling/FurlingFireAbility.cs
kanym 4b382e7fad feat(furling): make ability numbers BepInEx-configurable
Adds FurlingConfig.cs, following the established per-race pattern: one
Configuration Manager section per tier ability (Passive Combat, Master of
Shadows, The Wickerman, Grave Robber, The King Is Dead, In the Mist). No
keybinds section - every Furling ability is passive, triggered by tier,
biome, or combat events rather than a key press. Defaults match the
previous hardcoded constants exactly.

"Dance of the Dead" (tier 4+) has no numeric knob and stays untouched: it
doubles craft yield by crafting a literal second copy rather than
multiplying a configurable amount.

Also fixes a latent truncation bug found while wiring the trophy drop
multiplier: it was applied as `amount *= 2` (int), which would have
truncated any non-integer multiplier a player configured (e.g. 1.5x
rounding down every time). Now computed as
Mathf.RoundToInt(amount * multiplier).

Config sections stay bound alphabetically by race (Aswid, Draugh,
Dvergar, Fenrir, Furling, Skadi) in RacesOfValheim.Awake().
2026-08-06 14:25:23 +02:00

157 lines
6.6 KiB
C#

using HarmonyLib;
using UnityEngine;
using System.Collections.Generic;
namespace RacesOfValheim
{
/// <summary>
/// "Through Fire and Flames" — unlocks after Fader (state >= 8).
///
/// Effects:
/// 1. Player has SE_Burning applied ONCE (999-min duration), like walking on a bonfire.
/// Reapplied automatically after respawn, load, or state unlock.
/// 2. No fire damage taken (handled in FurlingPatches.Furling_Character_Damage_Patch).
/// 3. The Burning icon is hidden from the HUD.
/// 4. All physical attacks apply SE_Burning to the target.
/// </summary>
public static class FurlingFireAbility
{
private static int _lastState = -1;
private static bool _burningApplied = false;
private static readonly int BurningHash = "Burning".GetStableHashCode();
private const float BURN_DURATION = 999f * 60f; // 999 minutes in seconds
// ─── Called from FurlingRace.Update() — cheap check, no timer ────────
public static void Tick()
{
if (Player.m_localPlayer == null || !FurlingRace.IsFurling())
{
_burningApplied = false;
_lastState = -1;
return;
}
int state = BossProgressionManager.GetCurrentProgressionState();
if (state < 8)
{
_burningApplied = false;
_lastState = state;
return;
}
bool stateJustUnlocked = (_lastState < 8);
bool seMissing = !Player.m_localPlayer.GetSEMan()
.HaveStatusEffect(BurningHash);
// Apply only when: first time, state just reached 8, or SE was lost (respawn/load)
if (!_burningApplied || stateJustUnlocked || seMissing)
{
ApplyPermanentBurning();
_burningApplied = true;
}
_lastState = state;
}
private static void ApplyPermanentBurning()
{
var seman = Player.m_localPlayer.GetSEMan();
// Allow our application through the suppression patch
FurlingFire_SuppressExternalBurning_Patch.AllowNextBurning = true;
seman.AddStatusEffect(BurningHash, true);
// Override the duration to 999 minutes so it never expires naturally
StatusEffect se = seman.GetStatusEffect(BurningHash);
if (se != null)
{
se.m_ttl = BURN_DURATION;
// Reset elapsed time so we start fresh
HarmonyLib.Traverse.Create(se).Field<float>("m_time").Value = 0f;
}
}
// ─── Hide Burning icon from HUD ───────────────────────────────────────
[HarmonyPatch(typeof(SEMan), "GetStatusEffects")]
public static class FurlingFire_HideHUDBurning_Patch
{
public static void Postfix(SEMan __instance, List<StatusEffect> __result)
{
if (__result == null || __result.Count == 0) return;
Character character = HarmonyLib.Traverse.Create(__instance)
.Field<Character>("m_character").Value;
if (character == null || character != Player.m_localPlayer) return;
if (!FurlingRace.IsFurling()) return;
if (BossProgressionManager.GetCurrentProgressionState() < 8) return;
__result.RemoveAll(se => se != null && se.name != null &&
se.name.IndexOf("Burning", System.StringComparison.OrdinalIgnoreCase) >= 0);
}
}
// ─── Block external Burning (fire pits, arrows) from being applied ────
[HarmonyPatch(typeof(SEMan), "AddStatusEffect",
new System.Type[] { typeof(int), typeof(bool), typeof(int), typeof(float) })]
public static class FurlingFire_SuppressExternalBurning_Patch
{
public static bool AllowNextBurning = false;
public static bool Prefix(SEMan __instance, ref int nameHash)
{
if (nameHash != BurningHash) return true;
Character character = HarmonyLib.Traverse.Create(__instance)
.Field<Character>("m_character").Value;
if (character == null || character != Player.m_localPlayer) return true;
if (!FurlingRace.IsFurling()) return true;
if (BossProgressionManager.GetCurrentProgressionState() < 8) return true;
if (AllowNextBurning)
{
AllowNextBurning = false;
return true; // our own application — allow
}
return false; // external source — block (player is immune)
}
}
// ─── Physical attacks set enemies on fire ─────────────────────────────
[HarmonyPatch(typeof(Character), "Damage")]
public static class FurlingFire_IgniteOnHit_Patch
{
public static void Prefix(Character __instance, HitData hit)
{
if (__instance == null || __instance is Player) return;
if (Player.m_localPlayer == null || !FurlingRace.IsFurling()) return;
if (BossProgressionManager.GetCurrentProgressionState() < 8) return;
Character attacker = hit.GetAttacker();
if (attacker == null || attacker != Player.m_localPlayer) return;
if (hit.m_damage.m_blunt > 0 || hit.m_damage.m_slash > 0 ||
hit.m_damage.m_pierce > 0 || hit.m_damage.m_chop > 0 ||
hit.m_damage.m_pickaxe > 0)
{
hit.m_damage.m_fire = Mathf.Max(hit.m_damage.m_fire, FurlingConfig.IgniteOnHitMinFireDamage.Value);
}
}
public static void Postfix(Character __instance, HitData hit)
{
if (__instance == null || __instance is Player) return;
if (Player.m_localPlayer == null || !FurlingRace.IsFurling()) return;
if (BossProgressionManager.GetCurrentProgressionState() < 8) return;
Character attacker = hit.GetAttacker();
if (attacker == null || attacker != Player.m_localPlayer) return;
if (!__instance.IsDead())
__instance.GetSEMan().AddStatusEffect(BurningHash, true);
}
}
}
}