warvulture

This commit is contained in:
Ferdinando 2026-08-18 16:51:07 +02:00
commit 4559e0b9e1
14 changed files with 455 additions and 48 deletions

View file

@ -1,3 +1,4 @@
using System.Collections.Generic;
using System.Reflection;
using HarmonyLib;
using UnityEngine;
@ -158,9 +159,16 @@ namespace RacesOfValheim
// SkadiSEManPatch above from tier 1 onward, so the tier 2 "Freezing to Cold" conversion never
// gets a chance to run. These two patches scope out just that one environmental check: while
// Player.UpdateEnvStatusEffects is running for the local Skadi player, GetDamageModifiers is
// reported as Normal for Frost, so vanilla always attempts to apply the real status and
// SkadiSEManPatch's per-tier logic (block/convert/allow) is what actually decides the outcome.
// Frost damage resistance from hits (SkadiDamagePatch) is untouched by this.
// reported without SE_SkadiStats' own Frost contribution, so vanilla attempts to apply the
// real status and SkadiSEManPatch's per-tier logic (block/convert/allow) is what actually
// decides the outcome. Frost damage resistance from hits (SkadiDamagePatch) is untouched.
//
// Only the race's own contribution is discounted. This used to report a flat Normal, which
// also erased Frost resistance coming from a wolf/lox cape, a frost resistance mead or food:
// a Skadi who had beaten Moder still caught the converted Cold on the Mountain while wearing
// gear that makes a human immune, and below tier 4 caught real Freezing through the same gear.
// The tiered ladder is meant to make the race better than a bare human, never worse than an
// equipped one, so anything the player is actually wearing or drinking still counts.
[HarmonyPatch(typeof(Player), "UpdateEnvStatusEffects")]
public static class SkadiEnvCheckScope
{
@ -180,11 +188,38 @@ namespace RacesOfValheim
[HarmonyPatch(typeof(Character), "GetDamageModifiers")]
public static class SkadiEnvFrostModifierPatch
{
private static readonly int SkadiStatsHash = "SE_SkadiStats".GetStableHashCode();
// Handed to the aura in place of its own list while the recompute runs. SE_Stats applies
// m_mods as-is, so an empty list is simply "this effect grants nothing".
private static readonly List<HitData.DamageModPair> NoMods = new List<HitData.DamageModPair>();
private static bool recomputing = false;
public static void Postfix(Character __instance, ref HitData.DamageModifiers __result)
{
if (SkadiEnvCheckScope.Active && __instance == Player.m_localPlayer)
if (recomputing) return;
if (!SkadiEnvCheckScope.Active || __instance != Player.m_localPlayer) return;
// Character.GetDamageModifiers composes base modifiers + equipment + status effects,
// and DamageModifiers.Apply keeps the strongest of the lot - there is no way to
// subtract one contributor from a finished result. So the aura is muted and the whole
// thing recomputed: what comes back is exactly what this player would have without
// the race. The recursive call re-enters this postfix, which the flag turns into a
// no-op. The status effect on the player is a clone of the registered prototype
// (SEMan.AddStatusEffect clones on add), hence the lookup by hash rather than
// SkadiRace.skadiCurseSE.
SE_Stats aura = __instance.GetSEMan().GetStatusEffect(SkadiStatsHash) as SE_Stats;
List<HitData.DamageModPair> auraMods = aura != null ? aura.m_mods : null;
recomputing = true;
if (aura != null) aura.m_mods = NoMods;
try
{
__result.m_frost = HitData.DamageModifier.Normal;
__result.m_frost = __instance.GetDamageModifiers(null).m_frost;
}
finally
{
if (aura != null) aura.m_mods = auraMods;
recomputing = false;
}
}
}