warvulture
This commit is contained in:
parent
70bb263609
commit
4559e0b9e1
14 changed files with 455 additions and 48 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -167,11 +167,24 @@ namespace RacesOfValheim
|
|||
// Update the stats SE
|
||||
if (skadiCurseSE != null)
|
||||
{
|
||||
int auraHash = skadiCurseSE.name.GetStableHashCode();
|
||||
SEMan seman = Player.m_localPlayer.GetSEMan();
|
||||
|
||||
skadiCurseSE.UpdateStats(rules);
|
||||
if (!Player.m_localPlayer.GetSEMan().HaveStatusEffect(skadiCurseSE.name.GetStableHashCode()))
|
||||
if (!seman.HaveStatusEffect(auraHash))
|
||||
{
|
||||
Player.m_localPlayer.GetSEMan().AddStatusEffect(skadiCurseSE.name.GetStableHashCode(), true);
|
||||
seman.AddStatusEffect(auraHash, true);
|
||||
}
|
||||
|
||||
// SEMan.AddStatusEffect stores a Clone() of the prototype, so updating
|
||||
// skadiCurseSE alone only changed the copy that gets stamped out at the next add:
|
||||
// the aura already running on the player kept whatever tier it was born with.
|
||||
// Beating a boss mid-session left the old frost modifier and eitr regen in place
|
||||
// until the effect was re-added (race reselection or a relog) - most visibly at
|
||||
// the Queen, where Immune never replaced Resistant. Refresh the live one as well;
|
||||
// UpdateStats is a no-op unless the tier actually moved a value.
|
||||
SE_SkadiStats liveAura = seman.GetStatusEffect(auraHash) as SE_SkadiStats;
|
||||
if (liveAura != null) liveAura.UpdateStats(rules);
|
||||
}
|
||||
|
||||
if (rules.FrostAura)
|
||||
|
|
|
|||
|
|
@ -27,8 +27,29 @@ namespace RacesOfValheim
|
|||
m_tooltip = "Empowered by the frost.";
|
||||
}
|
||||
|
||||
// What the last UpdateStats call actually wrote. SEMan.AddStatusEffect stores a Clone() of
|
||||
// the registered prototype, so the effect running on the player is a separate object that
|
||||
// has to be refreshed too (SkadiRace.Update does that) - and both of them are asked to
|
||||
// update every frame. Rebuilding the mod list each time would churn a List per frame per
|
||||
// instance, so nothing is rewritten until a tier change actually moves a value. These
|
||||
// fields are not serialized, so a fresh clone starts at "never applied" and rebuilds once.
|
||||
private bool statsApplied = false;
|
||||
private float appliedFrostResistance = 0f;
|
||||
private float appliedEitrRegenMultiplier = 0f;
|
||||
|
||||
public void UpdateStats(SkadiProgression.FormRules rules)
|
||||
{
|
||||
if (statsApplied &&
|
||||
rules.FrostResistance == appliedFrostResistance &&
|
||||
rules.EitrRegenMultiplier == appliedEitrRegenMultiplier)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
statsApplied = true;
|
||||
appliedFrostResistance = rules.FrostResistance;
|
||||
appliedEitrRegenMultiplier = rules.EitrRegenMultiplier;
|
||||
|
||||
m_mods = new List<HitData.DamageModPair>();
|
||||
if (rules.FrostResistance >= 1f)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue