RacesOfValheim/JotunnModStub/Sverm/SvermProgression.cs
2026-08-16 07:44:44 +02:00

116 lines
5.4 KiB
C#

using UnityEngine;
namespace RacesOfValheim
{
/// <summary>
/// Turns a boss progression state into the set of Sverm perks active at that tier, the same way
/// DvergarProgression and SkeletonProgression do for their races.
///
/// Nothing is decided here - every figure comes out of SvermConfig - so the tuning pass can
/// happen without touching a single patch.
///
/// ONE THING IS DELIBERATELY NOT IN THE STRUCT: the carapace's armour value and the eitr
/// regeneration. Both are read off ObjectDB, which is empty until a world loads, so caching
/// them in a rules struct built on the first call would freeze a zero into every later tier.
/// They live in SvermCarapace, which caches per state and only once ObjectDB answers. Ask for
/// them there.
/// </summary>
public static class SvermProgression
{
public struct SvermRules
{
/// <summary>Extra fraction of blunt damage taken. 0.40 means a mace hits for 140%.</summary>
public float BluntWeakness;
/// <summary>
/// Extra fraction of fire damage taken, NEGATIVE once Annealed Chitin inverts it at
/// Fader. One number for both halves of the arc, because it is one arc.
/// </summary>
public float FireWeakness;
/// <summary>Fraction of the Chitin Claws' quality-4 damage a bare-handed blow lands for.</summary>
public float ClawDamagePercent;
public bool MetabolicSurge; // cheaper running and jumping, higher jump
public float CarryWeightBonus; // Ventral Pouches
public bool SeedsEdible; // Grinding Mandibles
public bool SensoryAntennae; // creature sense through terrain
public float VenomOnHit; // Venom Glands: poison added to every blow
public float AcidHemolymph; // poison dealt back to a melee attacker
/// <summary>-1 is "no fall damage at all", matching FenrirProgression's convention.</summary>
public float FallDamageModifier;
/// <summary>How tall the dorsal spines stand, in metres. 0 before they grow.</summary>
public float SpineSize;
public bool StingerMorph; // the Deathsquito form is unlocked
public float BodyScale; // Surrenal Glands
public float CarapaceRegenPerSecond;
public bool Emberform; // black chitin, red burn, burning claws
}
// GetRules runs from Update loops and from damage patches, so the per-state result is
// built once and handed back on every later call.
private static readonly SvermRules[] cache = new SvermRules[BossProgressionManager.MaxState + 1];
private static readonly bool[] cached = new bool[BossProgressionManager.MaxState + 1];
public static SvermRules GetRules(int state)
{
state = Mathf.Clamp(state, BossProgressionManager.MinState, BossProgressionManager.MaxState);
if (cached[state]) return cache[state];
bool annealed = state >= SvermConfig.AnnealedChitinState;
SvermRules rules = new SvermRules
{
BluntWeakness = SvermConfig.BluntWeakness,
// The whole point of the race's arc: the defect that defined it for seven tiers is
// burned out by the last boss and comes back as a resistance.
FireWeakness = annealed
? -SvermConfig.FireResistanceAtFader
: SvermConfig.FireWeakness,
ClawDamagePercent = SvermConfig.ClawDamagePercentByState[state],
MetabolicSurge = state >= SvermConfig.MetabolicSurgeState,
CarryWeightBonus = state >= SvermConfig.VentralPouchesState ? SvermConfig.CarryWeightBonus : 0f,
SeedsEdible = state >= SvermConfig.SeedsEdibleState,
SensoryAntennae = state >= SvermConfig.SensoryAntennaeState,
VenomOnHit = state >= SvermConfig.VenomGlandsState
? SvermConfig.VenomPerState * (state - SvermConfig.VenomGlandsState + 1)
: 0f,
AcidHemolymph = state >= SvermConfig.AcidHemolymphState
? SvermConfig.HemolymphPerState * (state - SvermConfig.AcidHemolymphState + 1)
: 0f,
FallDamageModifier = state >= SvermConfig.VestigialWingsState ? -1f : 0f,
SpineSize = state >= SvermConfig.FullWingspanState ? SvermConfig.SpineSizeFull
: state >= SvermConfig.VestigialWingsState ? SvermConfig.SpineSizeSmall
: 0f,
StingerMorph = state >= SvermConfig.StingerMorphState,
BodyScale = state >= SvermConfig.SurrenalGlandsState ? SvermConfig.BodyScaleAtQueen : 1f,
CarapaceRegenPerSecond = state >= SvermConfig.CarapaceRegenState
? SvermConfig.CarapaceRegenPerSecond
: 0f,
Emberform = annealed,
};
cache[state] = rules;
cached[state] = true;
return rules;
}
/// <summary>Rules for whatever tier the local player is currently on.</summary>
public static SvermRules Current => GetRules(BossProgressionManager.GetCurrentProgressionState());
}
}