From 5febc588eaa71245842559b1c5668ed5c9854af6 Mon Sep 17 00:00:00 2001 From: kanym Date: Tue, 4 Aug 2026 00:22:58 +0200 Subject: [PATCH] feat(dvergar): rename from Dvergur, and give it a lightning affinity Rename covers the folder, all seven filenames and every identifier, status effect name and display string. Valheim's own Dverger/dvergr prefab references are untouched - the names never collided. The race id is what sits in m_customData and the ZDO, so renaming it alone would have handed every existing character the selection menu again. DvergarRace migrates the old id on spawn, before anything else reads it. Runic Spark is modelled on Skadi's Ice Affinity and deliberately shares its shape: live from the base tier and growing a flat step per progression state, so +2 at Base through +16 after Fader. Lightning rather than frost, and like Skadi's it rides every blow rather than melee only. AddFlat gained the elemental channels while it was there - lightning would otherwise have landed in generic damage. The Trol remote-sync trace fired on a two-second timer for as long as a remote player existed, which in the main menu is forever: Player.m_localPlayer is null there, so the character preview counts as remote and it never stopped. Keyed on the state it reports instead, so it still catches a remote player being sized wrongly without narrating an idle menu. --- .../DvergarAbilities.cs} | 58 ++++---- .../DvergarConfig.cs} | 35 +++-- .../DvergarPatches.cs} | 128 ++++++++++-------- .../DvergarProgression.cs} | 50 +++---- .../DvergurRace.cs => Dvergar/DvergarRace.cs} | 59 +++++--- .../DvergarStatusEffects.cs} | 42 +++--- .../DvergarVisuals.cs} | 46 +++---- JotunnModStub/RaceCompendium.cs | 22 +-- JotunnModStub/RaceScale.cs | 4 +- JotunnModStub/RacesOfValheim.cs | 33 +++-- JotunnModStub/Trol/TrolPatches.cs | 25 ++-- JotunnModStub/ZdoVisualSync.cs | 4 +- 12 files changed, 287 insertions(+), 219 deletions(-) rename JotunnModStub/{Dvergur/DvergurAbilities.cs => Dvergar/DvergarAbilities.cs} (77%) rename JotunnModStub/{Dvergur/DvergurConfig.cs => Dvergar/DvergarConfig.cs} (90%) rename JotunnModStub/{Dvergur/DvergurPatches.cs => Dvergar/DvergarPatches.cs} (76%) rename JotunnModStub/{Dvergur/DvergurProgression.cs => Dvergar/DvergarProgression.cs} (57%) rename JotunnModStub/{Dvergur/DvergurRace.cs => Dvergar/DvergarRace.cs} (54%) rename JotunnModStub/{Dvergur/DvergurStatusEffects.cs => Dvergar/DvergarStatusEffects.cs} (83%) rename JotunnModStub/{Dvergur/DvergurVisuals.cs => Dvergar/DvergarVisuals.cs} (90%) diff --git a/JotunnModStub/Dvergur/DvergurAbilities.cs b/JotunnModStub/Dvergar/DvergarAbilities.cs similarity index 77% rename from JotunnModStub/Dvergur/DvergurAbilities.cs rename to JotunnModStub/Dvergar/DvergarAbilities.cs index bd37f69..67bb3b8 100644 --- a/JotunnModStub/Dvergur/DvergurAbilities.cs +++ b/JotunnModStub/Dvergar/DvergarAbilities.cs @@ -5,15 +5,15 @@ using UnityEngine; namespace RacesOfValheim { /// - /// The Dvergur's two eitr abilities. + /// The Dvergar's two eitr abilities. /// /// Runic Ping (Yagluth) - spend eitr to light up ore veins and hidden enemies nearby. /// Runic Overcharge (Fader) - spend eitr to load the next blow of a favoured weapon. /// - /// Both are driven from DvergurRace.Update and both read their cost, radius, duration and - /// cooldown out of DvergurConfig. + /// Both are driven from DvergarRace.Update and both read their cost, radius, duration and + /// cooldown out of DvergarConfig. /// - public static class DvergurAbilities + public static class DvergarAbilities { private static float lastPingTime = -1000f; private static float lastOverchargeTime = -1000f; @@ -24,14 +24,14 @@ namespace RacesOfValheim // Player.TakeInput, so nothing fires while a map, chest or chat window has focus. if (!RaceInput.Allowed) return; - DvergurProgression.DvergurRules rules = DvergurProgression.GetRules(state); + DvergarProgression.DvergarRules rules = DvergarProgression.GetRules(state); - if (rules.RunicPing && Input.GetKeyDown(DvergurConfig.RunicPingKey)) + if (rules.RunicPing && Input.GetKeyDown(DvergarConfig.RunicPingKey)) { TryRunicPing(player); } - if (rules.RunicOvercharge && Input.GetKeyDown(DvergurConfig.RunicOverchargeKey)) + if (rules.RunicOvercharge && Input.GetKeyDown(DvergarConfig.RunicOverchargeKey)) { TryRunicOvercharge(player); } @@ -41,17 +41,17 @@ namespace RacesOfValheim private static void TryRunicPing(Player player) { - if (Time.time - lastPingTime < DvergurConfig.RunicPingCooldown) return; + if (Time.time - lastPingTime < DvergarConfig.RunicPingCooldown) return; - if (player.GetEitr() < DvergurConfig.RunicPingEitrCost) + if (player.GetEitr() < DvergarConfig.RunicPingEitrCost) { player.Message(MessageHud.MessageType.Center, "Not enough eitr"); return; } - player.UseEitr(DvergurConfig.RunicPingEitrCost); + player.UseEitr(DvergarConfig.RunicPingEitrCost); lastPingTime = Time.time; - DvergurStatusEffects.ApplyCooldownIcon(DvergurConfig.RunicPingCdSE, DvergurConfig.RunicPingCooldown); + DvergarStatusEffects.ApplyCooldownIcon(DvergarConfig.RunicPingCdSE, DvergarConfig.RunicPingCooldown); int marked = MarkSurroundings(player); player.Message(MessageHud.MessageType.Center, @@ -69,25 +69,25 @@ namespace RacesOfValheim HashSet alreadyMarked = new HashSet(); int marked = 0; - foreach (Collider collider in Physics.OverlapSphere(center, DvergurConfig.RunicPingRadius)) + foreach (Collider collider in Physics.OverlapSphere(center, DvergarConfig.RunicPingRadius)) { if (collider == null) continue; GameObject vein = FindVeinRoot(collider); if (vein == null || !alreadyMarked.Add(vein)) continue; - SpawnMarker(vein.transform, DvergurConfig.RunicPingOreColor); + SpawnMarker(vein.transform, DvergarConfig.RunicPingOreColor); marked++; } foreach (Character character in Character.GetAllCharacters()) { if (character == null || character == player || character.IsDead() || character.IsTamed()) continue; - if (Vector3.Distance(character.transform.position, center) > DvergurConfig.RunicPingRadius) continue; + if (Vector3.Distance(character.transform.position, center) > DvergarConfig.RunicPingRadius) continue; if (!BaseAI.IsEnemy(player, character)) continue; if (!alreadyMarked.Add(character.gameObject)) continue; - SpawnMarker(character.transform, DvergurConfig.RunicPingEnemyColor); + SpawnMarker(character.transform, DvergarConfig.RunicPingEnemyColor); marked++; } @@ -124,7 +124,7 @@ namespace RacesOfValheim if (root == null) return null; string name = root.name.ToLower(); - foreach (string veinName in DvergurConfig.RunicPingVeinNames) + foreach (string veinName in DvergarConfig.RunicPingVeinNames) { if (name.Contains(veinName)) return root; } @@ -133,20 +133,20 @@ namespace RacesOfValheim private static void SpawnMarker(Transform target, Color color) { - GameObject markerObj = new GameObject("DvergurRunicMark"); + GameObject markerObj = new GameObject("DvergarRunicMark"); markerObj.transform.SetParent(target, false); markerObj.transform.localPosition = Vector3.up; Light light = markerObj.AddComponent(); light.type = LightType.Point; light.color = color; - light.range = DvergurConfig.RunicPingLightRange; - light.intensity = DvergurConfig.RunicPingLightIntensity; + light.range = DvergarConfig.RunicPingLightRange; + light.intensity = DvergarConfig.RunicPingLightIntensity; light.shadows = LightShadows.None; - if (DvergurRace.Instance != null) + if (DvergarRace.Instance != null) { - DvergurRace.Instance.StartCoroutine(DestroyAfter(markerObj, DvergurConfig.RunicPingDuration)); + DvergarRace.Instance.StartCoroutine(DestroyAfter(markerObj, DvergarConfig.RunicPingDuration)); } else { @@ -166,38 +166,38 @@ namespace RacesOfValheim private static void TryRunicOvercharge(Player player) { - if (Time.time - lastOverchargeTime < DvergurConfig.RunicOverchargeCooldown) return; + if (Time.time - lastOverchargeTime < DvergarConfig.RunicOverchargeCooldown) return; - int overchargeHash = DvergurConfig.OverchargeSE.GetStableHashCode(); + int overchargeHash = DvergarConfig.OverchargeSE.GetStableHashCode(); if (player.GetSEMan().HaveStatusEffect(overchargeHash)) return; // already loaded - if (player.GetEitr() < DvergurConfig.RunicOverchargeEitrCost) + if (player.GetEitr() < DvergarConfig.RunicOverchargeEitrCost) { player.Message(MessageHud.MessageType.Center, "Not enough eitr"); return; } - player.UseEitr(DvergurConfig.RunicOverchargeEitrCost); + player.UseEitr(DvergarConfig.RunicOverchargeEitrCost); lastOverchargeTime = Time.time; - DvergurStatusEffects.ApplyCooldownIcon(DvergurConfig.OverchargeCdSE, DvergurConfig.RunicOverchargeCooldown); + DvergarStatusEffects.ApplyCooldownIcon(DvergarConfig.OverchargeCdSE, DvergarConfig.RunicOverchargeCooldown); player.GetSEMan().AddStatusEffect(overchargeHash, true); StatusEffect se = player.GetSEMan().GetStatusEffect(overchargeHash); // The charge is held, not permanent: it lapses if no favoured blow lands in time. - if (se != null) se.m_ttl = DvergurConfig.RunicOverchargeWindow; + if (se != null) se.m_ttl = DvergarConfig.RunicOverchargeWindow; player.Message(MessageHud.MessageType.Center, "Runic Overcharge: your next blow is loaded"); } /// /// Spends a held charge. Called from the damage patch once it has confirmed the blow was - /// struck with a weapon the Dvergur is at home with. + /// struck with a weapon the Dvergar is at home with. /// public static bool ConsumeOvercharge(Player player) { if (player == null) return false; - int hash = DvergurConfig.OverchargeSE.GetStableHashCode(); + int hash = DvergarConfig.OverchargeSE.GetStableHashCode(); if (!player.GetSEMan().HaveStatusEffect(hash)) return false; player.GetSEMan().RemoveStatusEffect(hash, true); diff --git a/JotunnModStub/Dvergur/DvergurConfig.cs b/JotunnModStub/Dvergar/DvergarConfig.cs similarity index 90% rename from JotunnModStub/Dvergur/DvergurConfig.cs rename to JotunnModStub/Dvergar/DvergarConfig.cs index 11e406c..c4e1080 100644 --- a/JotunnModStub/Dvergur/DvergurConfig.cs +++ b/JotunnModStub/Dvergar/DvergarConfig.cs @@ -3,29 +3,29 @@ using UnityEngine; namespace RacesOfValheim { /// - /// Every tunable number the Dvergur uses, in one place. + /// Every tunable number the Dvergar uses, in one place. /// /// The race was specced with most percentages still open, so nothing here is baked into the - /// logic: DvergurProgression reads these to build its per-tier rules and the patches read the + /// logic: DvergarProgression 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. /// /// Values still marked TODO are placeholders chosen to be playable, not final. /// - public static class DvergurConfig + public static class DvergarConfig { // ─── Identity ──────────────────────────────────────────────────────── - // "Dvergur" is provisional. It is the value stored in m_customData["Race"] and in the + // "Dvergar" is provisional. It 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. - public const string RaceId = "Dvergur"; + public const string RaceId = "Dvergar"; - public const string StatsSE = "SE_DvergurStats"; - public const string OverchargeSE = "SE_DvergurOvercharge"; - public const string RunicPingCdSE = "SE_DvergurRunicPingCooldown"; - public const string OverchargeCdSE = "SE_DvergurOverchargeCooldown"; + public const string StatsSE = "SE_DvergarStats"; + public const string OverchargeSE = "SE_DvergarOvercharge"; + public const string RunicPingCdSE = "SE_DvergarRunicPingCooldown"; + public const string OverchargeCdSE = "SE_DvergarOverchargeCooldown"; // 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_DvergurState"; + public const string StateZdoKey = "RacesOfValheim_DvergarState"; // ─── Model ─────────────────────────────────────────────────────────── // Applied to the player's "Visual" child rather than the root transform, the way Furling @@ -44,7 +44,7 @@ namespace RacesOfValheim // This is a multiplier over the human skin texture, not a replacement, so a value near // (1,1,1) changes nothing anyone can see. The first attempt at (0.72, 0.74, 0.82) was // exactly that mistake: correct code, invisible result. 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 Dvergur + // commits to a channel - Trol (0.1, 0.6, 0.7), Furling (0.3, 0.8, 0.3) - so the Dvergar // does too: a cold, dark slate blue-grey. public static readonly Color SkinColor = new Color(0.42f, 0.52f, 0.68f, 1f); @@ -103,9 +103,20 @@ namespace RacesOfValheim 20f // 8 Fader }; - // A Dvergur must never be reduced below this, however the malus and food line up. + // A Dvergar must never be reduced below this, however the malus and food line up. public static readonly float MinMaxHealth = 5f; + // ─── Elemental affinity ────────────────────────────────────────────── + // Runes in the blood: every blow the Dvergar lands carries lightning. + // + // Deliberately the same shape as Skadi's Ice Affinity - live from the base tier and + // growing by a flat step per progression state, so +2 at Base through +16 after Fader - + // with lightning in place of frost. SkadiDamagePatch is the reference; like it, this + // applies to every blow the player lands, not only melee. + public static readonly float ElementalDamagePerState = 2f; + + public static readonly HitData.DamageType ElementalDamageType = HitData.DamageType.Lightning; + // ─── Weapon affinity ───────────────────────────────────────────────── // Bonus damage plus a stamina discount on the attack. Neither scales with the tier - a // tier only ever adds a new weapon to the list - and skill XP is deliberately untouched. diff --git a/JotunnModStub/Dvergur/DvergurPatches.cs b/JotunnModStub/Dvergar/DvergarPatches.cs similarity index 76% rename from JotunnModStub/Dvergur/DvergurPatches.cs rename to JotunnModStub/Dvergar/DvergarPatches.cs index b54b3e5..6953737 100644 --- a/JotunnModStub/Dvergur/DvergurPatches.cs +++ b/JotunnModStub/Dvergar/DvergarPatches.cs @@ -6,15 +6,15 @@ using UnityEngine; namespace RacesOfValheim { /// - /// Every hook the Dvergur needs. The patches only ever decide *whether* a perk applies; *how - /// much* it applies always comes from DvergurProgression, which in turn reads DvergurConfig. + /// Every hook the Dvergar needs. The patches only ever decide *whether* a perk applies; *how + /// much* it applies always comes from DvergarProgression, which in turn reads DvergarConfig. /// - public static class DvergurPatches + public static class DvergarPatches { // ─── Health malus ──────────────────────────────────────────────────── /// - /// The Dvergur is a small frame, and carries less health for it. + /// The Dvergar is a small frame, and carries less health for it. /// /// The malus is taken off the food total rather than off Character.GetMaxHealth, which is /// what the first attempt did and what produced the bug where the bar shrank but the @@ -30,17 +30,17 @@ namespace RacesOfValheim /// number and bar, value and animation all agree. /// [HarmonyPatch(typeof(Player), "GetTotalFoodValue")] - public static class Dvergur_GetTotalFoodValue_Patch + public static class Dvergar_GetTotalFoodValue_Patch { public static void Postfix(Player __instance, ref float hp) { if (__instance == null || __instance != Player.m_localPlayer) return; - if (!DvergurRace.IsDvergur()) return; + if (!DvergarRace.IsDvergar()) return; - float malus = DvergurProgression.Current.HealthMalus; + float malus = DvergarProgression.Current.HealthMalus; if (malus <= 0f) return; - hp = Mathf.Max(DvergurConfig.MinMaxHealth, hp - malus); + hp = Mathf.Max(DvergarConfig.MinMaxHealth, hp - malus); } } @@ -50,16 +50,16 @@ namespace RacesOfValheim /// Sizing runs off Player.Update, which is where the Trol does it and the only place it /// holds: Trol's own postfix forces every non-Trol player's visual back to scale 1 on the /// same frame, so a scale applied from anywhere else was simply overwritten. Being a - /// postfix on the same method puts the Dvergur on equal footing, and RaceScale keeps the + /// postfix on the same method puts the Dvergar on equal footing, and RaceScale keeps the /// two from undoing each other. /// [HarmonyPatch(typeof(Player), "Update")] - public static class Dvergur_PlayerUpdate_Scale_Patch + public static class Dvergar_PlayerUpdate_Scale_Patch { public static void Postfix(Player __instance) { if (__instance == null) return; - DvergurVisuals.ApplyScale(__instance, DvergurVisuals.IsDvergurPlayer(__instance)); + DvergarVisuals.ApplyScale(__instance, DvergarVisuals.IsDvergarPlayer(__instance)); } } @@ -67,23 +67,32 @@ namespace RacesOfValheim /// /// Bonus damage with hammer, bow, axe and crossbow as each is unlocked, and the payoff for - /// a held Runic Overcharge. Neither touches skill XP: the Dvergur is at home with these + /// a held Runic Overcharge. Neither touches skill XP: the Dvergar is at home with these /// weapons, not faster at learning them. /// [HarmonyPatch(typeof(Character), "Damage")] - public static class Dvergur_WeaponAffinity_Damage_Patch + public static class Dvergar_WeaponAffinity_Damage_Patch { public static void Prefix(Character __instance, HitData hit) { if (hit == null || Player.m_localPlayer == null) return; if (hit.GetAttacker() != Player.m_localPlayer) return; - if (!DvergurRace.IsDvergur()) return; + if (!DvergarRace.IsDvergar()) return; int state = BossProgressionManager.GetCurrentProgressionState(); - DvergurConfig.WeaponAffinity? found = DvergurProgression.GetAffinity(hit.m_skill, state); + + // Runic Spark, before the weapon check: the lightning rides every blow the Dvergar + // lands, favoured weapon or not, exactly as Skadi's frost does in SkadiDamagePatch. + float elemental = DvergarProgression.GetRules(state).ElementalDamage; + if (elemental > 0f) + { + AddFlat(hit, DvergarConfig.ElementalDamageType, elemental); + } + + DvergarConfig.WeaponAffinity? found = DvergarProgression.GetAffinity(hit.m_skill, state); if (!found.HasValue) return; - DvergurConfig.WeaponAffinity affinity = found.Value; + DvergarConfig.WeaponAffinity affinity = found.Value; if (affinity.DamagePercent > 0f) { @@ -97,10 +106,10 @@ namespace RacesOfValheim // Overcharge only ever discharges into a favoured weapon, which is why it is // spent here rather than on the first hit of any kind. - if (DvergurProgression.GetRules(state).RunicOvercharge && - DvergurAbilities.ConsumeOvercharge(Player.m_localPlayer)) + if (DvergarProgression.GetRules(state).RunicOvercharge && + DvergarAbilities.ConsumeOvercharge(Player.m_localPlayer)) { - ScalePhysical(hit, DvergurConfig.RunicOverchargeMultiplier); + ScalePhysical(hit, DvergarConfig.RunicOverchargeMultiplier); Player.m_localPlayer.Message(MessageHud.MessageType.TopLeft, "Runic Overcharge discharges"); } } @@ -116,10 +125,15 @@ namespace RacesOfValheim { switch (type) { - case HitData.DamageType.Blunt: hit.m_damage.m_blunt += amount; break; - case HitData.DamageType.Slash: hit.m_damage.m_slash += amount; break; - case HitData.DamageType.Pierce: hit.m_damage.m_pierce += amount; break; - default: hit.m_damage.m_damage += amount; break; + case HitData.DamageType.Blunt: hit.m_damage.m_blunt += amount; break; + case HitData.DamageType.Slash: hit.m_damage.m_slash += amount; break; + case HitData.DamageType.Pierce: hit.m_damage.m_pierce += amount; break; + case HitData.DamageType.Fire: hit.m_damage.m_fire += amount; break; + case HitData.DamageType.Frost: hit.m_damage.m_frost += amount; break; + case HitData.DamageType.Lightning: hit.m_damage.m_lightning += amount; break; + case HitData.DamageType.Poison: hit.m_damage.m_poison += amount; break; + case HitData.DamageType.Spirit: hit.m_damage.m_spirit += amount; break; + default: hit.m_damage.m_damage += amount; break; } } } @@ -131,63 +145,63 @@ namespace RacesOfValheim /// by this player apart from every other DropTable call in the world. Same flag-around-the /// -call approach the Furling uses for its doubled ore. /// - private static bool isDvergurMining = false; + private static bool isDvergarMining = false; private static bool BeginMiningHit(HitData hit) { if (hit == null || Player.m_localPlayer == null) return false; if (hit.GetAttacker() != Player.m_localPlayer) return false; - if (!DvergurRace.IsDvergur()) return false; - if (!DvergurProgression.Current.MiningAffinity) return false; + if (!DvergarRace.IsDvergar()) return false; + if (!DvergarProgression.Current.MiningAffinity) return false; // A pickaxe swing is what the affinity is about - chopping and combat hits on the same // objects go through here too and must be left alone. if (hit.m_damage.m_pickaxe <= 0f) return false; - hit.m_damage.m_pickaxe *= DvergurConfig.MiningDamageMultiplier; - isDvergurMining = true; + hit.m_damage.m_pickaxe *= DvergarConfig.MiningDamageMultiplier; + isDvergarMining = true; return true; } private static void EndMiningHit(bool began) { - if (began) isDvergurMining = false; + if (began) isDvergarMining = false; } [HarmonyPatch(typeof(MineRock5), "DamageArea")] - public static class Dvergur_MineRock5_DamageArea_Patch + public static class Dvergar_MineRock5_DamageArea_Patch { public static void Prefix(HitData hit, out bool __state) => __state = BeginMiningHit(hit); public static void Postfix(bool __state) => EndMiningHit(__state); } [HarmonyPatch(typeof(MineRock), "RPC_Hit")] - public static class Dvergur_MineRock_RPC_Hit_Patch + public static class Dvergar_MineRock_RPC_Hit_Patch { public static void Prefix(HitData hit, out bool __state) => __state = BeginMiningHit(hit); public static void Postfix(bool __state) => EndMiningHit(__state); } [HarmonyPatch(typeof(Destructible), "RPC_Damage")] - public static class Dvergur_Destructible_RPC_Damage_Patch + public static class Dvergar_Destructible_RPC_Damage_Patch { public static void Prefix(HitData hit, out bool __state) => __state = BeginMiningHit(hit); public static void Postfix(bool __state) => EndMiningHit(__state); } [HarmonyPatch(typeof(DropTable), "GetDropList", new System.Type[] { typeof(int) })] - public static class Dvergur_DropTable_GetDropList_Patch + public static class Dvergar_DropTable_GetDropList_Patch { public static void Postfix(ref List __result) { - if (!isDvergurMining || __result == null) return; - if (DvergurConfig.MiningExtraDropChance <= 0f) return; + if (!isDvergarMining || __result == null) return; + if (DvergarConfig.MiningExtraDropChance <= 0f) return; List extra = new List(); foreach (GameObject drop in __result) { if (drop == null || !IsOre(drop.name)) continue; - if (Random.value <= DvergurConfig.MiningExtraDropChance) extra.Add(drop); + if (Random.value <= DvergarConfig.MiningExtraDropChance) extra.Add(drop); } __result.AddRange(extra); } @@ -195,7 +209,7 @@ namespace RacesOfValheim private static bool IsOre(string prefabName) { string lower = prefabName.ToLower(); - foreach (string ore in DvergurConfig.OreDropNames) + foreach (string ore in DvergarConfig.OreDropNames) { if (lower.Contains(ore)) return true; } @@ -210,18 +224,18 @@ namespace RacesOfValheim /// the crafting panel and Player.ConsumeResources go through, so the figure the player is /// quoted and the figure they are charged can never drift apart. /// - /// Scoped to the metals and gems in DvergurConfig.DiscountedResourceNames, which is what + /// Scoped to the metals and gems in DvergarConfig.DiscountedResourceNames, which is what /// keeps this a smithing perk rather than a blanket discount on every wooden wall. /// [HarmonyPatch(typeof(Piece.Requirement), "GetAmount")] - public static class Dvergur_Requirement_GetAmount_Patch + public static class Dvergar_Requirement_GetAmount_Patch { public static void Postfix(Piece.Requirement __instance, ref int __result) { if (__result <= 1 || Player.m_localPlayer == null) return; - if (!DvergurRace.IsDvergur()) return; + if (!DvergarRace.IsDvergar()) return; - float discount = DvergurProgression.Current.SmithingDiscount; + float discount = DvergarProgression.Current.SmithingDiscount; if (discount <= 0f) return; if (__instance == null || __instance.m_resItem == null) return; @@ -233,7 +247,7 @@ namespace RacesOfValheim private static bool IsDiscounted(string prefabName) { string lower = prefabName.ToLower(); - foreach (string resource in DvergurConfig.DiscountedResourceNames) + foreach (string resource in DvergarConfig.DiscountedResourceNames) { if (lower == resource || lower.Contains(resource)) return true; } @@ -249,17 +263,17 @@ namespace RacesOfValheim /// /// The discounted entries are fresh TradeItem instances rather than edited originals: the /// list Valheim hands back holds the trader's own objects, and rewriting their prices in - /// place would permanently mark down the shop for everyone, Dvergur or not. + /// place would permanently mark down the shop for everyone, Dvergar or not. /// [HarmonyPatch(typeof(Trader), "GetAvailableItems")] - public static class Dvergur_Trader_GetAvailableItems_Patch + public static class Dvergar_Trader_GetAvailableItems_Patch { public static void Postfix(ref List __result) { if (__result == null || Player.m_localPlayer == null) return; - if (!DvergurRace.IsDvergur()) return; + if (!DvergarRace.IsDvergar()) return; - float discount = DvergurProgression.Current.TraderBuyDiscount; + float discount = DvergarProgression.Current.TraderBuyDiscount; if (discount <= 0f) return; List discounted = new List(__result.Count); @@ -286,14 +300,14 @@ namespace RacesOfValheim /// lands on exactly the side of the counter it is meant to. /// [HarmonyPatch(typeof(ItemDrop.ItemData), "GetValue")] - public static class Dvergur_ItemData_GetValue_Patch + public static class Dvergar_ItemData_GetValue_Patch { public static void Postfix(ref int __result) { if (__result <= 0 || Player.m_localPlayer == null) return; - if (!DvergurRace.IsDvergur()) return; + if (!DvergarRace.IsDvergar()) return; - float bonus = DvergurProgression.Current.TraderSellBonus; + float bonus = DvergarProgression.Current.TraderSellBonus; if (bonus <= 0f) return; __result = Mathf.RoundToInt(__result * (1f + bonus)); @@ -303,7 +317,7 @@ namespace RacesOfValheim // ─── Skin ──────────────────────────────────────────────────────────── /// - /// Tints the Dvergur ashen grey. + /// Tints the Dvergar ashen grey. /// /// The first attempt did this the way the race-selection menu appears to - VisEquipment's /// SetSkinColor followed by UpdateColors - and nothing happened, because that pair is not @@ -315,21 +329,21 @@ namespace RacesOfValheim /// /// No local-player check and no saved original: the race is read from the ZDO with a /// m_customData fallback so the main-menu preview and the first spawn frame are covered - /// too, and the tint simply stops being applied once the player is no longer a Dvergur. + /// too, and the tint simply stops being applied once the player is no longer a Dvergar. /// [HarmonyPatch(typeof(VisEquipment), "UpdateColors")] - public static class Dvergur_VisEquipment_UpdateColors_Patch + public static class Dvergar_VisEquipment_UpdateColors_Patch { public static void Postfix(VisEquipment __instance) { if (__instance == null || !__instance.m_isPlayer) return; Player player = __instance.GetComponent(); - if (player == null || !DvergurVisuals.IsDvergurPlayer(player)) return; + if (player == null || !DvergarVisuals.IsDvergarPlayer(player)) return; if (__instance.m_bodyModel != null && __instance.m_bodyModel.material != null) { - __instance.m_bodyModel.material.SetColor("_SkinColor", DvergurConfig.SkinColor); + __instance.m_bodyModel.material.SetColor("_SkinColor", DvergarConfig.SkinColor); } TintRenderers(Traverse.Create(__instance).Field("m_hairItemInstance").GetValue()); @@ -341,7 +355,7 @@ namespace RacesOfValheim if (instance == null) return; foreach (Renderer renderer in instance.GetComponentsInChildren()) { - if (renderer.material != null) renderer.material.SetColor("_SkinColor", DvergurConfig.HairColor); + if (renderer.material != null) renderer.material.SetColor("_SkinColor", DvergarConfig.HairColor); } } } @@ -354,7 +368,7 @@ namespace RacesOfValheim /// again behind the hood. /// [HarmonyPatch(typeof(VisEquipment), "UpdateVisuals")] - public static class Dvergur_VisEquipment_UpdateVisuals_Patch + public static class Dvergar_VisEquipment_UpdateVisuals_Patch { public static void Postfix(VisEquipment __instance) { @@ -363,7 +377,7 @@ namespace RacesOfValheim Player player = __instance.GetComponent(); if (player == null) return; - DvergurVisuals.ApplyHood(player); + DvergarVisuals.ApplyHood(player); } } } diff --git a/JotunnModStub/Dvergur/DvergurProgression.cs b/JotunnModStub/Dvergar/DvergarProgression.cs similarity index 57% rename from JotunnModStub/Dvergur/DvergurProgression.cs rename to JotunnModStub/Dvergar/DvergarProgression.cs index 8687411..f3bcc57 100644 --- a/JotunnModStub/Dvergur/DvergurProgression.cs +++ b/JotunnModStub/Dvergar/DvergarProgression.cs @@ -4,21 +4,24 @@ using UnityEngine; namespace RacesOfValheim { /// - /// Turns a boss progression state into the set of Dvergur perks active at that tier, the same + /// Turns a boss progression state into the set of Dvergar perks active at that tier, the same /// way SkeletonProgression and SkadiProgression do for their races. /// - /// Nothing is decided here - every figure comes out of DvergurConfig - so the tuning pass can + /// Nothing is decided here - every figure comes out of DvergarConfig - so the tuning pass can /// happen without touching a single patch. /// - public static class DvergurProgression + public static class DvergarProgression { - public struct DvergurRules + public struct DvergarRules { /// Points subtracted from max health at this tier. public float HealthMalus; - /// Weapon skills the Dvergur is at home with, already filtered by tier. - public List Affinities; + /// Lightning added to every blow at this tier. Live from the base tier. + public float ElementalDamage; + + /// Weapon skills the Dvergar is at home with, already filtered by tier. + public List Affinities; public bool MiningAffinity; public float SmithingDiscount; @@ -30,30 +33,31 @@ namespace RacesOfValheim // 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 DvergurRules[] cache = new DvergurRules[BossProgressionManager.MaxState + 1]; + private static readonly DvergarRules[] cache = new DvergarRules[BossProgressionManager.MaxState + 1]; private static readonly bool[] cached = new bool[BossProgressionManager.MaxState + 1]; - public static DvergurRules GetRules(int state) + public static DvergarRules GetRules(int state) { state = Mathf.Clamp(state, BossProgressionManager.MinState, BossProgressionManager.MaxState); if (cached[state]) return cache[state]; - List affinities = new List(); - foreach (DvergurConfig.WeaponAffinity affinity in DvergurConfig.WeaponAffinities) + List affinities = new List(); + foreach (DvergarConfig.WeaponAffinity affinity in DvergarConfig.WeaponAffinities) { if (state >= affinity.UnlockState) affinities.Add(affinity); } - DvergurRules rules = new DvergurRules + DvergarRules rules = new DvergarRules { - HealthMalus = DvergurConfig.Lookup(DvergurConfig.HealthMalusByState, state), + HealthMalus = DvergarConfig.Lookup(DvergarConfig.HealthMalusByState, state), + ElementalDamage = DvergarConfig.ElementalDamagePerState * state, Affinities = affinities, - MiningAffinity = state >= DvergurConfig.MiningAffinityState, - SmithingDiscount = DvergurConfig.Lookup(DvergurConfig.SmithingDiscountByState, state), - TraderBuyDiscount = DvergurConfig.Lookup(DvergurConfig.TraderBuyDiscountByState, state), - TraderSellBonus = DvergurConfig.Lookup(DvergurConfig.TraderSellBonusByState, state), - RunicPing = state >= DvergurConfig.RunicPingState, - RunicOvercharge = state >= DvergurConfig.RunicOverchargeState + MiningAffinity = state >= DvergarConfig.MiningAffinityState, + SmithingDiscount = DvergarConfig.Lookup(DvergarConfig.SmithingDiscountByState, state), + TraderBuyDiscount = DvergarConfig.Lookup(DvergarConfig.TraderBuyDiscountByState, state), + TraderSellBonus = DvergarConfig.Lookup(DvergarConfig.TraderSellBonusByState, state), + RunicPing = state >= DvergarConfig.RunicPingState, + RunicOvercharge = state >= DvergarConfig.RunicOverchargeState }; cache[state] = rules; @@ -62,17 +66,17 @@ namespace RacesOfValheim } /// Rules for whatever tier the local player is currently on. - public static DvergurRules Current => GetRules(BossProgressionManager.GetCurrentProgressionState()); + public static DvergarRules Current => GetRules(BossProgressionManager.GetCurrentProgressionState()); /// - /// The affinity covering a weapon skill at the current tier, or null when the Dvergur has + /// The affinity covering a weapon skill at the current tier, or null when the Dvergar has /// no particular feel for it. Mining counts as an affinity for stamina purposes only, so /// it is deliberately not part of this list. /// - public static DvergurConfig.WeaponAffinity? GetAffinity(Skills.SkillType skill, int state) + public static DvergarConfig.WeaponAffinity? GetAffinity(Skills.SkillType skill, int state) { - DvergurRules rules = GetRules(state); - foreach (DvergurConfig.WeaponAffinity affinity in rules.Affinities) + DvergarRules rules = GetRules(state); + foreach (DvergarConfig.WeaponAffinity affinity in rules.Affinities) { if (affinity.Skill == skill) return affinity; } diff --git a/JotunnModStub/Dvergur/DvergurRace.cs b/JotunnModStub/Dvergar/DvergarRace.cs similarity index 54% rename from JotunnModStub/Dvergur/DvergurRace.cs rename to JotunnModStub/Dvergar/DvergarRace.cs index daa83c0..def4d70 100644 --- a/JotunnModStub/Dvergur/DvergurRace.cs +++ b/JotunnModStub/Dvergar/DvergarRace.cs @@ -4,17 +4,17 @@ using UnityEngine; namespace RacesOfValheim { /// - /// Driver for the Dvergur: a short, stocky smith who trades a slice of health for an affinity + /// Driver for the Dvergar: a short, stocky smith who trades a slice of health for an affinity /// with hammer, bow, axe and crossbow, a knack for mining and the ear of Haldor and Hildir. /// /// Only the per-frame upkeep lives here. Body scale is a Player.Update postfix in - /// DvergurPatches, since that is the one place it survives; the perks are the other patches in - /// that file; the two eitr abilities are in DvergurAbilities; and every number they use comes - /// from DvergurConfig by way of DvergurProgression. + /// DvergarPatches, since that is the one place it survives; the perks are the other patches in + /// that file; the two eitr abilities are in DvergarAbilities; and every number they use comes + /// from DvergarConfig by way of DvergarProgression. /// - public class DvergurRace : MonoBehaviour + public class DvergarRace : MonoBehaviour { - public static DvergurRace Instance; + public static DvergarRace Instance; // NaN so that the very first frame always counts as a change and pushes the malus through. private float lastAppliedMalus = float.NaN; @@ -26,14 +26,37 @@ namespace RacesOfValheim public void CreateModAssets() { - DvergurStatusEffects.RegisterStatusEffects(); + DvergarStatusEffects.RegisterStatusEffects(); } - public static bool IsDvergur() + /// + /// The race was called "Dvergur" before it was renamed, and that string is what got written + /// into m_customData and the ZDO. Without this, every character created under the old name + /// would come back with no race at all and be handed the selection menu again. + /// + public const string LegacyRaceId = "Dvergur"; + + public static void MigrateLegacyRaceId(Player player) + { + if (player == null || player.m_customData == null) return; + if (!player.m_customData.TryGetValue("Race", out string race) || race != LegacyRaceId) return; + + player.m_customData["Race"] = DvergarConfig.RaceId; + + ZNetView nview = player.GetComponent(); + if (nview != null && nview.IsValid()) + { + nview.GetZDO().Set("RacesOfValheim_Race", DvergarConfig.RaceId); + } + + Jotunn.Logger.LogInfo($"[Dvergar] Migrated '{LegacyRaceId}' to '{DvergarConfig.RaceId}' for {player.GetPlayerName()}."); + } + + public static bool IsDvergar() { return Player.m_localPlayer != null && Player.m_localPlayer.m_customData.ContainsKey("Race") && - Player.m_localPlayer.m_customData["Race"] == DvergurConfig.RaceId; + Player.m_localPlayer.m_customData["Race"] == DvergarConfig.RaceId; } private void Update() @@ -41,30 +64,30 @@ namespace RacesOfValheim Player player = Player.m_localPlayer; if (player == null) return; - bool isDvergur = IsDvergur(); + bool isDvergar = IsDvergar(); - DvergurVisuals.ApplyHood(player); + DvergarVisuals.ApplyHood(player); // Max health is recomputed by Player.UpdateFood, which runs on its own schedule. Left // to itself the malus would only take effect at the next food tick, so a change of // race or of tier is pushed through immediately - this is also what makes the health - // bar and the number agree the instant a player becomes (or stops being) a Dvergur. - float desiredMalus = isDvergur ? DvergurProgression.Current.HealthMalus : 0f; + // bar and the number agree the instant a player becomes (or stops being) a Dvergar. + float desiredMalus = isDvergar ? DvergarProgression.Current.HealthMalus : 0f; if (!Mathf.Approximately(desiredMalus, lastAppliedMalus)) { lastAppliedMalus = desiredMalus; Traverse.Create(player).Method("UpdateFood", 0f, true).GetValue(); } - if (!isDvergur || player.IsDead()) return; + if (!isDvergar || player.IsDead()) return; int state = BossProgressionManager.GetCurrentProgressionState(); // Keep the passive carrier attached. It is re-added rather than assumed because a // respawn, a death or a world load all clear the player's status effects. - if (DvergurStatusEffects.StatsSE != null) + if (DvergarStatusEffects.StatsSE != null) { - int hash = DvergurConfig.StatsSE.GetStableHashCode(); + int hash = DvergarConfig.StatsSE.GetStableHashCode(); if (!player.GetSEMan().HaveStatusEffect(hash)) { player.GetSEMan().AddStatusEffect(hash, true); @@ -75,10 +98,10 @@ namespace RacesOfValheim ZNetView nview = player.GetComponent(); if (nview != null && nview.IsValid()) { - nview.GetZDO().Set(DvergurConfig.StateZdoKey, state); + nview.GetZDO().Set(DvergarConfig.StateZdoKey, state); } - DvergurAbilities.Tick(player, state); + DvergarAbilities.Tick(player, state); } } } diff --git a/JotunnModStub/Dvergur/DvergurStatusEffects.cs b/JotunnModStub/Dvergar/DvergarStatusEffects.cs similarity index 83% rename from JotunnModStub/Dvergur/DvergurStatusEffects.cs rename to JotunnModStub/Dvergar/DvergarStatusEffects.cs index 3e3d0b3..10f83d1 100644 --- a/JotunnModStub/Dvergur/DvergurStatusEffects.cs +++ b/JotunnModStub/Dvergar/DvergarStatusEffects.cs @@ -6,16 +6,16 @@ using UnityEngine; namespace RacesOfValheim { /// - /// Passive carrier for the Dvergur. The stamina half of weapon affinity lives here rather than + /// Passive carrier for the Dvergar. The stamina half of weapon affinity lives here rather than /// in a Harmony patch because Valheim already routes attack cost through the status effects /// (SEMan.ModifyAttackStaminaUsage), so there is nothing to intercept. /// - public class SE_DvergurStats : SE_Stats + public class SE_DvergarStats : SE_Stats { public override void Setup(Character character) { base.Setup(character); - name = DvergurConfig.StatsSE; + name = DvergarConfig.StatsSE; m_name = "Stone and Forge"; m_tooltip = "Small, sturdy, and born to the anvil."; } @@ -25,7 +25,7 @@ namespace RacesOfValheim base.ModifyAttackStaminaUsage(baseStaminaUse, ref staminaUse); if (!(m_character is Player player) || player != Player.m_localPlayer) return; - if (!DvergurRace.IsDvergur()) return; + if (!DvergarRace.IsDvergar()) return; int state = BossProgressionManager.GetCurrentProgressionState(); @@ -39,14 +39,14 @@ namespace RacesOfValheim // Mining is a discount on the pickaxe, not a weapon affinity, so it is checked apart. if (skill == Skills.SkillType.Pickaxes) { - if (DvergurProgression.GetRules(state).MiningAffinity) + if (DvergarProgression.GetRules(state).MiningAffinity) { - staminaUse = Mathf.Max(0f, staminaUse * (1f - DvergurConfig.MiningStaminaPercent)); + staminaUse = Mathf.Max(0f, staminaUse * (1f - DvergarConfig.MiningStaminaPercent)); } return; } - DvergurConfig.WeaponAffinity? affinity = DvergurProgression.GetAffinity(skill, state); + DvergarConfig.WeaponAffinity? affinity = DvergarProgression.GetAffinity(skill, state); if (!affinity.HasValue) return; // Static by design: the discount is the same the day it unlocks as it is after Fader. @@ -56,9 +56,9 @@ namespace RacesOfValheim /// /// Runic Overcharge, held between the cast and the blow that spends it. Purely a marker with a - /// countdown - DvergurPatches reads it when the next affine hit lands. + /// countdown - DvergarPatches reads it when the next affine hit lands. /// - public class SE_DvergurOvercharge : StatusEffect + public class SE_DvergarOvercharge : StatusEffect { } @@ -66,42 +66,42 @@ namespace RacesOfValheim /// Ability cooldowns. They exist only so the HUD has something to count down, the way /// SE_SkadiAbilityCooldown does: Valheim prints the remaining time of any effect with a m_ttl. /// - public class SE_DvergurAbilityCooldown : StatusEffect + public class SE_DvergarAbilityCooldown : StatusEffect { } - public static class DvergurStatusEffects + public static class DvergarStatusEffects { - public static SE_DvergurStats StatsSE { get; private set; } + public static SE_DvergarStats StatsSE { get; private set; } public static void RegisterStatusEffects() { Sprite icon = GetItemIcon("HelmetDverger") ?? GetItemIcon("DvergrKeyFragment") ?? GetItemIcon("Copper"); - var stats = ScriptableObject.CreateInstance(); - stats.name = DvergurConfig.StatsSE; + var stats = ScriptableObject.CreateInstance(); + stats.name = DvergarConfig.StatsSE; stats.m_name = "Stone and Forge"; stats.m_icon = icon; CustomStatusEffect customStats = new CustomStatusEffect(stats, fixReference: false); ItemManager.Instance.AddStatusEffect(customStats); - StatsSE = customStats.StatusEffect as SE_DvergurStats; + StatsSE = customStats.StatusEffect as SE_DvergarStats; - var overcharge = ScriptableObject.CreateInstance(); - overcharge.name = DvergurConfig.OverchargeSE; + var overcharge = ScriptableObject.CreateInstance(); + overcharge.name = DvergarConfig.OverchargeSE; overcharge.m_name = "Runic Overcharge"; overcharge.m_tooltip = "Your next blow with a favoured weapon carries the whole of the charge."; overcharge.m_icon = GetItemIcon("Eitr") ?? icon; ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(overcharge, fixReference: false)); - var pingCd = ScriptableObject.CreateInstance(); - pingCd.name = DvergurConfig.RunicPingCdSE; + var pingCd = ScriptableObject.CreateInstance(); + pingCd.name = DvergarConfig.RunicPingCdSE; pingCd.m_name = "Runic Ping"; pingCd.m_tooltip = "The runes must settle before you may call on them again."; pingCd.m_icon = GetItemIcon("DvergrKeyFragment") ?? icon; ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(pingCd, fixReference: false)); - var overchargeCd = ScriptableObject.CreateInstance(); - overchargeCd.name = DvergurConfig.OverchargeCdSE; + var overchargeCd = ScriptableObject.CreateInstance(); + overchargeCd.name = DvergarConfig.OverchargeCdSE; overchargeCd.m_name = "Overcharge Cooldown"; overchargeCd.m_tooltip = "The runes are spent."; overchargeCd.m_icon = GetItemIcon("Eitr") ?? icon; diff --git a/JotunnModStub/Dvergur/DvergurVisuals.cs b/JotunnModStub/Dvergar/DvergarVisuals.cs similarity index 90% rename from JotunnModStub/Dvergur/DvergurVisuals.cs rename to JotunnModStub/Dvergar/DvergarVisuals.cs index 0a8c43f..a1dc77f 100644 --- a/JotunnModStub/Dvergur/DvergurVisuals.cs +++ b/JotunnModStub/Dvergar/DvergarVisuals.cs @@ -5,7 +5,7 @@ using UnityEngine; namespace RacesOfValheim { /// - /// The Dvergur's looks: a short body, dvergr skin, and a hood that is always worn. + /// The Dvergar's looks: a short body, dvergr skin, and a hood that is always worn. /// /// The hood is a pure cosmetic override, not an equipment lock. The helmet slot stays free and /// whatever the player equips keeps every one of its stats - only its mesh is swapped out, so @@ -14,9 +14,9 @@ namespace RacesOfValheim /// Everything here runs for local and remote players alike, which is why it takes a Player /// rather than reading Player.m_localPlayer. /// - public static class DvergurVisuals + public static class DvergarVisuals { - private const string HoodName = "DvergurHood"; + private const string HoodName = "DvergarHood"; // The source is looked up once per session; the search walks a whole creature prefab and // would otherwise run again for every player that comes into view. The failure is cached @@ -45,7 +45,7 @@ namespace RacesOfValheim return "Human"; } - public static bool IsDvergurPlayer(Player player) => GetPlayerRace(player) == DvergurConfig.RaceId; + public static bool IsDvergarPlayer(Player player) => GetPlayerRace(player) == DvergarConfig.RaceId; // ─── Scale ─────────────────────────────────────────────────────────── @@ -55,7 +55,7 @@ namespace RacesOfValheim /// left the scale in a fight it could not win: Trol's Player.Update postfix resets every /// non-Trol player's visual to 1 on the same frame, and whichever ran last won. /// - public static void ApplyScale(Player player, bool isDvergur) + public static void ApplyScale(Player player, bool isDvergar) { if (player == null) return; @@ -64,15 +64,15 @@ namespace RacesOfValheim GameObject visual = Traverse.Create(player).Field("m_visual").GetValue(); if (visual == null) return; - if (isDvergur) + if (isDvergar) { - float target = DvergurConfig.VisualScale; + float target = DvergarConfig.VisualScale; if (Mathf.Abs(visual.transform.localScale.x - target) > 0.001f) { visual.transform.localScale = new Vector3(target, target, target); } } - else if (Mathf.Abs(visual.transform.localScale.x - DvergurConfig.VisualScale) < 0.001f) + else if (Mathf.Abs(visual.transform.localScale.x - DvergarConfig.VisualScale) < 0.001f) { // Only ever undo our own scale - another race may legitimately be sizing this player. visual.transform.localScale = Vector3.one; @@ -90,7 +90,7 @@ namespace RacesOfValheim VisEquipment visEq = player != null ? player.GetComponent() : null; if (visEq == null) return; - if (IsDvergurPlayer(player) && !player.IsDead()) + if (IsDvergarPlayer(player) && !player.IsDead()) { EnsureHood(visEq); HideEquippedHelmet(visEq); @@ -132,7 +132,7 @@ namespace RacesOfValheim { if (visEq.m_bodyModel == null || visEq.m_bodyModel.bones == null) return; - Transform playerHead = FindBoneByName(visEq.m_bodyModel.bones, DvergurConfig.PlayerHeadBoneName); + Transform playerHead = FindBoneByName(visEq.m_bodyModel.bones, DvergarConfig.PlayerHeadBoneName); if (playerHead == null) return; if (playerHead.Find(HoodName) != null) return; // already wearing it @@ -149,13 +149,13 @@ namespace RacesOfValheim StripComponents(hood); hood.SetActive(true); - Transform hatBone = FindChildByName(hood.transform, DvergurConfig.HoodBoneName); - Transform bodyRoot = FindChildByName(hood.transform, DvergurConfig.BodyRootBoneName); + Transform hatBone = FindChildByName(hood.transform, DvergarConfig.HoodBoneName); + Transform bodyRoot = FindChildByName(hood.transform, DvergarConfig.BodyRootBoneName); if (hatBone == null) { Jotunn.Logger.LogWarning( - $"[Dvergur] No '{DvergurConfig.HoodBoneName}' bone in the instantiated dvergr; hood dropped."); + $"[Dvergar] No '{DvergarConfig.HoodBoneName}' bone in the instantiated dvergr; hood dropped."); Object.Destroy(hood); return; } @@ -166,14 +166,14 @@ namespace RacesOfValheim if (bodyRoot != null) bodyRoot.localScale = Vector3.zero; // Scale and rotation before alignment, since both move the hat bone. - hood.transform.localRotation = Quaternion.Euler(DvergurConfig.HoodOffsetRotation); - hood.transform.localScale = Vector3.one * DvergurConfig.HoodExtraScale; + hood.transform.localRotation = Quaternion.Euler(DvergarConfig.HoodOffsetRotation); + hood.transform.localScale = Vector3.one * DvergarConfig.HoodExtraScale; // The hat now sits wherever the dvergr's own skull was. Shifting the whole object by // the gap between that and the player's head bone lands it correctly without a single // hand-measured offset. hood.transform.position += playerHead.position - hatBone.position; - hood.transform.localPosition += DvergurConfig.HoodOffsetPosition; + hood.transform.localPosition += DvergarConfig.HoodOffsetPosition; foreach (SkinnedMeshRenderer renderer in hood.GetComponentsInChildren(true)) { @@ -234,14 +234,14 @@ namespace RacesOfValheim if (visualResolved) return cachedVisual; visualResolved = true; - GameObject prefab = PrefabManager.Cache.GetPrefab(DvergurConfig.DvergerPrefabName); + GameObject prefab = PrefabManager.Cache.GetPrefab(DvergarConfig.DvergerPrefabName); if (prefab == null) { - Jotunn.Logger.LogWarning($"[Dvergur] Prefab '{DvergurConfig.DvergerPrefabName}' not found; no hood."); + Jotunn.Logger.LogWarning($"[Dvergar] Prefab '{DvergarConfig.DvergerPrefabName}' not found; no hood."); return null; } - Transform visual = prefab.transform.Find(DvergurConfig.DvergerVisualName); + Transform visual = prefab.transform.Find(DvergarConfig.DvergerVisualName); if (visual == null) { // Fall back to whatever holds the renderer, in case the child is ever renamed. @@ -252,11 +252,11 @@ namespace RacesOfValheim if (visual == null) { Jotunn.Logger.LogWarning( - $"[Dvergur] '{DvergurConfig.DvergerPrefabName}' has no '{DvergurConfig.DvergerVisualName}' child and no renderer; no hood."); + $"[Dvergar] '{DvergarConfig.DvergerPrefabName}' has no '{DvergarConfig.DvergerVisualName}' child and no renderer; no hood."); return null; } - Jotunn.Logger.LogInfo($"[Dvergur] Hood source resolved to '{DvergurConfig.DvergerPrefabName}/{visual.name}'."); + Jotunn.Logger.LogInfo($"[Dvergar] Hood source resolved to '{DvergarConfig.DvergerPrefabName}/{visual.name}'."); cachedVisual = visual.gameObject; return cachedVisual; } @@ -265,9 +265,9 @@ namespace RacesOfValheim { if (visEq.m_bodyModel == null || visEq.m_bodyModel.bones == null) return; - Transform playerHead = FindBoneByName(visEq.m_bodyModel.bones, DvergurConfig.PlayerHeadBoneName); + Transform playerHead = FindBoneByName(visEq.m_bodyModel.bones, DvergarConfig.PlayerHeadBoneName); Transform hood = playerHead != null ? playerHead.Find(HoodName) : null; - if (hood == null) return; // never was a Dvergur - leave the helmet alone + if (hood == null) return; // never was a Dvergar - leave the helmet alone // Destroy is deferred to the end of the frame, so the object is renamed first: without // that, every call until it actually goes away finds it again and re-runs the restore. diff --git a/JotunnModStub/RaceCompendium.cs b/JotunnModStub/RaceCompendium.cs index eee4c6a..c827de8 100644 --- a/JotunnModStub/RaceCompendium.cs +++ b/JotunnModStub/RaceCompendium.cs @@ -16,7 +16,7 @@ namespace RacesOfValheim "Furling Secrets", "Trol Secrets", "Draugh Secrets", - "Dvergur Secrets" + "Dvergar Secrets" }; public static void UpdateCompendiumText(Player player) @@ -68,9 +68,9 @@ namespace RacesOfValheim { GenerateDraughText(knownTexts, state, player); } - else if (currentRace == DvergurConfig.RaceId) + else if (currentRace == DvergarConfig.RaceId) { - GenerateDvergurText(knownTexts, state); + GenerateDvergarText(knownTexts, state); } } @@ -78,17 +78,19 @@ namespace RacesOfValheim /// Reads its figures straight out of the live rules rather than restating them, so the /// entry cannot drift from the code the way a hand-written percentage would. /// - private static void GenerateDvergurText(Dictionary knownTexts, int state) + private static void GenerateDvergarText(Dictionary knownTexts, int state) { - DvergurProgression.DvergurRules rules = DvergurProgression.GetRules(state); + DvergarProgression.DvergarRules rules = DvergarProgression.GetRules(state); StringBuilder sb = new StringBuilder(); - sb.AppendLine("The Dvergur's Craft\n"); + sb.AppendLine("The Dvergar's Craft\n"); sb.AppendLine($"[Base Passive] Small and Stubborn: You stand a third shorter than a human and carry {rules.HealthMalus:0.#} less health for it. The dvergr hood never leaves your head - wear whatever helm you please and keep every point of its protection, but the runes will always show you as one of the deep folk.\n"); + sb.AppendLine($"[Base Passive] Runic Spark: The runes in your blood earth themselves through whatever you strike. Every blow you land carries +{rules.ElementalDamage:0.#} Lightning damage - a bonus that grows as each boss falls.\n"); + List weapons = new List(); - foreach (DvergurConfig.WeaponAffinity affinity in rules.Affinities) + foreach (DvergarConfig.WeaponAffinity affinity in rules.Affinities) { weapons.Add(affinity.DisplayName); } @@ -107,12 +109,12 @@ namespace RacesOfValheim sb.AppendLine($"[Bonemass Unlock] Kin of the Traders (Passive): Haldor and Hildir know their own. Their prices drop by {rules.TraderBuyDiscount * 100f:0}% for you, and what they pay for your trophies and hunting rewards rises by {rules.TraderSellBonus * 100f:0}%.\n"); if (rules.RunicPing) - sb.AppendLine($"[Yagluth Unlock] Runic Ping ('{DvergurConfig.RunicPingKey}' Key): Spend {DvergurConfig.RunicPingEitrCost:0} eitr to send a pulse through the stone. For {DvergurConfig.RunicPingDuration:0} seconds every ore vein and every hidden enemy within {DvergurConfig.RunicPingRadius:0} meters is lit for you alone.\n"); + sb.AppendLine($"[Yagluth Unlock] Runic Ping ('{DvergarConfig.RunicPingKey}' Key): Spend {DvergarConfig.RunicPingEitrCost:0} eitr to send a pulse through the stone. For {DvergarConfig.RunicPingDuration:0} seconds every ore vein and every hidden enemy within {DvergarConfig.RunicPingRadius:0} meters is lit for you alone.\n"); if (rules.RunicOvercharge) - sb.AppendLine($"[Fader Unlock] Runic Overcharge ('{DvergurConfig.RunicOverchargeKey}' Key): Spend {DvergurConfig.RunicOverchargeEitrCost:0} eitr to load the runes. Your next blow with a favoured weapon lands with {DvergurConfig.RunicOverchargeMultiplier:0}x its weight. Hold the charge no longer than {DvergurConfig.RunicOverchargeWindow:0} seconds or it bleeds away.\n"); + sb.AppendLine($"[Fader Unlock] Runic Overcharge ('{DvergarConfig.RunicOverchargeKey}' Key): Spend {DvergarConfig.RunicOverchargeEitrCost:0} eitr to load the runes. Your next blow with a favoured weapon lands with {DvergarConfig.RunicOverchargeMultiplier:0}x its weight. Hold the charge no longer than {DvergarConfig.RunicOverchargeWindow:0} seconds or it bleeds away.\n"); - knownTexts["Dvergur Secrets"] = sb.ToString(); + knownTexts["Dvergar Secrets"] = sb.ToString(); } private static void GenerateDraughText(Dictionary knownTexts, int state, Player player) diff --git a/JotunnModStub/RaceScale.cs b/JotunnModStub/RaceScale.cs index 7c8f5fe..505db57 100644 --- a/JotunnModStub/RaceScale.cs +++ b/JotunnModStub/RaceScale.cs @@ -9,7 +9,7 @@ namespace RacesOfValheim /// makes every such race stamp on every other one, with the winner decided by whichever /// postfix Harmony happened to run last. /// - /// That is what left the Dvergur at full height: Trol's reset ran on the same frame and put it + /// That is what left the Dvergar at full height: Trol's reset ran on the same frame and put it /// straight back to 1. Asking here first means a race only ever resets a player that nobody /// else is sizing. /// @@ -19,7 +19,7 @@ namespace RacesOfValheim { "Trol", "Furling", - DvergurConfig.RaceId + DvergarConfig.RaceId }; public static bool ManagesOwnScale(string race) diff --git a/JotunnModStub/RacesOfValheim.cs b/JotunnModStub/RacesOfValheim.cs index b5216d7..05a2b60 100644 --- a/JotunnModStub/RacesOfValheim.cs +++ b/JotunnModStub/RacesOfValheim.cs @@ -32,7 +32,7 @@ namespace RacesOfValheim gameObject.AddComponent(); gameObject.AddComponent(); gameObject.AddComponent(); - gameObject.AddComponent(); + gameObject.AddComponent(); PrefabManager.OnVanillaPrefabsAvailable += CreateAllModAssets; CommandManager.Instance.AddConsoleCommand(new ResetRaceCommand()); CommandManager.Instance.AddConsoleCommand(new CheckProgressionCommand()); @@ -74,8 +74,8 @@ namespace RacesOfValheim player.GetSEMan().RemoveStatusEffect("SE_SkeletonStats".GetStableHashCode()); player.GetSEMan().RemoveStatusEffect("SE_SkadiStats".GetStableHashCode()); player.GetSEMan().RemoveStatusEffect("SE_SkadiCooldown".GetStableHashCode()); - player.GetSEMan().RemoveStatusEffect(DvergurConfig.StatsSE.GetStableHashCode()); - player.GetSEMan().RemoveStatusEffect(DvergurConfig.OverchargeSE.GetStableHashCode()); + player.GetSEMan().RemoveStatusEffect(DvergarConfig.StatsSE.GetStableHashCode()); + player.GetSEMan().RemoveStatusEffect(DvergarConfig.OverchargeSE.GetStableHashCode()); ZNetView nview = player.GetComponent(); if (nview != null && nview.IsValid()) nview.GetZDO().Set("RacesOfValheim_Race", "Human"); @@ -97,7 +97,7 @@ namespace RacesOfValheim FurlingRace.Instance.CreateModAssets(); TrolRace.Instance.CreateModAssets(); DraughRace.Instance.CreateModAssets(); - DvergurRace.Instance.CreateModAssets(); + DvergarRace.Instance.CreateModAssets(); } // --- RACE SELECTION UI --- public void ShowRaceSelectionMenu() @@ -239,7 +239,7 @@ namespace RacesOfValheim CreateRaceButtonWithConfirm("Draugh", new Vector2(450, -20), GetDraughIcon(), "A decaying undead warrior fueled by dark magic and extreme metal.", SelectDraugh); // Row 3 (y = -140) - CreateRaceButtonWithConfirm("Dvergur", new Vector2(-450, -140), GetDvergurIcon(), "Small, stubborn smiths of the deep. Frail of frame, but masters of metal, mine and market.", SelectDvergur); + CreateRaceButtonWithConfirm("Dvergar", new Vector2(-450, -140), GetDvergarIcon(), "Small, stubborn smiths of the deep. Frail of frame, but masters of metal, mine and market.", SelectDvergar); GUIManager.BlockInput(true); } @@ -583,30 +583,30 @@ namespace RacesOfValheim return null; } - private void SelectDvergur() + private void SelectDvergar() { if (Player.m_localPlayer != null) { - Player.m_localPlayer.m_customData["Race"] = DvergurConfig.RaceId; + Player.m_localPlayer.m_customData["Race"] = DvergarConfig.RaceId; ZNetView nview = Player.m_localPlayer.GetComponent(); - if (nview != null && nview.IsValid()) nview.GetZDO().Set("RacesOfValheim_Race", DvergurConfig.RaceId); + if (nview != null && nview.IsValid()) nview.GetZDO().Set("RacesOfValheim_Race", DvergarConfig.RaceId); - Player.m_localPlayer.GetSEMan().AddStatusEffect(DvergurConfig.StatsSE.GetStableHashCode(), true); + Player.m_localPlayer.GetSEMan().AddStatusEffect(DvergarConfig.StatsSE.GetStableHashCode(), true); // No SetSkinColor here: the tint is written onto the material by the UpdateColors - // postfix in DvergurPatches, which keys off the race and so needs nothing saved. + // postfix in DvergarPatches, which keys off the race and so needs nothing saved. VisEquipment visEq = Player.m_localPlayer.GetComponent(); if (visEq != null) { visEq.GetType().GetMethod("UpdateVisuals", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public)?.Invoke(visEq, null); } - Player.m_localPlayer.Message(MessageHud.MessageType.Center, "You chose the path of the Dvergur."); + Player.m_localPlayer.Message(MessageHud.MessageType.Center, "You chose the path of the Dvergar."); CloseRaceSelectionMenu(); } } - private Sprite GetDvergurIcon() + private Sprite GetDvergarIcon() { GameObject prefab = PrefabManager.Cache.GetPrefab("HelmetDverger")?.gameObject; if (prefab == null) prefab = PrefabManager.Cache.GetPrefab("DvergrKeyFragment")?.gameObject; @@ -679,6 +679,11 @@ namespace RacesOfValheim { if (__instance == Player.m_localPlayer) { + // Runs before anything reads the race, so the rest of this method - and the race + // check further down that would otherwise reopen the selection menu - sees the + // renamed id rather than the old one. + DvergarRace.MigrateLegacyRaceId(__instance); + if (__instance.m_customData.ContainsKey("FenrirCurse_Active") && __instance.m_customData["FenrirCurse_Active"] == "true") { __instance.GetSEMan().AddStatusEffect("SE_FenrirCurse".GetStableHashCode(), true); @@ -691,7 +696,7 @@ namespace RacesOfValheim if (visEq != null) visEq.GetType().GetMethod("UpdateColors", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public)?.Invoke(visEq, null); } - // The Dvergur needs no entry here: its tint is applied by the UpdateColors postfix + // The Dvergar needs no entry here: its tint is applied by the UpdateColors postfix // every time Valheim refreshes the body, rather than being stored on the player. // Check for Race Selection @@ -784,7 +789,7 @@ namespace RacesOfValheim public override void Run(string[] args) { - string prefabName = args.Length > 0 ? args[0] : DvergurConfig.DvergerPrefabName; + string prefabName = args.Length > 0 ? args[0] : DvergarConfig.DvergerPrefabName; GameObject prefab = Jotunn.Managers.PrefabManager.Cache.GetPrefab(prefabName); if (prefab == null) { diff --git a/JotunnModStub/Trol/TrolPatches.cs b/JotunnModStub/Trol/TrolPatches.cs index a049085..5c1a2c3 100644 --- a/JotunnModStub/Trol/TrolPatches.cs +++ b/JotunnModStub/Trol/TrolPatches.cs @@ -95,7 +95,12 @@ namespace RacesOfValheim public const string StateKey = "RacesOfValheim_State"; public const string TrueFormKey = "RacesOfValheim_TrolTrueForm"; - private static float lastRemoteLog = 0f; + // Remote sync tracing. It used to fire on a 2-second timer for as long as a remote player + // existed, which in the main menu means forever: Player.m_localPlayer is null there, so the + // character-preview player counts as remote and the log never stopped. Keyed on the state + // it reports instead, so it still catches a remote player being sized wrongly - the reason + // it exists - without narrating a menu that is doing nothing. + private static string lastRemoteLogKey = ""; private static float ScaleForState(int state) { @@ -147,13 +152,17 @@ namespace RacesOfValheim targetScale = state >= 7 ? 2.5f : 2.0f; } - if (!isLocal && Time.time - lastRemoteLog > 2f) + if (!isLocal) { - lastRemoteLog = Time.time; - Jotunn.Logger.LogInfo( - $"[TrolSync] remote '{__instance.GetPlayerName()}' race='{race}' zdoReady={zdoReady} " + - $"state={state} trueForm={isTrueFormActive} target={targetScale:F2} " + - $"currentScale={visual.transform.localScale.x:F2} rootScale={__instance.transform.localScale.x:F2}"); + string logKey = $"{__instance.GetPlayerName()}|{race}|{zdoReady}|{state}|{isTrueFormActive}|{targetScale:F2}"; + if (logKey != lastRemoteLogKey) + { + lastRemoteLogKey = logKey; + Jotunn.Logger.LogInfo( + $"[TrolSync] remote '{__instance.GetPlayerName()}' race='{race}' zdoReady={zdoReady} " + + $"state={state} trueForm={isTrueFormActive} target={targetScale:F2} " + + $"currentScale={visual.transform.localScale.x:F2} rootScale={__instance.transform.localScale.x:F2}"); + } } if (race == "Trol") @@ -179,7 +188,7 @@ namespace RacesOfValheim else if (!RaceScale.ManagesOwnScale(race) && Mathf.Abs(visual.transform.localScale.x - 1f) > 0.001f) { // Races that size themselves are left alone. Without this guard the reset fires on - // every frame for a Furling or a Dvergur too, undoing their scale as fast as they + // every frame for a Furling or a Dvergar too, undoing their scale as fast as they // set it, because both are applied from a postfix on this same method. visual.transform.localScale = Vector3.one; } diff --git a/JotunnModStub/ZdoVisualSync.cs b/JotunnModStub/ZdoVisualSync.cs index 4b0fefa..dc29a07 100644 --- a/JotunnModStub/ZdoVisualSync.cs +++ b/JotunnModStub/ZdoVisualSync.cs @@ -81,11 +81,11 @@ namespace RacesOfValheim { // Managed externally in TrolPatches.cs } - else if (race == DvergurConfig.RaceId) + else if (race == DvergarConfig.RaceId) { // Scale is handled for every player by the Player.Update postfix; this only keeps // the hood and the hidden helmet asserted between equipment refreshes. - DvergurVisuals.ApplyHood(m_player); + DvergarVisuals.ApplyHood(m_player); } else {