The ability is vanilla's Burning set to 999 minutes. FurlingRace.Update returned before ticking it for anyone who was not a Furling, and ResetRace never removed it, so the fire followed the player onto any race and came back visible if they picked the Furling again. The tick now runs for every race and puts out a Burning longer than an hour when the player is not a tier 8 Furling; ResetRace does the same at once.
183 lines
7.9 KiB
C#
183 lines
7.9 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() for every race — cheap check, no timer ────────
|
|
public static void Tick()
|
|
{
|
|
if (Player.m_localPlayer == null) return;
|
|
|
|
if (!FurlingRace.IsFurling())
|
|
{
|
|
RemovePermanentBurning(Player.m_localPlayer);
|
|
_burningApplied = false;
|
|
_lastState = -1;
|
|
return;
|
|
}
|
|
|
|
int state = BossProgressionManager.GetCurrentProgressionState();
|
|
|
|
if (state < 8)
|
|
{
|
|
RemovePermanentBurning(Player.m_localPlayer);
|
|
_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;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Puts out the fire this ability lit, and only that one.
|
|
///
|
|
/// It is vanilla's own Burning, so it outlived the race: FurlingRace.Update used to return
|
|
/// before calling Tick for anyone who was not a Furling, and ResetRace never listed it. A
|
|
/// player who changed race kept burning for 999 minutes, with no immunity and no hidden
|
|
/// icon, and brought the same fire back if they picked the Furling again.
|
|
///
|
|
/// The duration tells ours apart. Real fire lasts seconds, so a Burning longer than an hour
|
|
/// can only be the one set above; a player standing in a campfire keeps theirs.
|
|
/// </summary>
|
|
public static void RemovePermanentBurning(Player player)
|
|
{
|
|
SEMan seman = player != null ? player.GetSEMan() : null;
|
|
if (seman == null) return;
|
|
|
|
StatusEffect se = seman.GetStatusEffect(BurningHash);
|
|
if (se != null && se.m_ttl > 3600f) seman.RemoveStatusEffect(BurningHash, true);
|
|
}
|
|
|
|
// ─── 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 ────
|
|
// Valheim 1.0 appended a 'short variant' parameter to this overload. The type array has to
|
|
// match it exactly or the patch silently fails to bind and PatchAll throws.
|
|
[HarmonyPatch(typeof(SEMan), "AddStatusEffect",
|
|
new System.Type[] { typeof(int), typeof(bool), typeof(int), typeof(float), typeof(short) })]
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
}
|