warvulture

This commit is contained in:
Ferdinando 2026-08-21 11:22:52 +02:00
commit 4b95e705e7
9 changed files with 418 additions and 12 deletions

View file

@ -1,7 +1,7 @@
{
"name": "RacesOfValheim",
"description": "A Valheim mod that adds nine custom playable races (Aswid, Draugh, Dvergar, Fenrir, Furling, Skadi, Skeleton, Trenta, Trol) each with unique abilities, traits, and a deep boss-driven progression system.",
"version_number": "1.4.0",
"description": "A Valheim mod that adds ten custom playable races (Aswid, Draugh, Dvergar, Fenrir, Furling, Skadi, Skeleton, Sverm, Trenta, Trol) each with unique abilities, traits, race stations and a deep boss-driven progression system.",
"version_number": "1.4.6",
"website_url": "",
"dependencies": [
"denikson-BepInExPack_Valheim-5.4.2333",

View file

@ -280,12 +280,18 @@ namespace RacesOfValheim
Refresh();
});
AddButton("ResetBtn", "Reset Race", new Vector2(0, -110), new Color(0.5f, 0.25f, 0.2f, 1f), () =>
AddButton("ResetRaceBtn", "Reset Race", new Vector2(-170, -110), new Color(0.5f, 0.25f, 0.2f, 1f), () =>
{
Close();
RacesOfValheim.ResetRace();
});
AddButton("ResetProgressionBtn", "Reset Progression", new Vector2(170, -110), new Color(0.5f, 0.4f, 0.2f, 1f), () =>
{
RacesOfValheim.ResetProgression();
Refresh();
});
AddButton("CloseBtn", "Close", new Vector2(0, -200), new Color(0.3f, 0.3f, 0.3f, 1f), Close);
GUIManager.BlockInput(true);

View file

@ -15,7 +15,7 @@ namespace RacesOfValheim
{
public const string PluginGUID = "com.nandor.racesofvalheim";
public const string PluginName = "Races Of Valheim";
public const string PluginVersion = "1.4.5";
public const string PluginVersion = "1.4.6";
private readonly Harmony harmony = new Harmony(PluginGUID);
@ -123,6 +123,25 @@ namespace RacesOfValheim
}
}
/// <summary>
/// Clears the boss-progression override and falls back to the natural world state.
/// Shared by the resetprogression console command and the Race Menu Ward.
/// </summary>
public static int ResetProgression()
{
BossProgressionManager.DebugState = -1;
int state = BossProgressionManager.GetCurrentProgressionState();
Player player = Player.m_localPlayer;
if (player != null)
{
player.Message(MessageHud.MessageType.Center, $"Progression reset to: {state}");
Traverse.Create(player).Method("SetupEquipment").GetValue();
}
return state;
}
/// <summary>
/// Strips whatever body-part weapon the outgoing race grew. The Aswid/Fenrir claws
/// (RaceClawSet) and the Sverm's Chitin Claws (SvermClawSlot) are quest items a player can
@ -1238,14 +1257,8 @@ namespace RacesOfValheim
public override void Run(string[] args)
{
BossProgressionManager.DebugState = -1;
int state = BossProgressionManager.GetCurrentProgressionState();
int state = RacesOfValheim.ResetProgression();
Console.instance.Print($"[DEBUG] Progression state reset to natural world state: {state}");
if (Player.m_localPlayer != null)
{
Player.m_localPlayer.Message(MessageHud.MessageType.Center, $"Progression reset to: {state}");
Traverse.Create(Player.m_localPlayer).Method("SetupEquipment").GetValue();
}
}
}
}

View file

@ -461,6 +461,7 @@ namespace RacesOfValheim
if (__instance != Player.m_localPlayer) return;
TrentaComposter.EnsureKnown(__instance);
TrentaHeartwoodGrove.EnsureKnown(__instance);
TrentaElderRoot.EnsureKnown(__instance);
FurlingCrops.EnsureKnown(__instance);
}
}

View file

