159 lines
6.8 KiB
C#
159 lines
6.8 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 ────
|
|
// 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);
|
|
}
|
|
}
|
|
}
|
|
}
|