Merge branch 'main' into race-chains-and-stations

# Conflicts:
#	JotunnModStub/Aswid/AswidRace.cs
#	JotunnModStub/Factions/FactionHostilityPatch.cs
#	JotunnModStub/Factions/FactionMerchantCatalog.cs
#	JotunnModStub/Furling/FurlingPatches.cs
This commit is contained in:
kanym 2026-08-07 17:15:10 +02:00
commit f60b8d8f7d
48 changed files with 1865 additions and 380 deletions

View file

@ -0,0 +1,76 @@
using BepInEx.Configuration;
namespace RacesOfValheim
{
/// <summary>
/// Every tunable number behind the Skeleton's abilities, bound as BepInEx ConfigEntry so they
/// show up in Configuration Manager without touching code - see
/// CONFIGURATION-MANAGER-HOWTO.md. Bound once, from RacesOfValheim.Awake(). One section per
/// topic (matches the other races' layout).
///
/// No keybinds section: every Skeleton ability is passive, triggered by tier and combat events
/// rather than a key press.
///
/// The per-tier progression table itself (SkeletonProgression.GetRules: max health bonus,
/// lifesteal percent per tier, max summons) is left as-is, same boundary drawn for every other
/// race's progression table - not exposed here. Only the flat ability numbers a tier's boolean
/// flag switches on are configurable.
///
/// One caveat: Enhanced Regen Health Multiplier is read into SE_SkeletonStats.RebuildForState,
/// which only re-reads it when the player's progression state changes (it short-circuits if
/// the state matches what it last built for). Retuning that one value mid-session at an
/// already-reached tier needs a relog (or reaching a new tier) to take effect. Everything else
/// here reads live on every use.
/// </summary>
public static class SkeletonConfig
{
// ─── Passive combat ──────────────────────────────────────────────────
public static ConfigEntry<float> AutoStunCooldown;
public static ConfigEntry<float> AutoStunStaggerMultiplier;
public static ConfigEntry<float> PoisonAttackBonus;
public static ConfigEntry<float> EnhancedRegenHealthMultiplier;
public static ConfigEntry<float> EnhancedRegenTickSpeedBonus;
// ─── Fire Aura (tier 5+) ───────────────────────────────────────────────
public static ConfigEntry<float> FireAuraRadius;
public static ConfigEntry<float> FireAuraDamagePerTick;
public static ConfigEntry<float> FireAuraTickInterval;
// ─── Resurrection (tier 6+) ────────────────────────────────────────────
public static ConfigEntry<float> ResurrectionCooldown;
// ─── Visuals ───────────────────────────────────────────────────────────
public static ConfigEntry<bool> HeadFireVFXEnabled;
public static void Bind(ConfigFile config)
{
const string combat = "Skeleton - Passive Combat";
AutoStunCooldown = config.Bind(combat, "Auto Stun Cooldown", 5f,
new ConfigDescription("Seconds between forced staggers on the enemy hit, tier 3+.", new AcceptableValueRange<float>(0f, 60f)));
AutoStunStaggerMultiplier = config.Bind(combat, "Auto Stun Stagger Multiplier", 100f,
new ConfigDescription("Stagger multiplier applied to force the stagger through.", new AcceptableValueRange<float>(1f, 500f)));
PoisonAttackBonus = config.Bind(combat, "Poison Attack Bonus", 20f,
new ConfigDescription("Flat poison damage added to every hit the player lands, tier 4+.", new AcceptableValueRange<float>(0f, 100f)));
EnhancedRegenHealthMultiplier = config.Bind(combat, "Enhanced Regen Health Multiplier", 1.5f,
new ConfigDescription("Health regeneration multiplier, tier 5+.", new AcceptableValueRange<float>(1f, 5f)));
EnhancedRegenTickSpeedBonus = config.Bind(combat, "Enhanced Regen Tick Speed Bonus", 0.25f,
new ConfigDescription("Extra speed at which the regen timer accumulates, tier 5+ (0.25 = 25% faster ticks).", new AcceptableValueRange<float>(0f, 2f)));
const string aura = "Skeleton - Fire Aura";
FireAuraRadius = config.Bind(aura, "Radius", 5f,
new ConfigDescription("Meters from the player that the tier 5+ aura damages.", new AcceptableValueRange<float>(1f, 20f)));
FireAuraDamagePerTick = config.Bind(aura, "Damage Per Tick", 30f,
new ConfigDescription("Fire damage dealt to every enemy in range, once per tick.", new AcceptableValueRange<float>(0f, 100f)));
FireAuraTickInterval = config.Bind(aura, "Tick Interval", 1f,
new ConfigDescription("Seconds between aura damage ticks.", new AcceptableValueRange<float>(0.1f, 5f)));
const string resurrection = "Skeleton - Resurrection";
ResurrectionCooldown = config.Bind(resurrection, "Cooldown", 300f,
new ConfigDescription("Seconds between auto-resurrections, tier 6+.", new AcceptableValueRange<float>(0f, 3600f)));
const string visuals = "Skeleton - Visuals";
HeadFireVFXEnabled = config.Bind(visuals, "Head Fire VFX Enabled", true,
new ConfigDescription("Whether the burning-skull effect (worn from tier 5+) renders at all. A client-side preference: disabling it stops you from seeing it on yourself and on every other skeleton you look at, but does not change what other players see."));
}
}
}