@ -444,6 +444,65 @@ namespace RacesOfValheim
public static readonly Color RotSeedTint = new Color(0.16f, 0.12f, 0.08f, 1f);
// ─── Root of the Elder (item progression, defensive) ──────────────────
// Race-locked, hammer-only, permanent: a piece that heals itself and, once a minute, heals
// every player-built thing within reach of it too. Full design in Trenta_ElderRoot.txt.
//
// No crafting station, same reasoning as the Composter/Grove chain's own station-free entry
// point would need if it had one: this is a race identity piece, not a purchase from
// someone else's bench (see the War Totem's own note on the same choice).
public const string ElderRootPieceName = "TrentaElderRoot";
public const string ElderRootDisplayName = "Root of the Elder";
public const int ElderRootUnlockState = 3; // The Elder dead
public const string ElderRootRecipeGuck = "Guck";
public const int ElderRootRecipeGuckAmount = 5;
public const string ElderRootRecipeFineWood = "FineWood";
public const int ElderRootRecipeFineWoodAmount = 10;
// Source of the borrowed model - swamp scenery, already safe to strip under ModelBorrow's
// rules (no MonoBehaviour worth stripping in the first place, unlike a living prefab).
// THE ELDER'S SUMMONED ROOT - the thing that claws its way out of the ground and attacks
// whoever comes near during the boss fight. Verified by its path in manifest_extended:
// Assets/Characters/Greydwarf_king/TentaRoot
// "Assets/Characters/..." means CREATURE (the same path convention Trol_WarTotem.txt sez.
// 2.1 wrote down after the GoblinTotem item/piece mix-up), and "Greydwarf_king" is The
// Elder. Its whole kit sits in the same folder - misc/spawn_roots (the emergence),
// misc/tentaroot_attack, animation/tentaroot, fx_tentaroot_death, sfx_tentaroot_attack.
// The Mistlands Staff of Green Roots summons the same creature (staff_greenroots_tentaroot),
// which is the second confirmation that this is a summon and not decoration.
//
// TWO WRONG PICKS BEFORE THIS ONE, both found by searching the manifest for a word instead
// of asking what the boss actually spawns:
// "Vines" - unrelated swamp scenery, inert.
// "gdking_root_projectile" - the spike the Elder SHOOTS. A projectile/vfx, not the
// summon. Still correctly used further down for Muspell's
// ranged attack, which is what it really is.
//
// BORROWING FROM THIS IS NOT LIKE BORROWING SCENERY: it carries a Character, and
// ModelBorrow strips in a single pass, which is the exact shape of the bug that once broke
// the hammer for every piece in the game. TrentaElderRoot.ResolveModelSource walks to the
// "Visual" child first - the same thing FenrirRace and SkadiRace do for their forms - so
// no Character is ever handed to ModelBorrow.
public const string ElderRootModelSourcePrefab = "TentaRoot";
/// <summary>Child of a creature prefab that holds only mesh and animator, no Character.</summary>
public const string CreatureVisualChildName = "Visual";
// Height in metres of the borrowed model's largest dimension. NOT a guess any more: the
// mesh measures (0.48, 4.51, 0.47) at native size - a tall, thin root - and the first two
// tries in game (1.2 then 1.6) both came out about 70% too short. 2.7 m is roughly 60% of
// the creature's own height and stands a good head above the player.
public const float ElderRootModelSize = 2.7f;
// Forward to TrentaConfigManagement (BepInEx ConfigEntry) - see that class.
public static float ElderRootHealth => TrentaConfigManagement.ElderRootHealth.Value;
public static float ElderRootSelfHealDelay => TrentaConfigManagement.ElderRootSelfHealDelay.Value;
public static float ElderRootSelfHealPercentPerSecond => TrentaConfigManagement.ElderRootSelfHealPercentPerSecond.Value;
public static float ElderRootRepairRadius => TrentaConfigManagement.ElderRootRepairRadius.Value;
public static float ElderRootRepairInterval => TrentaConfigManagement.ElderRootRepairInterval.Value;
// ─── Heartwood Grove (item progression, tier 2) ──────────────────────
// Plant a seed, wait, and the tree that comes up fertilises what surrounds it, stings what
// approaches it, and fills a chest with honey. Three independent functions on one piece.

