RacesOfValheim/JotunnModStub/Trenta/TrentaConfig.cs
Ferdinando d0ed92c553 feat(trenta): add the Trenta race
A vegan, tree-born race unlocking new perks per boss defeated: skin/hair
tint, blocked non-vegan food, awakened seed foods after Eikthyr, a mob
hostility list, Photosynthesis, elemental resistances, Purple Rain after
the Elder, swim/poison/wet immunity after Bonemass, Last Stand and Thorns
after Moder, a Homecoming Portal after Yagluth, Hornet's Nest after the
Queen, and Muspell (a half-size Elder transformation with Stomp/Spike
attacks) after Fader.

Also fixes RaceScale never listing Trenta as self-sizing, which let a
shared Player.Update postfix fight Muspell's own scale changes every
frame.
2026-08-04 20:58:01 +02:00

378 lines
25 KiB
C#

using System.Collections.Generic;
using UnityEngine;
namespace RacesOfValheim
{
/// <summary>
/// Every tunable number the Trenta uses, in one place.
///
/// Same arrangement as DvergarConfig: TrentaProgression reads these to build its per-tier
/// rules and the patches read the rules, never a literal. Retuning the race means editing
/// this file only.
///
/// Nothing here is final - the values are placeholders so the race compiles and runs while
/// the design is still open.
/// </summary>
public static class TrentaConfig
{
// ─── Identity ────────────────────────────────────────────────────────
// Anagram of "Treant": the Trenta are the tree-born.
//
// This is the value stored in m_customData["Race"] and in the ZDO, so renaming it after
// players have chosen the race would orphan their characters. Decide it now.
public const string RaceId = "Trenta";
public const string StatsSE = "SE_TrentaStats";
// Mirrors the ZDO key layout the other races use, so remote clients can read the tier
// without having the local player's progression state.
public const string StateZdoKey = "RacesOfValheim_TrentaState";
// Title of the compendium entry, once RaceCompendium learns about the race.
public const string CompendiumTitle = "Trenta Secrets";
// ─── Model ───────────────────────────────────────────────────────────
// Applied to the player's "Visual" child rather than the root transform, the way Furling
// and Dvergar do it: scaling the root would drag the collider and camera pivot along.
//
// Tuning knobs are static readonly rather than const throughout: a const folds at compile
// time, which turns "is this perk switched off?" guards into dead code the moment a knob
// is set to zero.
public static readonly float VisualScale = 1f; // TODO: taller than a human?
// ─── Skin ────────────────────────────────────────────────────────────
// Written straight onto the body material's _SkinColor by an UpdateColors postfix, which
// is the only thing that actually tints a player.
//
// This is a multiplier over the human skin texture, not a replacement, so a value near
// (1,1,1) changes nothing anyone can see. Every race that reads clearly commits to a
// channel - Trol (0.1, 0.6, 0.7), Furling (0.3, 0.8, 0.3) - so the Trenta does too:
// the pale green of a young leaf for skin, dark foliage green for hair and beard.
public static readonly Color SkinColor = new Color(0.55f, 0.85f, 0.35f, 1f);
public static readonly Color HairColor = new Color(0.06f, 0.28f, 0.08f, 1f);
// ─── Progression tables ──────────────────────────────────────────────
// Indexed by progression state; index 0 is unused so the state number indexes directly.
// 1 Base, 2 Eikthyr, 3 The Elder, 4 Bonemass, 5 Moder, 6 Yagluth, 7 The Queen, 8 Fader.
public static readonly float[] HealthBonusByState =
{
0f, // (unused)
0f, // 1 Base TODO
0f, // 2 Eikthyr TODO
0f, // 3 The Elder TODO
0f, // 4 Bonemass TODO
0f, // 5 Moder TODO
0f, // 6 Yagluth TODO
0f, // 7 The Queen TODO
0f // 8 Fader TODO
};
// ─── Photosynthesis ──────────────────────────────────────────────────
// Base passive, live from state 1: stand motionless in daylight, out from under a roof,
// and the Trenta puts down roots. TrentaAbilities.TickPhotosynthesis reads every number
// below; nothing is hard-coded in the patch itself.
public const float PhotosynthesisStillnessSeconds = 10f; // channel time before it fires
public const int PhotosynthesisHealSeconds = 8; // number of 1-second heal ticks
public const float PhotosynthesisHealPercentPerSecond = 0.10f; // % of max health per tick
public const float PhotosynthesisRestBaseMinutes = 5f; // Rested duration at Base
public const float PhotosynthesisRestMinutesPerBoss = 1f; // + this, per boss defeated
// Character.GetVelocity() never reads exactly zero even standing still - a bit of
// physics jitter is normal. Below this, the Trenta counts as motionless.
public const float PhotosynthesisVelocityEpsilon = 0.01f;
// ─── Purple Rain (The Elder) ─────────────────────────────────────────
// A spray of toxic-purple pollen: heals everything the Trenta doesn't fight, poisons
// everything that fights the Trenta. "Ally" is deliberately not a hardcoded species list -
// TrentaAbilities checks the same BaseAI.IsEnemy the mod's own hostility rules use, so it
// lines up with RaceHostilityManager's Trenta block (Greyling/Greydwarf/Fuling/Troll/
// Leech/Deathsquito) and with every tamed companion and teammate, for free.
public const int PurpleRainUnlockState = 3; // The Elder dead
public const KeyCode PurpleRainKey = KeyCode.G;
public const float PurpleRainCooldown = 20f;
public const float PurpleRainRadius = 8f; // TODO: tune
public const float PurpleRainHealAmount = 40f; // TODO: tune - flat heal per ally hit
public const float PurpleRainPoisonDamage = 40f; // TODO: tune - a Poison-type hit; vanilla's
// own poison-on-hit handling takes over
// from there, same as SkeletonRace's fire
// aura just deals Fire damage and lets
// the burn status follow from that.
public const string PurpleRainCdSE = "SE_TrentaPurpleRainCooldown";
// Source of the spray particle system Purple Rain clones and retints. "Greydwarf_Shaman"
// is the same prefab name AswidRace's own raw-food mapping already keys off, so it is
// known-correct rather than guessed.
public const string PurpleRainVfxSourcePrefab = "Greydwarf_Shaman";
public static readonly Color PurpleRainVfxColor = new Color(0.55f, 0.1f, 0.85f, 1f); // toxic purple
// ─── Bonemass passives ───────────────────────────────────────────────
// Three flat unlocks, all live from the same boss kill: swimming costs no stamina, and
// Poison and Wet can no longer touch a Trenta. A body that runs on sunlight and rain
// rather than blood has nothing left for the swamp to spoil.
public const int BonemassDefeatedState = 4;
// ─── Moder passives ──────────────────────────────────────────────────
public const int ModerDefeatedState = 5;
// Last Stand: always-on armor bonus that scales with health already lost, so it does
// nothing at full health and its most at the edge of death. SE_TrentaStats.ModifyArmorMods
// reads this every time armor is computed - there is no timer or trigger to it.
public const float LastStandMaxArmorBonus = 0.5f; // +50% armor at ~0 health remaining
// Thorns: reflects this fraction of every hit taken back at whoever landed it.
// Trenta_Character_Damage_Thorns_Patch reads it fresh on every hit - no timer, no charge,
// no cooldown, it just always applies. Replaces Camouflage, which never worked reliably.
public const float ThornsReflectPercent = 0.2f;
// ─── Homecoming Portal (Yagluth) ─────────────────────────────────────
// Opens a linked pair of portals - one where the Trenta is standing, one at their
// respawn point - for everyone to walk through, no item-carry restriction, for 30
// seconds. The visual is deliberately just the swirl, not the vanilla wooden frame -
// "solo la componente VFX del portale normale" - and the teleport itself is entirely
// custom (TrentaPortal.cs), not a re-skinned vanilla TeleportWorld, which is exactly why
// it can skip the raw-ore restriction the real thing carries.
public const int PortalUnlockState = 6; // Yagluth dead
public const KeyCode PortalKey = KeyCode.H;
public const float PortalCooldown = 300f; // 5 minutes
public const float PortalLifetime = 30f;
public const float PortalSpawnDistance = 2f; // meters in front of the player, where it opens
// Source of the swirl visual the portal clones and retints. "portal_wood" is the
// confirmed internal ID of the vanilla portal piece (verified against a live source
// rather than guessed, the same standard as every other prefab name in this file).
public const string PortalVfxSourcePrefab = "portal_wood";
public static readonly Color PortalVfxColor = new Color(0.55f, 0.1f, 0.85f, 1f); // same toxic purple as Purple Rain
public const string PortalCdSE = "SE_TrentaPortalCooldown";
// ─── Hornet's Nest (The Queen) ───────────────────────────────────────
// A permanent, passive companion rather than a keybound ability: once the Queen is dead
// it simply exists, hovering on the Trenta, and stays until the state that granted it no
// longer holds. TrentaRace.Update ticks its lifecycle unconditionally (not gated behind
// the usual "still Trenta" early return) so it is torn down the instant a race change,
// a drop in tier or death would otherwise leave it orphaned with nothing left to update it.
public const int HornetsNestUnlockState = 7; // The Queen dead
// Matches the wild Bee Nest's own sting - 10 poison damage every 4 seconds - rather than
// an invented number, on the read that "as if constantly stung by bees" means using the
// real thing's own numbers. Not found as a tunable field on the Beehive class itself
// (probably scene data on the wild instance, not code), so this one rests on the wiki's
// account of live behaviour rather than the assembly's own IL the way most numbers in
// this file do - flag it if it reads as too strong or too weak once tried.
public const float HornetsNestDamagePerTick = 10f;
public const float HornetsNestTickInterval = 4f;
public const float HornetsNestEngageRadius = 6f; // TODO: tune - how close a foe has to get
public const float HornetsNestFollowSpeed = 8f; // TODO: tune
public const float HornetsNestOrbitRadius = 0.6f; // how tightly it hugs the Trenta at rest
public const float HornetsNestAttackHeight = 1.5f; // hovers this high over a target it is stinging - the "from above" for the pierce half of each tick
// The flies only, not the smoke or the drip, off the same "Draugr" prefab
// DraughRace.EnsureVFX already reads for its own aura - same source, same filtering rule,
// just discarding the two effects Draugh keeps instead of the one it discards.
public const string HornetsNestFliesSourcePrefab = "Draugr";
// Source of the buzz: the ambient bee-swarm effect a placed Beehive plays, read for its
// AudioClip only - never instantiated, so nothing about how it looks ever enters this
// ability, matching "la sua unica componente visiva sarà le mosche" literally.
public const string HornetsNestBeehivePrefab = "Beehive";
// ─── Muspell (Fader) ─────────────────────────────────────────────────
// A toggled transformation, the same shape as FenrirRace's own G/H/J forms: press J to
// become a half-size The Elder, press J again to revert. The permanent-fire half of the
// original design (Burning VFX + ignite-on-hit) was tried and dropped - the flame glitched
// with no reliable fix in reach, so it was removed rather than chased further.
// TrentaMuspell.cs mirrors FenrirRace.cs (transform/revert routines, ExecuteTransformation/
// ExecuteReversion) and FenrirBehaviors.cs (per-form Animator + mouse-button attack
// pattern) about as closely as two independent races' code can - both are read, not
// guessed, so the shape of this is trustworthy even where individual numbers below are not.
public const int MuspellUnlockState = 8; // Fader dead
public const KeyCode MuspellKey = KeyCode.J;
// "gd_king" is The Elder's own internal prefab name, confirmed against a live source
// (not guessed) the same way "portal_wood" and "Draugr" were.
public const string MuspellFormPrefab = "gd_king";
public const float MuspellScale = 0.5f;
// Stomp's damage/radius are still this mod's own numbers - TODO: replace with
// gd_king_stomp's own SharedData.m_damages once dumpelder reports it, the same way the
// trigger name below was replaced with a read value instead of a guess.
public const float MuspellStompDamage = 60f;
public const float MuspellStompRadius = 2.5f; // TODO: tune
// The ranged attack is a real Projectile (type=Projectile, range 8-24), not an instant
// cone hit - "gdking_root_projectile", The Elder's own vine/spike shot, spawned and set up
// exactly the way Attack.FireProjectileBurst does it (Instantiate, new HitData, IProjectile
// .Setup), for "identico" rather than an approximation.
public const string MuspellSpikeProjectilePrefab = "gdking_root_projectile";
public const float MuspellSpikeDamage = 35f; // TODO: replace with the projectile's own m_damage once dumpelder reports it
public const float MuspellSpikeVelocity = 20f; // TODO: tune - m_projectileVel isn't in this dump yet either
// Read straight off gd_king's own default weapons via the "dumpelder" console command
// (RacesOfValheim.DumpElderCommand) rather than guessed - confirmed by IL that
// Attack.m_attackAnimation feeds directly into ZSyncAnimation.SetTrigger, so these are the
// exact strings The Elder itself uses:
// gd_king_stomp (jaws) -> primary animation "stomp", m_attackRandomAnimations=2
// gd_king_shoot (shaman attack) -> primary animation "shoot", spawns gdking_root_projectile
// gd_king_rootspawn (spawn) -> primary animation "spawn"
// Stomp's randomAnimations=2 means the real trigger fired is "stomp0" or "stomp1", picked
// at random each swing, mirroring Attack.Start's own random-suffix branch.
public const string MuspellStompTrigger = "stomp";
public const int MuspellStompTriggerVariants = 2;
public const string MuspellSpikeTrigger = "shoot";
public const string MuspellRootSummonTrigger = "spawn";
// Purple Rain's own cooldown while Muspell is active - read by TryPurpleRain instead of
// PurpleRainCooldown whenever TrentaMuspell.IsTransformed is true.
public const float MuspellPurpleRainCooldown = 10f;
// ─── Diet ────────────────────────────────────────────────────────────
// The Trenta are strict vegans: no meat, fish, egg or honey, in any dish that contains
// even a trace of one. TrentaFoodPatches blocks eating anything whose prefab is not in
// this set - meads are untouched, since those never carry m_food/m_foodStamina/m_foodEitr
// and so never look like "food" to that check in the first place.
//
// Every entry here is the game's actual internal prefab ID (verified against the item's
// wiki infobox one at a time - the display name does not reliably predict it: Blueberries
// is "Blueberries" but Raspberries is "Raspberry", Magecap is "MushroomMagecap", Fiddlehead
// is "Fiddleheadfern"). Get one of these wrong and that food silently stops being
// recognised as vegan-safe rather than throwing, so this list must never be hand-guessed.
//
// Deliberately excludes every dish that touches Honey, Egg, Royal jelly or Volture egg
// (Cooked egg, Mushroom omelette, Frosted sweetbread, Yggdrasil porridge, Spicy marmalade,
// Roasted crust pie) even though none of those are meat - a vegan diet is "no animal
// product", not "no meat", and the player asked for the former.
public static readonly HashSet<string> VeganFoodPrefabNames = new HashSet<string>
{
// Meadows / Black Forest
"Raspberry", // Raspberries
"Mushroom", // Mushroom
"Blueberries", // Blueberries
"MushroomYellow", // Yellow mushroom
"Carrot", // Carrot
"QueensJam", // Queen's jam
"CarrotSoup", // Carrot soup
// Mountain
"Onion", // Onion
"OnionSoup", // Onion soup
// Plains
"Cloudberry", // Cloudberries
"Bread", // Bread
// Mistlands
"MushroomMagecap", // Magecap
"MushroomJotunPuffs", // Jotun puffs
"Salad", // Salad
// Ashlands
"MushroomSmokePuff", // Smoke puff
"Fiddleheadfern", // Fiddlehead
"Vineberry", // Vineberry cluster
"ScorchingMedley", // Scorching medley
"SizzlingBerryBroth", // Sizzling berry broth
"SparklingShroomshake", // Sparkling shroomshake
"MarinatedGreens" // Marinated greens
};
// Digestion runs twice as long for a Trenta eating any of the foods above.
public const float FoodDurationMultiplier = 2f;
// ─── Awakened seeds ──────────────────────────────────────────────────
// Once a Trenta has felled Eikthyr, every seed, cone, acorn and self-seeding mushroom in
// the game wakes up: eating the raw item on the spot consumes it and grants the strongest
// health/eitr dish its own biome has to offer (see the biome-pairing table worked out with
// the player - eitr food wins the tie-break wherever a biome has one, otherwise health
// wins by default). Before that boss falls the same click does nothing special - the seed
// just behaves like the ordinary planting material it already is.
//
// A handful of judgment calls, all defaults rather than answers pulled from the player:
// - Fir cone spans Black Forest/Swamp/Mountain and Birch seeds spans Meadows/Plains;
// each is given one fixed stat block drawn from the highest-tier biome it grows in
// (Mountain, Plains) rather than varying by where it happened to be picked up.
// - Flax has no seed-to-food entry: it produces fibre, never food, in vanilla, so there
// is nothing sensible to "awaken" it into.
// - Magecap and Jotun puffs are self-seeding (the raw item you plant is the same one you
// already eat raw at the base tier), so their entry represents an *upgrade* on the same
// item rather than turning an inedible material into a first meal.
public const int EikthyrDefeatedState = 2; // BossProgressionManager state 2 = Eikthyr dead
// Prefix shared by every generated awakened-food prefab, so patches can recognise one on
// sight (Trenta_Player_EatFood_DuplicateGuard_Patch) without re-deriving the raw-name map.
public const string AwakenedSeedPrefabPrefix = "TrentaAwakened_";
public struct AwakenedSeedFood
{
public string RawPrefabName; // the seed/cone/acorn/mushroom item this replaces on eating
public float Health;
public float Stamina;
public float Eitr;
public float Duration; // seconds
public float Healing; // hp/tick
public string AwakenedPrefabName => AwakenedSeedPrefabPrefix + RawPrefabName;
}
public static readonly AwakenedSeedFood[] AwakenedSeedFoods =
{
// Meadows - no eitr food in the biome, so health wins by default (Cooked deer meat).
new AwakenedSeedFood { RawPrefabName = "BeechSeeds", Health = 35, Stamina = 12, Eitr = 0, Duration = 1200, Healing = 2 },
new AwakenedSeedFood { RawPrefabName = "Acorn", Health = 35, Stamina = 12, Eitr = 0, Duration = 1200, Healing = 2 },
// Black Forest - no eitr food, health wins (Deer stew).
new AwakenedSeedFood { RawPrefabName = "CarrotSeeds", Health = 45, Stamina = 15, Eitr = 0, Duration = 1500, Healing = 3 },
new AwakenedSeedFood { RawPrefabName = "PineCone", Health = 45, Stamina = 15, Eitr = 0, Duration = 1500, Healing = 3 },
// Fir cone also grows in Swamp and Mountain; Mountain is its highest tier (Wolf skewer).
new AwakenedSeedFood { RawPrefabName = "FirCone", Health = 65, Stamina = 21, Eitr = 0, Duration = 1500, Healing = 3 },
// Swamp - no eitr food, health wins (Serpent stew).
new AwakenedSeedFood { RawPrefabName = "TurnipSeeds", Health = 80, Stamina = 26, Eitr = 0, Duration = 1800, Healing = 4 },
// Mountain - no eitr food, health wins (Wolf skewer).
new AwakenedSeedFood { RawPrefabName = "OnionSeeds", Health = 65, Stamina = 21, Eitr = 0, Duration = 1500, Healing = 3 },
// Plains - no eitr food, health wins (Lox meat pie). Birch seeds also grows in
// Meadows; Plains is its higher tier.
new AwakenedSeedFood { RawPrefabName = "Barley", Health = 75, Stamina = 24, Eitr = 0, Duration = 1800, Healing = 4 },
new AwakenedSeedFood { RawPrefabName = "BirchSeeds", Health = 75, Stamina = 24, Eitr = 0, Duration = 1800, Healing = 4 },
// Mistlands - Seeker aspic has the biome's highest eitr, so it wins the tie-break over
// Misthare supreme's higher health.
new AwakenedSeedFood { RawPrefabName = "MushroomMagecap", Health = 28, Stamina = 14, Eitr = 85, Duration = 1800, Healing = 3 },
new AwakenedSeedFood { RawPrefabName = "MushroomJotunPuffs", Health = 28, Stamina = 14, Eitr = 85, Duration = 1800, Healing = 3 },
// Ashlands - Marinated greens has the biome's highest eitr, wins the tie-break over
// Piquant pie's higher health.
new AwakenedSeedFood { RawPrefabName = "VineberrySeeds", Health = 32, Stamina = 16, Eitr = 95, Duration = 1800, Healing = 4 }
};
// Built once from the array above so the Humanoid.UseItem patch can look a clicked
// prefab up in O(1) instead of scanning the array on every item use.
public static readonly Dictionary<string, AwakenedSeedFood> AwakenedSeedFoodByRawPrefab = BuildAwakenedSeedFoodLookup();
private static Dictionary<string, AwakenedSeedFood> BuildAwakenedSeedFoodLookup()
{
var lookup = new Dictionary<string, AwakenedSeedFood>();
foreach (AwakenedSeedFood food in AwakenedSeedFoods)
{
lookup[food.RawPrefabName] = food;
}
return lookup;
}
// ─── Helpers ─────────────────────────────────────────────────────────
/// <summary>Clamped table lookup, so a state outside 1..8 can never index out of range.</summary>
public static float Lookup(float[] table, int state)
{
if (table == null || table.Length == 0) return 0f;
int index = Mathf.Clamp(state, BossProgressionManager.MinState, table.Length - 1);
return table[index];
}
}
}