View file

@ -335,8 +335,8 @@ namespace RacesOfValheim
anim.cullingMode = AnimatorCullingMode.AlwaysAnimate;
}
HideItemInstances(__instance, "m_hairItemInstances");
HideItemInstances(__instance, "m_beardItemInstances");
HideItemInstances(__instance, "m_hairItemInstance");
HideItemInstances(__instance, "m_beardItemInstance");
SetHelmetVisible(__instance, false);
}
}
@ -359,8 +359,8 @@ namespace RacesOfValheim
}
}
ShowItemInstances(__instance, "m_hairItemInstances");
ShowItemInstances(__instance, "m_beardItemInstances");
ShowItemInstances(__instance, "m_hairItemInstance");
ShowItemInstances(__instance, "m_beardItemInstance");
SetHelmetVisible(__instance, true);
}
}
@ -375,70 +375,61 @@ namespace RacesOfValheim
/// first frame after a race change, all of which reach this postfix and none of which
/// reach SkeletonRace.
///
/// Scaled rather than deactivated, because Valheim re-enables the instance whenever it
/// refreshes visuals - the approach the Dvergar's hood already proved out.
/// Delegates to SkeletonVisuals.SetEquipmentPieceHidden, which scales the wrapper to
/// zero and disables its renderers - scale alone leaves a skinned piece (bound to the
/// player's own bones rather than its own transform) still drawing, which is what a
/// helmet with a skinned cloth or chain part looked like.
/// </summary>
private static void SetHelmetVisible(VisEquipment visEq, bool visible)
{
GameObject helmet = Traverse.Create(visEq).Field<GameObject>("m_helmetItemInstance").Value;
if (helmet == null) return;
Vector3 wanted = visible ? Vector3.one : Vector3.zero;
// Only ever undo our own hiding: another race may legitimately be scaling this.
if (!visible && helmet.transform.localScale != Vector3.zero)
{
helmet.transform.localScale = wanted;
}
else if (visible && helmet.transform.localScale == Vector3.zero)
{
helmet.transform.localScale = wanted;
}
SkeletonVisuals.SetEquipmentPieceHidden(helmet, !visible);
}
private static void HideItemInstances(VisEquipment visEq, string fieldName)
{
SetItemInstanceActive(visEq, fieldName, false);
}
private static void ShowItemInstances(VisEquipment visEq, string fieldName)
{
SetItemInstanceActive(visEq, fieldName, true);
}
/// <summary>
/// Hair and beard live in VisEquipment as a single GameObject (m_hairItemInstance /
/// m_beardItemInstance), the same as the helmet - not a list. A previous version of
/// this looked for "m_hairItemInstances" / "m_beardItemInstances" (plural), which do
/// not exist on VisEquipment, so the reflection lookup silently found nothing and the
/// beard never got the SetActive(false) this was supposed to give it. Handling both
/// shapes here matches the defensive pattern the Furling race already uses.
/// </summary>
private static void SetItemInstanceActive(VisEquipment visEq, string fieldName, bool active)
{
try
{
var field = typeof(VisEquipment).GetField(fieldName, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
if (field != null)
if (field == null) return;
object value = field.GetValue(visEq);
if (value is GameObject go)
{
var list = field.GetValue(visEq) as System.Collections.Generic.List<GameObject>;
if (list != null)
if (go != null) go.SetActive(active);
}
else if (value is System.Collections.Generic.List<GameObject> list)
{
foreach (GameObject item in list)
{
foreach (GameObject go in list)
{
if (go != null) go.SetActive(false);
}
if (item != null) item.SetActive(active);
}
}
}
catch (System.Exception e)
{
Jotunn.Logger.LogWarning($"Failed to hide {fieldName}: {e.Message}");
Jotunn.Logger.LogWarning($"Failed to set {fieldName} active={active}: {e.Message}");
}
}
private static void ShowItemInstances(VisEquipment visEq, string fieldName)
{
try
{
var field = typeof(VisEquipment).GetField(fieldName, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
if (field != null)
{
var list = field.GetValue(visEq) as System.Collections.Generic.List<GameObject>;
if (list != null)
{
foreach (GameObject go in list)
{
if (go != null) go.SetActive(true);
}
}
}
}
catch (System.Exception e) { }
}
// Bones worth reporting on. Not remapped - the player rig has a real 'Jaw' bone and the
// name match lands on it correctly, which is exactly why the plain and poison skeletons
// always looked right. An earlier attempt pinned this group to the head instead and
@ -605,16 +596,16 @@ namespace RacesOfValheim
if (attacker != null && attacker == Player.m_localPlayer && SkeletonRace.IsSkeleton())
{
// Auto Stun
if (rules.AutoStunFirstHit && Time.time - lastStunTime > 5f)
if (rules.AutoStunFirstHit && Time.time - lastStunTime > SkeletonConfig.AutoStunCooldown.Value)
{
hit.m_staggerMultiplier = 100f; // Force stagger
hit.m_staggerMultiplier = SkeletonConfig.AutoStunStaggerMultiplier.Value; // Force stagger
lastStunTime = Time.time;
}
// Poison Attacks
if (rules.PoisonAttacks)
{
hit.m_damage.m_poison += 20f; // Add flat 20 poison damage
hit.m_damage.m_poison += SkeletonConfig.PoisonAttackBonus.Value;
}
// Lifesteal

View file

@ -175,6 +175,87 @@ namespace RacesOfValheim
}
}
/// <summary>
/// F8 debug: fires a ray from the camera and logs whatever it hits. Cosmetic pieces
/// (hair, beard, helmet) carry no collider, so this mostly confirms terrain/creature hits
/// - LogHeadCosmeticsState below is what actually answers "what is that floating chunk."
/// Kept anyway because it is the general-purpose "what am I looking at" tool for any other
/// bone or prefab placement question that comes up later.
/// </summary>
private void LogRaycastHit()
{
Camera cam = Camera.main;
if (cam == null)
{
Jotunn.Logger.LogInfo("[F8] No camera found for raycast.");
return;
}
Ray ray = new Ray(cam.transform.position, cam.transform.forward);
if (Physics.Raycast(ray, out RaycastHit hit, 50f))
{
Jotunn.Logger.LogInfo("--- F8 RAYCAST HIT ---");
Jotunn.Logger.LogInfo($"Collider: '{hit.collider.gameObject.name}' at {hit.point:F2}, distance={hit.distance:F2}");
Jotunn.Logger.LogInfo($"Full path: {GetFullPath(hit.collider.transform)}");
Renderer renderer = hit.collider.GetComponentInParent<Renderer>();
if (renderer != null)
{
Jotunn.Logger.LogInfo($"Nearest renderer: '{renderer.gameObject.name}' ({renderer.GetType().Name}), enabled={renderer.enabled}, scale={renderer.transform.lossyScale:F3}");
}
Jotunn.Logger.LogInfo("----------------------");
}
else
{
Jotunn.Logger.LogInfo("[F8] Raycast hit nothing within 50m (cosmetic pieces usually have no collider anyway).");
}
}
private static string GetFullPath(Transform t)
{
string path = t.name;
for (Transform parent = t.parent; parent != null; parent = parent.parent)
{
path = parent.name + "/" + path;
}
return path;
}
/// <summary>
/// F8 debug: dumps the exact state of the three item slots this race hides (hair, beard,
/// helmet) - active flag, renderer enabled flag and scale for every renderer underneath.
/// This is the direct answer to "what is still visible and why": a chunk that survives
/// hiding will show up here as active=true, or as a renderer with enabled=true even while
/// its wrapper is scaled to zero (the skinned-mesh case scale alone cannot hide).
/// </summary>
private void LogHeadCosmeticsState()
{
if (Player.m_localPlayer == null) return;
VisEquipment vis = Player.m_localPlayer.GetComponent<VisEquipment>();
if (vis == null) return;
Jotunn.Logger.LogInfo("--- F8 SKELETON HEAD COSMETICS ---");
DumpItemInstanceField(vis, "m_hairItemInstance");
DumpItemInstanceField(vis, "m_beardItemInstance");
DumpItemInstanceField(vis, "m_helmetItemInstance");
Jotunn.Logger.LogInfo("----------------------------------");
}
private static void DumpItemInstanceField(VisEquipment vis, string fieldName)
{
GameObject go = HarmonyLib.Traverse.Create(vis).Field<GameObject>(fieldName).Value;
if (go == null)
{
Jotunn.Logger.LogInfo($"[F8] {fieldName}: null (nothing equipped/instantiated).");
return;
}
Jotunn.Logger.LogInfo($"[F8] {fieldName}: '{go.name}' active={go.activeSelf} scale={go.transform.localScale:F3}");
foreach (Renderer r in go.GetComponentsInChildren<Renderer>(true))
{
Jotunn.Logger.LogInfo($"[F8] renderer '{r.gameObject.name}' ({r.GetType().Name}) enabled={r.enabled}");
}
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.F8))
@ -185,6 +266,9 @@ namespace RacesOfValheim
DumpTransformHierarchy(Hud.instance.transform, "");
Jotunn.Logger.LogInfo("--------------------------");
}
LogRaycastHit();
LogHeadCosmeticsState();
}
if (Player.m_localPlayer == null) return;
@ -250,10 +334,7 @@ namespace RacesOfValheim
{
// Hide Helmets (Valheim uses singular GameObject for helmet)
var helmetObj = HarmonyLib.Traverse.Create(currentVis).Field<GameObject>("m_helmetItemInstance").Value;
if (helmetObj != null && helmetObj.transform.localScale != Vector3.zero)
{
helmetObj.transform.localScale = Vector3.zero;
}
SkeletonVisuals.SetEquipmentPieceHidden(helmetObj, true);
// Scale Body Armor (Chest, Legs, Shoulder) by 5%
string[] armorFields = { "m_chestItemInstances", "m_legItemInstances", "m_shoulderItemInstances" };
@ -355,18 +436,17 @@ namespace RacesOfValheim
// rate, which is the player's own field.
if (rules.EnhancedRegen)
{
// Speed up regen ticks by 20% (1.25x faster timer accumulation)
float currentTimer = HarmonyLib.Traverse.Create(Player.m_localPlayer).Field<float>("m_foodRegenTimer").Value;
HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_foodRegenTimer").SetValue(currentTimer + Time.deltaTime * 0.25f);
HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_foodRegenTimer").SetValue(currentTimer + Time.deltaTime * SkeletonConfig.EnhancedRegenTickSpeedBonus.Value);
}
// Flames on the skull, worn with the fire-tier model and nothing else.
headFlame.Apply(Player.m_localPlayer, rules.ModelPrefab == SkeletonProgression.FireModel);
headFlame.Apply(Player.m_localPlayer, SkeletonConfig.HeadFireVFXEnabled.Value && rules.ModelPrefab == SkeletonProgression.FireModel);
if (rules.FireAura)
{
EnsureFireAuraVFX(true);
if (Time.time - lastAuraTime >= 1f)
if (Time.time - lastAuraTime >= SkeletonConfig.FireAuraTickInterval.Value)
{
ApplyFireAura();
lastAuraTime = Time.time;
@ -475,10 +555,10 @@ namespace RacesOfValheim
if (Player.m_localPlayer == null) return;
Vector3 center = Player.m_localPlayer.transform.position;
float radius = 5f;
float radius = SkeletonConfig.FireAuraRadius.Value;
HitData hitData = new HitData();
hitData.m_damage.m_fire = 30f; // 30 fire damage per second
hitData.m_damage.m_fire = SkeletonConfig.FireAuraDamagePerTick.Value;
hitData.SetAttacker(Player.m_localPlayer);
hitData.m_dir = Vector3.zero;

View file

@ -39,7 +39,7 @@ namespace RacesOfValheim
// template: SEMan.AddStatusEffect clones what it is given and adds the clone, so
// anything written to the template afterwards reaches nobody. That is why the Moder
// regeneration bonus never applied either.
m_healthRegenMultiplier = rules.EnhancedRegen ? 1.5f : 1.0f;
m_healthRegenMultiplier = rules.EnhancedRegen ? SkeletonConfig.EnhancedRegenHealthMultiplier.Value : 1.0f;
m_mods = new List<HitData.DamageModPair>
{
@ -62,9 +62,9 @@ namespace RacesOfValheim
base.Setup(character);
m_name = "Resurrection Cooldown";
m_tooltip = "Your skeletal body is too weak to resurrect again right now.";
m_icon = Jotunn.Managers.PrefabManager.Cache.GetPrefab<GameObject>("TrophySkeletonPoison")?.GetComponent<ItemDrop>()?.m_itemData.GetIcon()
m_icon = Jotunn.Managers.PrefabManager.Cache.GetPrefab<GameObject>("TrophySkeletonPoison")?.GetComponent<ItemDrop>()?.m_itemData.GetIcon()
?? Jotunn.Managers.PrefabManager.Cache.GetPrefab<GameObject>("TrophySkeleton")?.GetComponent<ItemDrop>()?.m_itemData.GetIcon();
m_ttl = 300f; // 5 minutes
m_ttl = SkeletonConfig.ResurrectionCooldown.Value;
}
}
}

View file

@ -48,6 +48,37 @@ namespace RacesOfValheim
public static bool IsSkeletonPlayer(Player player) => GetPlayerRace(player) == RaceId;
/// <summary>
/// Fully hides (or restores) one equipped item instance - a helmet, typically.
///
/// Scale-to-zero alone leaves skinned pieces behind: a SkinnedMeshRenderer bound to the
/// player's own bones (some helmets carry a cloth or chain piece skinned that way) is
/// deformed by those bone matrices, not by its GameObject's transform, so zeroing the
/// wrapper's localScale does nothing to it - exactly the "part of the helmet is still
/// there" artifact reported on the Skeleton. Disabling every Renderer underneath has no
/// such exception; combined with the scale it hides both plain and skinned pieces, and
/// is reasserted the same way (Valheim's own visual refresh re-enables the instance and
/// resets its scale, so both must be redone every time visuals rebuild).
/// </summary>
public static void SetEquipmentPieceHidden(GameObject instance, bool hidden)
{
if (instance == null) return;
Vector3 wantedScale = hidden ? Vector3.zero : Vector3.one;
if (instance.transform.localScale != wantedScale)
{
instance.transform.localScale = wantedScale;
}
foreach (Renderer renderer in instance.GetComponentsInChildren<Renderer>(true))
{
if (renderer.enabled == hidden)
{
renderer.enabled = !hidden;
}
}
}
/// <summary>
/// The tier a given player's body should be built for. The ZDO carries it so remote
/// players render at their own standing; without one - the menu preview - fall back to
@ -182,15 +213,21 @@ namespace RacesOfValheim
light.intensity *= 0.6f;
}
// Anything that made the source a torch rather than a fire.
foreach (MonoBehaviour comp in m_instance.GetComponentsInChildren<MonoBehaviour>(true))
// Allowlist, not a blocklist: keep only what a pure VFX actually needs (the
// particle systems, their renderers, and the light tweaked above) and destroy
// every other component, whatever it turns out to be. A blocklist of "known bad"
// types (MonoBehaviour, Collider) missed Rigidbody - not a MonoBehaviour in Unity,
// so the old loop never touched it - and a torch's fire-particle node carrying one
// meant physics kept acting on the clone independently of m_instance being
// repositioned onto the head every frame: it visibly fell away while the empty
// parent stayed correctly tracked above it. Anything that made the source a torch
// rather than a bare flame - the stick mesh, ItemDrop, durability, all of it -
// goes the same way.
foreach (Component comp in m_instance.GetComponentsInChildren<Component>(true))
{
if (comp is Transform || comp is ParticleSystem || comp is ParticleSystemRenderer || comp is Light) continue;
Object.Destroy(comp);
}
foreach (Collider col in m_instance.GetComponentsInChildren<Collider>(true))
{
Object.Destroy(col);
}
return true;
}