View file

@ -50,6 +50,13 @@ namespace RacesOfValheim
public static ConfigEntry<float> LastStandMaxArmorBonus;
public static ConfigEntry<float> ThornsReflectPercent;
// ─── Root of the Elder (tier 3+, defensive piece) ─────────────────────
public static ConfigEntry<float> ElderRootHealth;
public static ConfigEntry<float> ElderRootSelfHealDelay;
public static ConfigEntry<float> ElderRootSelfHealPercentPerSecond;
public static ConfigEntry<float> ElderRootRepairRadius;
public static ConfigEntry<float> ElderRootRepairInterval;
// ─── Homecoming Portal (tier 6+) ──────────────────────────────────────
public static ConfigEntry<float> PortalCooldown;
public static ConfigEntry<float> PortalLifetime;
@ -113,6 +120,18 @@ namespace RacesOfValheim
ThornsReflectPercent = config.Bind(lastStand, "Thorns Reflect Percent", 0.2f,
new ConfigDescription("Fraction of every hit taken reflected back at the attacker, tier 5+.", new AcceptableValueRange<float>(0f, 1f)));
const string elderRoot = "Trenta - Root of the Elder";
ElderRootHealth = config.Bind(elderRoot, "Health", 300f,
new ConfigDescription("Max structural health of the piece itself.", new AcceptableValueRange<float>(50f, 2000f)));
ElderRootSelfHealDelay = config.Bind(elderRoot, "Self-Heal Delay", 10f,
new ConfigDescription("Seconds without taking a hit before the piece starts healing itself.", new AcceptableValueRange<float>(0f, 60f)));
ElderRootSelfHealPercentPerSecond = config.Bind(elderRoot, "Self-Heal Percent Per Second", 0.02f,
new ConfigDescription("Fraction of max health regained per second once healing starts.", new AcceptableValueRange<float>(0f, 1f)));
ElderRootRepairRadius = config.Bind(elderRoot, "Repair Radius", 5f,
new ConfigDescription("Meters from the piece within which every player-built thing gets repaired.", new AcceptableValueRange<float>(1f, 30f)));
ElderRootRepairInterval = config.Bind(elderRoot, "Repair Interval", 60f,
new ConfigDescription("Seconds between repair pulses.", new AcceptableValueRange<float>(5f, 600f)));
const string portal = "Trenta - Homecoming Portal";
PortalCooldown = config.Bind(portal, "Cooldown", 300f,
new ConfigDescription("Seconds between casts, tier 6+.", new AcceptableValueRange<float>(0f, 3600f)));

View file

@ -0,0 +1,306 @@
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using UnityEngine;
namespace RacesOfValheim
{
/// <summary>
/// The Trenta's defensive piece: a gnarled root left over from the Elder, permanent once
/// planted, that heals itself and, once a minute, heals everything a player built within reach
/// of it too.
///
/// Full design in Trenta_ElderRoot.txt. Two facts from that document matter for reading this
/// file:
///
/// - WearNTear.Repair() and WearNTear.ApplyDamage(float, HitData) are both read from IL, not
/// guessed. Repair() is the same full-heal-and-broadcast the hammer itself uses.
/// ApplyDamage subtracts its float argument from current health and broadcasts the result -
/// a NEGATIVE amount heals, which is how the self-heal below works without a second RPC.
/// - Piece.IsPlacedByPlayer() is the filter, copied from Sverm/SvermWorker.cs (the mod's own
/// precedent for "heal player buildings in a radius"). Without it this piece would also try
/// to mend ruins, troll-cave walls and any other scenery that happens to carry a WearNTear.
///
/// The clone base and the strip pattern are TrolTotem's, unchanged: piece_workbench is a real
/// Piece (unlike the item-prefab trap that piece's own file documents), stripped to
/// Piece/ZNetView/WearNTear and given a borrowed look instead of the bench's own mesh.
/// </summary>
public static class TrentaElderRoot
{
public static void Register()
{
GameObject prefab = PrefabManager.Instance.CreateClonedPrefab(
TrentaConfig.ElderRootPieceName, "piece_workbench");
if (prefab == null)
{
Jotunn.Logger.LogWarning("[Trenta] Could not clone piece_workbench; the Root of the Elder is not registered.");
return;
}
// Strip the workbench down to a placeable shell: no station, no crafting, no furniture.
// The look comes from the borrowed Vines model below.
foreach (MonoBehaviour behaviour in prefab.GetComponentsInChildren<MonoBehaviour>(true))
{
if (behaviour == null) continue;
if (behaviour is Piece || behaviour is ZNetView || behaviour is WearNTear) continue;
Object.DestroyImmediate(behaviour);
}
foreach (Renderer renderer in prefab.GetComponentsInChildren<Renderer>(true))
{
if (renderer != null) renderer.enabled = false; // the bench's own mesh, hidden
}
AswidBloodRefinery.StripOffensive(prefab, TrentaConfig.ElderRootPieceName);
GameObject modelSource = ResolveModelSource();
if (modelSource != null)
{
ModelBorrow.Attach(prefab.transform, "RootModel", modelSource,
Vector3.zero, Quaternion.identity, TrentaConfig.ElderRootModelSize, "Trenta");
}
// Belt as well as braces, exactly as SvermHive.Register does after its own guard: even
// though ResolveModelSource never hands a Character to ModelBorrow, anything that could
// still act alive comes off the finished piece. This is the line that keeps the
// hammer-breaking failure (see ResolveModelSource) impossible rather than merely
// unlikely.
SvermHive.StripLife(prefab);
WearNTear wear = prefab.GetComponent<WearNTear>();
if (wear != null)
{
wear.m_health = TrentaConfig.ElderRootHealth;
wear.m_materialType = WearNTear.MaterialType.Wood;
}
prefab.AddComponent<TrentaElderRootBehaviour>();
Sprite icon = BorrowIcon(TrentaConfig.ElderRootRecipeGuck);
Piece piece = prefab.GetComponent<Piece>() ?? prefab.AddComponent<Piece>();
piece.m_craftingStation = null;
piece.m_resources = new Piece.Requirement[0];
piece.m_name = TrentaConfig.ElderRootDisplayName;
piece.m_canBeRemoved = true;
piece.m_groundPiece = true;
piece.m_groundOnly = true;
piece.m_icon = icon;
Piece template = PrefabManager.Cache.GetPrefab<Piece>("piece_workbench");
if (template != null && template.m_placeEffect != null) piece.m_placeEffect = template.m_placeEffect;
PieceManager.Instance.AddPiece(new CustomPiece(prefab, fixReference: false, new PieceConfig
{
Name = TrentaConfig.ElderRootDisplayName,
Description = "What the Elder left behind, still growing. Mends itself, and " +
"everything a player built close enough to it.",
PieceTable = PieceTables.Hammer,
Category = PieceCategories.Crafting,
Icon = icon,
Requirements = new[]
{
new RequirementConfig(TrentaConfig.ElderRootRecipeGuck, TrentaConfig.ElderRootRecipeGuckAmount, 0, true),
new RequirementConfig(TrentaConfig.ElderRootRecipeFineWood, TrentaConfig.ElderRootRecipeFineWoodAmount, 0, true),
}
}));
Jotunn.Logger.LogInfo($"[Trenta] Registered '{TrentaConfig.ElderRootPieceName}' " +
$"({TrentaConfig.ElderRootDisplayName}) on the hammer's Crafting page.");
}
/// <summary>
/// The model to borrow, with the creature carefully left behind.
///
/// TentaRoot is a CHARACTER (verified by its manifest path, Assets/Characters/...), and
/// handing a Character to ModelBorrow is the precise bug that once stopped the hammer
/// working for every piece in the game: ModelBorrow strips in ONE pass over
/// GetComponentsInChildren&lt;MonoBehaviour&gt;, and Unity refuses to destroy a component
/// another one still requires - "Can't remove Humanoid because CharacterDrop depends on
/// it". The Humanoid survives, every placement ghost wakes one, and
/// Character.GetCharactersInRange throws inside Player.UpdatePlacementGhost.
///
/// So the creature is never borrowed from directly. Its "Visual" child is - the node that
/// holds mesh and animator and nothing alive - which is the same route FenrirRace and
/// SkadiRace already take for every one of their transformations. If that child is missing
/// the answer is to attach nothing and say so, NOT to fall back to the creature: an
/// invisible piece is a cosmetic bug, a live Humanoid on a building is a broken hammer.
/// </summary>
private static GameObject ResolveModelSource()
{
string sourceName = TrentaConfig.ElderRootModelSourcePrefab;
GameObject source = PrefabManager.Cache.GetPrefab<GameObject>(sourceName);
if (source == null)
{
Jotunn.Logger.LogWarning($"[Trenta] No '{sourceName}' to borrow the Root's model from; " +
"the piece is registered without a model.");
return null;
}
Transform visual = source.transform.Find(TrentaConfig.CreatureVisualChildName);
if (visual != null)
{
Jotunn.Logger.LogInfo($"[Trenta] Root model taken from '{sourceName}/" +
$"{TrentaConfig.CreatureVisualChildName}' - the creature itself is left alone.");
return visual.gameObject;
}
// No Visual child. If the prefab is harmless scenery after all we can still use it;
// if it is alive we refuse, loudly, and the piece comes up invisible.
if (SvermHive.IsSafeScenery(source, sourceName))
{
Jotunn.Logger.LogInfo($"[Trenta] '{sourceName}' has no '{TrentaConfig.CreatureVisualChildName}' " +
"child but carries nothing alive; borrowing from it whole.");
return source;
}
Jotunn.Logger.LogWarning($"[Trenta] '{sourceName}' is alive and has no " +
$"'{TrentaConfig.CreatureVisualChildName}' child to borrow safely. " +
"The Root is registered WITHOUT a model rather than risking a live " +
"Character on a building - run `dumpelder " + sourceName + "` in the " +
"console to see its real hierarchy and name the right child here.");
return null;
}
private static Sprite BorrowIcon(string prefabName)
{
ItemDrop drop = PrefabManager.Cache.GetPrefab<ItemDrop>(prefabName);
Sprite[] icons = drop != null && drop.m_itemData != null && drop.m_itemData.m_shared != null
? drop.m_itemData.m_shared.m_icons
: null;
return icons != null && icons.Length > 0 ? icons[0] : null;
}
/// <summary>
/// Teaches the piece to the local player. Every dynamically cloned hammer piece in this mod
/// needs this - see the shared OnSpawned postfix in TrentaComposter.cs, which now calls this
/// too.
/// </summary>
public static void EnsureKnown(Player player)
{
if (player == null) return;
GameObject prefab = PrefabManager.Instance.GetPrefab(TrentaConfig.ElderRootPieceName);
Piece piece = prefab != null ? prefab.GetComponent<Piece>() : null;
if (piece == null) return;
Traverse traverse = Traverse.Create(player);
traverse.Method("AddKnownPiece", piece).GetValue();
traverse.Method("UpdateAvailablePiecesList").GetValue();
}
}
/// <summary>
/// Lives on the placed piece. Two independent jobs, both on the same tick cadence rules as the
/// rest of the mod: no coroutine, just Time.time comparisons in Update.
/// </summary>
public class TrentaElderRootBehaviour : MonoBehaviour
{
private WearNTear m_wear;
private float m_lastHitTime = -9999f;
private float m_nextRepairTick;
private void Start()
{
m_wear = GetComponent<WearNTear>();
if (m_wear != null) m_wear.m_onDamaged += OnHit;
m_nextRepairTick = Time.time + TrentaConfig.ElderRootRepairInterval;
}
private void OnDestroy()
{
if (m_wear != null) m_wear.m_onDamaged -= OnHit;
}
private void OnHit()
{
m_lastHitTime = Time.time;
}
private void Update()
{
TickSelfHeal();
if (Time.time >= m_nextRepairTick)
{
m_nextRepairTick = Time.time + TrentaConfig.ElderRootRepairInterval;
RunRepairPulse();
}
}
/// <summary>
/// The piece's own regeneration: unhurt for a while, then a fraction of max health back
/// every second. Cannot reuse SkeletonSentryBehaviour - that class heals a Character, and
/// this is a WearNTear, exactly the distinction SkeletonSentry.cs's own header explains for
/// why the Bound Sentry is cloned from a live creature rather than built as a piece.
///
/// ApplyDamage(float, HitData) has no built-in cap against m_health (read from its IL), so
/// the clamp against the remaining gap happens here, not inside the engine call.
/// </summary>
private void TickSelfHeal()
{
if (m_wear == null) return;
ZNetView nview = m_wear.GetComponent<ZNetView>();
if (nview == null || !nview.IsValid() || !nview.IsOwner()) return;
if (Time.time - m_lastHitTime < TrentaConfig.ElderRootSelfHealDelay) return;
float current = nview.GetZDO().GetFloat(ZDOVars.s_health, m_wear.m_health);
if (current >= m_wear.m_health) return;
float healThisFrame = TrentaConfig.ElderRootSelfHealPercentPerSecond * m_wear.m_health * Time.deltaTime;
healThisFrame = Mathf.Min(healThisFrame, m_wear.m_health - current);
if (healThisFrame > 0f) m_wear.ApplyDamage(-healThisFrame, null);
}
/// <summary>
/// Everything in range, in one pass - deliberately not the one-piece-per-tick pacing
/// Sverm/SvermWorker.cs uses for the same kind of aura. Kept different on purpose; see
/// Trenta_ElderRoot.txt sez. 4.2 before "fixing" this to match that precedent.
/// </summary>
private void RunRepairPulse()
{
foreach (Collider collider in Physics.OverlapSphere(transform.position, TrentaConfig.ElderRootRepairRadius))
{
if (collider == null) continue;
WearNTear otherWear = collider.GetComponentInParent<WearNTear>();
if (otherWear == null || otherWear == m_wear) continue;
Piece piece = otherWear.GetComponent<Piece>();
if (piece == null || !piece.IsPlacedByPlayer()) continue;
otherWear.Repair();
}
}
}
/// <summary>
/// Race lock plus the boss gate, in one prefix - same shape as TrolTotemRaceLockPatch, with a
/// second refusal added for the progression check the Root also needs.
/// </summary>
[HarmonyPatch(typeof(Player), "PlacePiece",
new[] { typeof(Piece), typeof(Vector3), typeof(Quaternion), typeof(bool) })]
public static class TrentaElderRootPlacementPatch
{
public static bool Prefix(Player __instance, Piece __0)
{
if (__instance != Player.m_localPlayer || __0 == null) return true;
if (Utils.GetPrefabName(__0.gameObject) != TrentaConfig.ElderRootPieceName) return true;
if (!TrentaRace.IsTrenta())
{
__instance.Message(MessageHud.MessageType.Center, "The root will not take hold for you.");
return false;
}
if (BossProgressionManager.GetCurrentProgressionState() < TrentaConfig.ElderRootUnlockState)
{
__instance.Message(MessageHud.MessageType.Center, "The Elder has not fallen yet.");
return false;
}
return true;
}
}
}

View file

@ -34,6 +34,7 @@ namespace RacesOfValheim
// before that catalogue is read.
TrentaComposter.Register();
TrentaHeartwoodGrove.Register();
TrentaElderRoot.Register();
}
/// <summary>