From 4559e0b9e1914ae5260c35eb801cefb1c052ba7c Mon Sep 17 00:00:00 2001 From: Ferdinando Date: Tue, 18 Aug 2026 16:51:07 +0200 Subject: [PATCH] warvulture --- JotunnModStub/Aswid/AswidClaws.cs | 7 +- JotunnModStub/Aswid/AswidConfig.cs | 2 +- JotunnModStub/Aswid/AswidPatches.cs | 3 +- JotunnModStub/Aswid/AswidRace.cs | 12 +- JotunnModStub/Fenrir/FenrirClaws.cs | 7 +- JotunnModStub/RaceClaws.cs | 320 ++++++++++++++++++++-- JotunnModStub/RaceClawsConfig.cs | 33 +++ JotunnModStub/RaceCompendium.cs | 6 +- JotunnModStub/RacesOfValheim.cs | 5 +- JotunnModStub/Skadi/SkadiPatches.cs | 45 ++- JotunnModStub/Skadi/SkadiRace.cs | 17 +- JotunnModStub/Skadi/SkadiStatusEffects.cs | 21 ++ README.md | 23 +- manifest.json | 2 +- 14 files changed, 455 insertions(+), 48 deletions(-) create mode 100644 JotunnModStub/RaceClawsConfig.cs diff --git a/JotunnModStub/Aswid/AswidClaws.cs b/JotunnModStub/Aswid/AswidClaws.cs index 2965613..cbfe3db 100644 --- a/JotunnModStub/Aswid/AswidClaws.cs +++ b/JotunnModStub/Aswid/AswidClaws.cs @@ -5,9 +5,10 @@ namespace RacesOfValheim /// /// The Claws of the Beast: the Bjorn claw, burned down to almost black. /// - /// Everything about how they behave - issued once, never dropped, back in hand the moment the - /// hands are free, tier damage as slash - lives in RaceClawSet. This file is only the Aswid's - /// half of the answer: which model, what colour, and when the race is wearing another body. + /// Everything about how they behave - a timed skill (RaceClawsConfig.ActivateKey), issued and + /// retracted on its own, back in hand the moment the hands are free while it runs, tier damage + /// as slash - lives in RaceClawSet. This file is only the Aswid's half of the answer: which + /// model, what colour, and when the race is wearing another body. /// /// The tint is config rather than a constant because "almost black" is a look, not a number, /// and it needs one pass in front of a mirror. It is applied to the item's own copies of the diff --git a/JotunnModStub/Aswid/AswidConfig.cs b/JotunnModStub/Aswid/AswidConfig.cs index b195c9f..f7e6a87 100644 --- a/JotunnModStub/Aswid/AswidConfig.cs +++ b/JotunnModStub/Aswid/AswidConfig.cs @@ -106,7 +106,7 @@ namespace RacesOfValheim TameKey = config.Bind(keybinds, "Tame", new KeyboardShortcut(KeyCode.U), new ConfigDescription("Tames the creature under your cursor, if your tier allows it.")); ToggleDevourKey = config.Bind(keybinds, "Toggle Devour Ability", new KeyboardShortcut(KeyCode.I), - new ConfigDescription("Turns the automatic Devour-on-kill behavior on or off.")); + new ConfigDescription("Turns the Vampiric Aura and the automatic Devour-on-kill behavior on or off together. Turn this off before talking to Haldor/Hildir - the aura does not recognize traders and will attack them.")); const string combat = "Aswid - Passive Combat"; DamageBonusPerState = config.Bind(combat, "Damage Bonus Per State", 2f, diff --git a/JotunnModStub/Aswid/AswidPatches.cs b/JotunnModStub/Aswid/AswidPatches.cs index 07166f1..95ab0c6 100644 --- a/JotunnModStub/Aswid/AswidPatches.cs +++ b/JotunnModStub/Aswid/AswidPatches.cs @@ -532,7 +532,8 @@ namespace RacesOfValheim if (__instance == Player.m_localPlayer && RaceInput.Allowed && AswidConfig.ToggleDevourKey.Value.IsDown()) { AswidRace.DevourEnabled = !AswidRace.DevourEnabled; - string msg = AswidRace.DevourEnabled ? "Devour Ability: ENABLED" : "Devour Ability: DISABLED"; + AswidRace.AuraEnabled = AswidRace.DevourEnabled; + string msg = AswidRace.DevourEnabled ? "Vampiric Aura: ENABLED" : "Vampiric Aura: DISABLED"; __instance.Message(MessageHud.MessageType.Center, msg); } diff --git a/JotunnModStub/Aswid/AswidRace.cs b/JotunnModStub/Aswid/AswidRace.cs index 67bbe53..d2085f4 100644 --- a/JotunnModStub/Aswid/AswidRace.cs +++ b/JotunnModStub/Aswid/AswidRace.cs @@ -832,11 +832,18 @@ namespace RacesOfValheim private float damageTickTimer = 0f; /// - /// The Vampiric Aura is passive: it drains on its own, in every form, with no key to hold and - /// no icon or message of its own. The form only decides how hard it bites. + /// The Vampiric Aura drains on its own, in every form, with no key to hold - but it does not + /// distinguish traders from monsters, so it can execute Haldor/Hildir on approach. AuraEnabled + /// (toggled with Devour on the same key) is the escape hatch for that. /// private void HandleVampiricAura() { + if (!AuraEnabled) + { + damageTickTimer = 0f; + return; + } + damageTickTimer += Time.deltaTime; if (damageTickTimer < AswidConfig.AuraTickInterval.Value) return; @@ -914,6 +921,7 @@ namespace RacesOfValheim } public static bool DevourEnabled = true; + public static bool AuraEnabled = true; private static float lastConsumeTime = 0f; public static void TryConsumeMob(Character c, float maxHp, bool bypassCooldown = false) diff --git a/JotunnModStub/Fenrir/FenrirClaws.cs b/JotunnModStub/Fenrir/FenrirClaws.cs index 604fd0b..ebe749d 100644 --- a/JotunnModStub/Fenrir/FenrirClaws.cs +++ b/JotunnModStub/Fenrir/FenrirClaws.cs @@ -5,9 +5,10 @@ namespace RacesOfValheim /// /// The Cursed Claws: the flesh rippers, worn exactly as the game authored them. /// - /// Everything about how they behave - issued once, never dropped, back in hand the moment the - /// hands are free, tier damage as slash - lives in RaceClawSet. This file is only the Fenrir's - /// half: which model, and when the race is currently a wolf. + /// Everything about how they behave - a timed skill (RaceClawsConfig.ActivateKey), issued and + /// retracted on its own, back in hand the moment the hands are free while it runs, tier damage + /// as slash - lives in RaceClawSet. This file is only the Fenrir's half: which model, and when + /// the race is currently a wolf. /// /// No tint. The fenrir claw already looks like something a Fenrir would grow, which is the /// whole reason it is the one being borrowed. diff --git a/JotunnModStub/RaceClaws.cs b/JotunnModStub/RaceClaws.cs index 2e11b50..251d38b 100644 --- a/JotunnModStub/RaceClaws.cs +++ b/JotunnModStub/RaceClaws.cs @@ -1,33 +1,42 @@ using System.Collections.Generic; using HarmonyLib; +using Jotunn.Entities; using Jotunn.Managers; using UnityEngine; namespace RacesOfValheim { /// - /// Claws that are part of the body, for the races that grow a pair. + /// Claws that are part of the body, for the races that grow a pair - as an ACTIVE SKILL. A + /// keypress (RaceClawsConfig.ActivateKey) grows them for RaceClawsConfig.DurationSeconds, and + /// they retract - unequipped and removed from the inventory outright - the moment that timer + /// runs out. Recasting mid-window simply restarts the timer. /// /// This is SvermClawSlot generalised, not reinvented: the Sverm's Chitin Claws worked out /// the whole shape of the problem, and the Aswid and the Fenrir are asking for the same object /// with a different face. So the machinery moved here and each race supplies only what is /// genuinely its own - the item name, the model to wear, and whether it is currently a wolf. - /// The Sverm still runs its own copy, untouched, because it also carries a carapace, a stinger - /// form and a fire term at Fader that none of this knows about. + /// The Sverm still runs its own copy, untouched (permanent, not timed), because it also carries + /// a carapace, a stinger form and a fire term at Fader that none of this knows about. /// /// WHY A REAL ITEM AND NOT A COSMETIC. Bolting a model to the hand bones works right up until /// the game rebuilds equipment visuals - which it does on every equip - and wipes it. A real /// item in a real slot has nothing to put back. The trade is that a real weapon occupies the /// right hand, so three rules keep that reading as intended rather than as a bug: sheathe - /// anything else and the claws come back, the holster key cannot put them away, and they - /// cannot be dragged, moved or dropped. + /// anything else and the claws come back (while the skill is still running), the holster key + /// cannot put them away, and they cannot be dragged, moved or dropped. None of that costs an + /// inventory slot outside the two-minute window any more, which was the whole reason to move + /// off the earlier "issued once, forever" version: a slot permanently occupied by an + /// unremovable item was a standing annoyance, not a feature. /// /// BALANCE IS SHARED ON PURPOSE. The damage is not read from the model each race wears - the /// Fenrir's flesh rippers and the Bjorn claw are not worth the same, and a race should not be /// stronger because its claws are prettier. Every set reads the Sverm's own reference weapon at /// quality 4 and the Sverm's own per-tier percentages, so all three races hit for identical /// numbers at identical tiers. What differs here is the shape of the damage: these two land it - /// entirely as slash, where the Sverm splits it three ways and lights it on fire at Fader. + /// entirely as slash, where the Sverm splits it three ways and lights it on fire at Fader. The + /// damage bonus itself only applies while the claws are the thing actually equipped - see + /// ApplyToUnarmedHit - so a bare-fisted punch after they retract is a bare-fisted punch. /// public abstract class RaceClawSet { @@ -69,21 +78,52 @@ namespace RacesOfValheim // ─── Registry ──────────────────────────────────────────────────────── private static readonly List sets = new List(); + private static bool rosterBuilt; /// /// The roster. Kept here rather than in RacesOfValheim.Awake so the whole feature is this /// file plus one short file per race, and adding a third clawed race is one line - not one /// line here and another one three hundred lines away in the plugin's startup. + /// + /// BUILT LAZILY, AND NOT FROM A STATIC CONSTRUCTOR. That is the fix for a bug that cost the + /// Fenrir this entire feature while the Aswid worked perfectly, which is exactly what made + /// it hard to see: the item registered, the model resolved, the patch ran, and the race + /// resolved to "Fenrir" - the set simply was not in this list. + /// + /// The trap is .NET type initialisation re-entrancy. FenrirRace.CreateModAssets touches + /// FenrirClaws.Instance first (before AswidRace does its own), which starts FenrirClaws's + /// type initialiser; constructing that instance triggers this base type's static + /// constructor, which reaches back for FenrirClaws.Instance - still null, because its field + /// initialiser is halfway through running further down the same stack. The CLR does not + /// wait and does not re-run it: it hands back null. Register(null) then returned quietly and + /// the Fenrir was absent from the roster forever, while the Aswid - reached from inside the + /// static constructor rather than from outside it - was added normally. + /// + /// Called from For/SetOwning, which only ever run from Player.Update and the inventory GUI, + /// long after every type initialiser has finished. Register also complains about a null now + /// rather than swallowing it, so this class of failure is loud the next time. /// - static RaceClawSet() + private static void EnsureRoster() { + if (rosterBuilt) return; + rosterBuilt = true; // set first: a re-entrant call must not build the list twice + Register(AswidClaws.Instance); Register(FenrirClaws.Instance); + + List names = new List(); + foreach (RaceClawSet set in sets) names.Add(set.RaceId); + Jotunn.Logger.LogInfo($"[RaceClaws] Roster: {(names.Count > 0 ? string.Join(", ", names.ToArray()) : "EMPTY")}."); } public static void Register(RaceClawSet set) { - if (set == null || sets.Contains(set)) return; + if (set == null) + { + Jotunn.Logger.LogWarning("[RaceClaws] Refused to register a null claw set - that race will have no claws."); + return; + } + if (sets.Contains(set)) return; sets.Add(set); } @@ -91,6 +131,7 @@ namespace RacesOfValheim public static RaceClawSet For(Player player) { if (player == null) return null; + EnsureRoster(); string race = GetRace(player); foreach (RaceClawSet set in sets) @@ -104,6 +145,7 @@ namespace RacesOfValheim public static RaceClawSet SetOwning(ItemDrop.ItemData item) { if (item == null || item.m_shared == null) return null; + EnsureRoster(); foreach (RaceClawSet set in sets) { @@ -115,6 +157,13 @@ namespace RacesOfValheim /// /// Reads the race off the ZDO, falling back to m_customData - the same order every visual /// in this mod reads it in, so a remote player and the menu preview both answer correctly. + /// + /// "Human" in the ZDO is treated as no answer rather than as an answer, and that is not + /// cosmetic: ResetRace writes exactly that string into the ZDO before reopening the + /// selection menu, so a client whose ZDO write lost the race afterwards would otherwise be + /// stuck reading "Human" forever with a perfectly correct "Fenrir" sitting in m_customData + /// right next to it. Falling through to m_customData costs one dictionary lookup and closes + /// that hole. /// private static string GetRace(Player player) { @@ -122,7 +171,7 @@ namespace RacesOfValheim if (nview != null && nview.IsValid()) { string race = nview.GetZDO().GetString("RacesOfValheim_Race", ""); - if (!string.IsNullOrEmpty(race)) return race; + if (!string.IsNullOrEmpty(race) && race != "Human") return race; } if (player.m_customData != null && player.m_customData.TryGetValue("Race", out string custom)) @@ -133,6 +182,26 @@ namespace RacesOfValheim return "Human"; } + /// + /// Both raw values the race is read from, for the diagnostic line. Kept next to GetRace so + /// the two cannot drift apart. + /// + internal static string DescribeRaceSources(Player player) + { + if (player == null) return "player is null"; + + ZNetView nview = player.GetComponent(); + string zdo = nview == null ? "no ZNetView" + : !nview.IsValid() ? "ZDO not valid" + : $"'{nview.GetZDO().GetString("RacesOfValheim_Race", "")}'"; + + string custom = player.m_customData == null ? "no customData" + : player.m_customData.TryGetValue("Race", out string c) ? $"'{c}'" + : "absent"; + + return $"ZDO={zdo}, customData={custom}, resolved='{GetRace(player)}'"; + } + // ─── Registration of the item ──────────────────────────────────────── private bool registered; @@ -196,9 +265,50 @@ namespace RacesOfValheim registered = true; Jotunn.Logger.LogInfo($"[{RaceId}] Registered '{ItemName}' from '{source.name}'."); + RegisterActiveStatusEffect(drop); RefreshTint(); } + /// + /// The buff the player sees while the claws are out: the claw item's OWN icon, with the + /// countdown the game draws under any effect carrying a m_ttl. No custom HUD, no second + /// timer to keep in sync with this one - vanilla already draws exactly this. + /// + /// Registered from here, which is to say from CreateModAssets, and that timing is the whole + /// point rather than a detail: an earlier version created this effect lazily on the first + /// activation and it never appeared, because Jotunn only takes new entries into ObjectDB at + /// OnVanillaPrefabsAvailable. SEMan.AddStatusEffect then looked the name up, found nothing, + /// and did nothing - silently, exactly the way the claws themselves failed the first time + /// round (see the WarnOnce in MaintainInner). + /// + /// The icon is read off the cloned item rather than named here, so each race shows its own + /// claws and nobody has to remember to update a second list when a model changes. + /// + private void RegisterActiveStatusEffect(ItemDrop drop) + { + Sprite icon = drop != null && drop.m_itemData != null && drop.m_itemData.m_shared != null && + drop.m_itemData.m_shared.m_icons != null && drop.m_itemData.m_shared.m_icons.Length > 0 + ? drop.m_itemData.m_shared.m_icons[0] + : null; + + if (icon == null) + { + // Worth saying out loud: the effect still works and still counts down, but a buff + // with no icon is nearly invisible in the HUD, which would read as "the timer is + // broken" rather than "the sprite was missing". + Jotunn.Logger.LogWarning($"[{RaceId}] '{ItemName}' carries no icon, so the claws' buff will show without one."); + } + + StatusEffect se = ScriptableObject.CreateInstance(); + se.name = ActiveSeName; + se.m_name = DisplayName; + se.m_tooltip = "Your claws are out. They retract when this runs out."; + se.m_icon = icon; + + ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(se, fixReference: false)); + Jotunn.Logger.LogInfo($"[{RaceId}] Registered the claws' buff '{ActiveSeName}'."); + } + private GameObject ResolveModel() { foreach (string name in ModelPrefabs) @@ -308,6 +418,124 @@ namespace RacesOfValheim } } + // ─── Active skill: grow, then retract ───────────────────────────────── + + /// + /// Time.time at which the skill's current window ends. Starts in the past, so a set that + /// has never been activated - including a save carried over from before this was a timed + /// skill - reads as inactive and MaintainInner strips whatever leftover item it finds. + /// + private float activeUntil = -1f; + + /// True while the two-minute window is still running. + public bool IsActive => Time.time < activeUntil; + + /// Seconds left on the window, floored at zero. What the HUD timer counts down. + public float SecondsRemaining => Mathf.Max(0f, activeUntil - Time.time); + + /// + /// Published on the local player's own ZDO every Maintain tick, one flag shared by both + /// races (whichever set is running is the only one that could ever be true for a given + /// player, since a player is only ever one race). Read back for a REMOTE attacker in + /// ApplyToUnarmedHit - IsActive itself is this client's own timer and answers nothing about + /// somebody else's, the same problem GetState solves for progression tier. + /// + private const string ClawsActiveZdoKey = "RacesOfValheim_ClawsActive"; + + /// + /// Grows the claws for RaceClawsConfig.DurationSeconds. Safe to call again mid-window - it + /// just restarts the timer rather than stacking or refusing. + /// + public void Activate(Player player) + { + if (player == null || player != Player.m_localPlayer) return; + + // Logged rather than silent: this is the one path a keypress can go nowhere from, and + // "nothing happened" with no line in the log is exactly the failure mode that cost the + // registration timing bug an evening (see the comment in MaintainInner). + if (For(player) != this) + { + Jotunn.Logger.LogInfo( + $"[{RaceId}] Grow-claws key ignored: this player's race is not {RaceId} " + + $"({DescribeRaceSources(player)})."); + return; + } + if (player.IsDead()) + { + Jotunn.Logger.LogInfo($"[{RaceId}] Grow-claws key ignored: player is dead."); + return; + } + if (IsTransformed(player)) + { + Jotunn.Logger.LogInfo($"[{RaceId}] Grow-claws key ignored: player is currently transformed."); + return; + } + + activeUntil = Time.time + RaceClawsConfig.DurationSeconds.Value; + ApplyActiveIcon(RaceClawsConfig.DurationSeconds.Value); + Jotunn.Logger.LogInfo($"[{RaceId}] Grow-claws key pressed: growing the {DisplayName} for {RaceClawsConfig.DurationSeconds.Value}s."); + + // Issues and equips immediately rather than waiting for the next throttled Maintain + // tick, so the keypress reads as instant rather than landing up to half a second late. + Maintain(player); + + PlayGrowAnimation(player); + } + + /// + /// The draw gesture, so the claws arrive with a movement rather than simply being in hand + /// on the next frame. + /// + /// "equip_hip" is not a guess and not a borrowed approximation: it is the trigger vanilla's + /// own Humanoid.ShowHandItems fires when it takes a sheathed weapon back out, read out of + /// assembly_valheim rather than assumed. That makes it exactly the right motion here - the + /// claws are being drawn - and it carries no baked Animation Event, unlike the "gpower" + /// gesture the transformations borrow, which needed a suppressor to stop it casting the + /// player's real Guardian Power (see RaceInput.SuppressGuardianPowerBriefly). + /// + private static void PlayGrowAnimation(Player player) + { + ZSyncAnimation zanim = player.GetComponent(); + if (zanim != null) zanim.SetTrigger("equip_hip"); + } + + // ─── The buff the player sees ──────────────────────────────────────── + + /// + /// One effect per race rather than one shared between them, so each shows its own claws in + /// the buff bar. Derived from the item name, so a new clawed race needs nothing here. + /// + private string ActiveSeName => "SE_" + ItemName + "Active"; + + /// + /// Puts the buff up (or restarts it, if the skill was recast mid-window) and gives it the + /// remaining time. The countdown under the icon is the game's own - see + /// RegisterActiveStatusEffect. + /// + private void ApplyActiveIcon(float seconds) + { + if (Player.m_localPlayer == null || seconds <= 0f) return; + + int hash = ActiveSeName.GetStableHashCode(); + SEMan seman = Player.m_localPlayer.GetSEMan(); + seman.RemoveStatusEffect(hash, true); + seman.AddStatusEffect(hash, true); + + StatusEffect se = seman.GetStatusEffect(hash); + if (se != null) se.m_ttl = seconds; + } + + /// + /// Takes the buff down. The effect's own m_ttl already expires on its own when the window + /// runs out normally; this is for the retractions that happen off the clock - a race change, + /// or a form taken while the claws were still out. + /// + private void ClearActiveIcon(Player player) + { + if (player == null) return; + player.GetSEMan().RemoveStatusEffect(ActiveSeName.GetStableHashCode(), true); + } + // ─── Issue and re-equip ────────────────────────────────────────────── /// @@ -320,8 +548,9 @@ namespace RacesOfValheim private static bool maintaining; /// - /// Makes sure the player owns exactly one pair and is holding them whenever both hands are - /// free. Safe to call on a timer: every step checks first. + /// While the skill is active: makes sure the player owns exactly one pair and is holding + /// them whenever both hands are free. Once the window closes: takes that pair back off the + /// player entirely. Safe to call on a timer either way - every step checks first. /// public void Maintain(Player player) { @@ -340,11 +569,29 @@ namespace RacesOfValheim EnsureRegistered(); RefreshTint(); + ZNetView nview = player.GetComponent(); + if (nview != null && nview.IsValid()) nview.GetZDO().Set(ClawsActiveZdoKey, IsActive); + Inventory inventory = player.GetInventory(); if (inventory == null) return; ItemDrop.ItemData claws = Find(inventory); + // The window has closed (or never opened this session). Retract: unequip if still in + // hand, then remove the item outright - no slot sits occupied between activations, + // which is the entire point of moving this off the old "issued once, forever" design. + if (!IsActive) + { + if (claws != null) + { + if (player.IsItemEquiped(claws)) player.UnequipItem(claws, false); + inventory.RemoveItem(claws); + ClearActiveIcon(player); + Jotunn.Logger.LogInfo($"[{RaceId}] The {DisplayName} retracted."); + } + return; + } + if (claws == null) { GameObject prefab = ObjectDB.instance != null ? ObjectDB.instance.GetItemPrefab(ItemName) : null; @@ -469,7 +716,9 @@ namespace RacesOfValheim } /// - /// Rewrites a bare-handed blow into a claw blow, as slash and nothing else. + /// Rewrites a bare-handed blow into a claw blow, as slash and nothing else - but only while + /// the claws are actually the thing in hand, which since this became a timed skill is no + /// longer every unarmed hit by default. /// /// The figure is the Sverm's - its reference weapon at quality 4, times its percentage for /// this tier - but where the Sverm keeps the weapon's own three-way split, this collapses @@ -482,6 +731,22 @@ namespace RacesOfValheim if (hit == null || attacker == null) return; if (IsTransformed(attacker)) return; // the form is doing its own damage + // Outside the skill's window this is just a bare fist - vanilla's own unarmed damage, + // not the claw tier. IsActive answers for the local player; a remote Aswid/Fenrir's + // punch reads the same flag published on their own ZDO, the same fallback GetState + // uses for progression tier - inventories are not something a remote client can read. + bool active; + if (attacker == Player.m_localPlayer) + { + active = IsActive; + } + else + { + ZNetView nview = attacker.GetComponent(); + active = nview != null && nview.IsValid() && nview.GetZDO().GetBool(ClawsActiveZdoKey, false); + } + if (!active) return; + HitData.DamageTypes reference = SvermClaws.GetReferenceDamage(); float percent = SvermClaws.GetDamagePercent(GetState(attacker)); if (percent <= 0f) return; @@ -501,8 +766,9 @@ namespace RacesOfValheim // ─── Patches ───────────────────────────────────────────────────────────── /// - /// Issues the claws and puts them back in hand. On a throttle rather than every frame: it is a - /// handful of checks that all short-circuit once the claws exist. + /// Reads the activation key every frame (a keypress lasts one frame, so this cannot be + /// throttled), then issues/retracts the claws and puts them back in hand on a throttle - that + /// half is a handful of checks that all short-circuit once state matches the target. /// [HarmonyPatch(typeof(Player), "Update")] public static class RaceClaws_PlayerUpdate_Patch @@ -513,11 +779,27 @@ namespace RacesOfValheim public static void Postfix(Player __instance) { if (__instance != Player.m_localPlayer) return; + + RaceClawSet set = RaceClawSet.For(__instance); + + if (set == null) return; + + if (RaceClawsConfig.ActivateKey.Value.IsDown()) + { + if (RaceInput.Allowed) + { + set.Activate(__instance); + } + else + { + Jotunn.Logger.LogInfo($"[{set.RaceId}] Grow-claws key pressed but ignored: RaceInput.Allowed is false (a menu/GUI has focus)."); + } + } + if (Time.time < next) return; next = Time.time + Interval; - RaceClawSet set = RaceClawSet.For(__instance); - if (set != null) set.Maintain(__instance); + set.Maintain(__instance); } } @@ -591,9 +873,9 @@ namespace RacesOfValheim } /// - /// The tier's damage, on any bare-handed blow. Fist weapons report Unarmed, so this covers both - /// the equipped claws and an actually empty hand - which is what keeps the two halves of the - /// feature agreeing with each other. + /// The tier's damage, on any bare-handed blow - RaceClawSet.ApplyToUnarmedHit itself checks + /// whether the claws are actually equipped, so a genuinely empty hand (skill not running, or + /// still mid-retract) falls through to vanilla's own unarmed damage instead. /// [HarmonyPatch(typeof(Character), nameof(Character.Damage))] public static class RaceClaws_Damage_Patch diff --git a/JotunnModStub/RaceClawsConfig.cs b/JotunnModStub/RaceClawsConfig.cs new file mode 100644 index 0000000..5332d25 --- /dev/null +++ b/JotunnModStub/RaceClawsConfig.cs @@ -0,0 +1,33 @@ +using UnityEngine; +using BepInEx.Configuration; + +namespace RacesOfValheim +{ + /// + /// The one keybind and the one duration behind the Claws skill (RaceClaws.cs), shared by every + /// race that grows a pair rather than bound separately per race - there is only one skill here, + /// not one per race wearing it. Bound once, from RacesOfValheim.Awake(), alongside the other + /// non-race shared config (WarVultureConfig, ButlerConfig, ...). + /// + /// The default is K rather than O: O was the first pick, but Fenrir already owns it for Howl + /// (FenrirConfig.HowlKey), and colliding the two on one client would leave one of them dead + /// without any error to say why. Either can still be moved onto the other from Configuration + /// Manager if that turns out to be wanted after all. + /// + public static class RaceClawsConfig + { + public static ConfigEntry ActivateKey; + public static ConfigEntry DurationSeconds; + + public static void Bind(ConfigFile config) + { + const string keybinds = "Race Claws - Keybinds"; + ActivateKey = config.Bind(keybinds, "Grow Claws", new KeyboardShortcut(KeyCode.K), + new ConfigDescription("Grows the claws (Aswid: Claws of the Beast, Fenrir: Cursed Claws) for the duration below. Pressed again mid-window, restarts the timer instead of stacking.")); + + const string skill = "Race Claws - Skill"; + DurationSeconds = config.Bind(skill, "Duration", 120f, + new ConfigDescription("Seconds the claws stay grown before retracting on their own. The remaining time shows under the claws' own icon in the buff bar.", new AcceptableValueRange(10f, 600f))); + } + } +} diff --git a/JotunnModStub/RaceCompendium.cs b/JotunnModStub/RaceCompendium.cs index 7c9861e..1f232d0 100644 --- a/JotunnModStub/RaceCompendium.cs +++ b/JotunnModStub/RaceCompendium.cs @@ -328,10 +328,10 @@ namespace RacesOfValheim sb.AppendLine($"[Base Passive] Benedictus et Afflictus:"); sb.AppendLine($"Physical kills automatically consume enemies (Vae Victis) granting Blood Magic XP. Your physical stats scale progressively as you defeat Valheim's Bosses: +{arm} Armor, +{dmg} Damage, +{spd}% Speed, and +{jmp}% Jump. All your passive bonuses are doubled during the night. You can cast Blood Magic items with infinite Eitr, and your Blood Magic skill increases twice as fast.\n"); - sb.AppendLine("Vampiric Aura (Like a Bat out of Hell/Weight of Shadows Only): Block with your shield (Mouse 2) while in bat or mist form to channel an AoE magic damage aura against nearby enemies, healing for 20% of the damage dealt and converting them into food when they die.\n"); + sb.AppendLine("Vampiric Aura (Passive, [I] to toggle): A magic damage aura drains nearby enemies automatically, at all times and in every form - no key to hold. It deals half damage as a human, full as a bat, and double as mist, healing you for 20% of the damage dealt. Weakened enemies are executed outright and converted into food. It cannot tell traders from monsters, so switch it off with [I] before talking to Haldor or Hildir.\n"); // The live figure, so the entry cannot drift from the code: it is the same yardstick // the Sverm's own claws are measured against, which is what keeps the three races even. - sb.AppendLine($"[Base Passive] Claws of the Beast: Blackened claws you did not forge and cannot put down. Bare-handed blows land at {SvermClaws.GetDamagePercent(state) * 100f:0}% of a full-grown pair's weight, all of it as slash, and they grow with every boss that falls. Draw a sword and they wait; sheathe it and they are back. They cannot be dropped, traded or stolen - and in bat or mist form you have no hands to hold them with.\n"); + sb.AppendLine($"Claws of the Beast ([K], {RaceClawsConfig.DurationSeconds.Value:0}s): Grows blackened claws for a limited time instead of a weapon. Bare-handed blows land at {SvermClaws.GetDamagePercent(state) * 100f:0}% of a full-grown pair's weight, all of it as slash, and they grow with every boss that falls. Draw a sword and they wait, sheathe it and they are back, until the timer runs out and they retract on their own - no slot wasted between casts. They cannot be dropped, traded or stolen while grown - and in bat or mist form you have no hands to hold them with.\n"); if (state >= 1) { // Eikthyr - Base passives already covered @@ -373,7 +373,7 @@ namespace RacesOfValheim int arm = state * 3; int dmg = state * 5; knownTexts["Fenrir Secrets"] = $"The secrets of the pack will be revealed soon...\n\nBase Passive: Physical kills automatically consume enemies (if edible). Your physical stats scale progressively as you defeat Valheim's Bosses: +{arm} Armor, +{dmg} Damage, +{spd}% Speed, and +{jmp}% Jump.\n\n" + - $"[Base Passive] Cursed Claws: The wolf's hands, kept on in the man's shape. Bare-handed blows land at {SvermClaws.GetDamagePercent(state) * 100f:0}% of a full-grown pair's weight, all of it as slash, and they grow with every boss that falls. Draw a sword and they wait; sheathe it and they are back. They cannot be dropped, traded or stolen - and in beast form the jaws do the work instead."; + $"Cursed Claws ([K], {RaceClawsConfig.DurationSeconds.Value:0}s): The wolf's hands, kept on in the man's shape for a limited time instead of a weapon. Bare-handed blows land at {SvermClaws.GetDamagePercent(state) * 100f:0}% of a full-grown pair's weight, all of it as slash, and they grow with every boss that falls. Draw a sword and they wait, sheathe it and they are back, until the timer runs out and they retract on their own. They cannot be dropped, traded or stolen while grown - and in beast form the jaws do the work instead."; } private static void GenerateSkadiText(Dictionary knownTexts, int state) diff --git a/JotunnModStub/RacesOfValheim.cs b/JotunnModStub/RacesOfValheim.cs index 18d25ab..c9c1a14 100644 --- a/JotunnModStub/RacesOfValheim.cs +++ b/JotunnModStub/RacesOfValheim.cs @@ -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.4"; + public const string PluginVersion = "1.4.5"; private readonly Harmony harmony = new Harmony(PluginGUID); @@ -46,6 +46,9 @@ namespace RacesOfValheim // Not a race either: the two Bone Servants, shared by the Skeleton and Skadi, so they // bind here rather than inside either race's run. ButlerConfig.Bind(Config); + // Not a race either: the Claws skill Aswid and Fenrir share, so it binds here rather + // than inside either race's run. + RaceClawsConfig.Bind(Config); harmony.PatchAll(); gameObject.AddComponent(); gameObject.AddComponent(); diff --git a/JotunnModStub/Skadi/SkadiPatches.cs b/JotunnModStub/Skadi/SkadiPatches.cs index 7e1c3cd..d8d1cb6 100644 --- a/JotunnModStub/Skadi/SkadiPatches.cs +++ b/JotunnModStub/Skadi/SkadiPatches.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using System.Reflection; using HarmonyLib; using UnityEngine; @@ -158,9 +159,16 @@ namespace RacesOfValheim // SkadiSEManPatch above from tier 1 onward, so the tier 2 "Freezing to Cold" conversion never // gets a chance to run. These two patches scope out just that one environmental check: while // Player.UpdateEnvStatusEffects is running for the local Skadi player, GetDamageModifiers is - // reported as Normal for Frost, so vanilla always attempts to apply the real status and - // SkadiSEManPatch's per-tier logic (block/convert/allow) is what actually decides the outcome. - // Frost damage resistance from hits (SkadiDamagePatch) is untouched by this. + // reported without SE_SkadiStats' own Frost contribution, so vanilla attempts to apply the + // real status and SkadiSEManPatch's per-tier logic (block/convert/allow) is what actually + // decides the outcome. Frost damage resistance from hits (SkadiDamagePatch) is untouched. + // + // Only the race's own contribution is discounted. This used to report a flat Normal, which + // also erased Frost resistance coming from a wolf/lox cape, a frost resistance mead or food: + // a Skadi who had beaten Moder still caught the converted Cold on the Mountain while wearing + // gear that makes a human immune, and below tier 4 caught real Freezing through the same gear. + // The tiered ladder is meant to make the race better than a bare human, never worse than an + // equipped one, so anything the player is actually wearing or drinking still counts. [HarmonyPatch(typeof(Player), "UpdateEnvStatusEffects")] public static class SkadiEnvCheckScope { @@ -180,11 +188,38 @@ namespace RacesOfValheim [HarmonyPatch(typeof(Character), "GetDamageModifiers")] public static class SkadiEnvFrostModifierPatch { + private static readonly int SkadiStatsHash = "SE_SkadiStats".GetStableHashCode(); + // Handed to the aura in place of its own list while the recompute runs. SE_Stats applies + // m_mods as-is, so an empty list is simply "this effect grants nothing". + private static readonly List NoMods = new List(); + private static bool recomputing = false; + public static void Postfix(Character __instance, ref HitData.DamageModifiers __result) { - if (SkadiEnvCheckScope.Active && __instance == Player.m_localPlayer) + if (recomputing) return; + if (!SkadiEnvCheckScope.Active || __instance != Player.m_localPlayer) return; + + // Character.GetDamageModifiers composes base modifiers + equipment + status effects, + // and DamageModifiers.Apply keeps the strongest of the lot - there is no way to + // subtract one contributor from a finished result. So the aura is muted and the whole + // thing recomputed: what comes back is exactly what this player would have without + // the race. The recursive call re-enters this postfix, which the flag turns into a + // no-op. The status effect on the player is a clone of the registered prototype + // (SEMan.AddStatusEffect clones on add), hence the lookup by hash rather than + // SkadiRace.skadiCurseSE. + SE_Stats aura = __instance.GetSEMan().GetStatusEffect(SkadiStatsHash) as SE_Stats; + List auraMods = aura != null ? aura.m_mods : null; + + recomputing = true; + if (aura != null) aura.m_mods = NoMods; + try { - __result.m_frost = HitData.DamageModifier.Normal; + __result.m_frost = __instance.GetDamageModifiers(null).m_frost; + } + finally + { + if (aura != null) aura.m_mods = auraMods; + recomputing = false; } } } diff --git a/JotunnModStub/Skadi/SkadiRace.cs b/JotunnModStub/Skadi/SkadiRace.cs index 63fe55c..7980895 100644 --- a/JotunnModStub/Skadi/SkadiRace.cs +++ b/JotunnModStub/Skadi/SkadiRace.cs @@ -167,11 +167,24 @@ namespace RacesOfValheim // Update the stats SE if (skadiCurseSE != null) { + int auraHash = skadiCurseSE.name.GetStableHashCode(); + SEMan seman = Player.m_localPlayer.GetSEMan(); + skadiCurseSE.UpdateStats(rules); - if (!Player.m_localPlayer.GetSEMan().HaveStatusEffect(skadiCurseSE.name.GetStableHashCode())) + if (!seman.HaveStatusEffect(auraHash)) { - Player.m_localPlayer.GetSEMan().AddStatusEffect(skadiCurseSE.name.GetStableHashCode(), true); + seman.AddStatusEffect(auraHash, true); } + + // SEMan.AddStatusEffect stores a Clone() of the prototype, so updating + // skadiCurseSE alone only changed the copy that gets stamped out at the next add: + // the aura already running on the player kept whatever tier it was born with. + // Beating a boss mid-session left the old frost modifier and eitr regen in place + // until the effect was re-added (race reselection or a relog) - most visibly at + // the Queen, where Immune never replaced Resistant. Refresh the live one as well; + // UpdateStats is a no-op unless the tier actually moved a value. + SE_SkadiStats liveAura = seman.GetStatusEffect(auraHash) as SE_SkadiStats; + if (liveAura != null) liveAura.UpdateStats(rules); } if (rules.FrostAura) diff --git a/JotunnModStub/Skadi/SkadiStatusEffects.cs b/JotunnModStub/Skadi/SkadiStatusEffects.cs index dc6e3ee..00a7e56 100644 --- a/JotunnModStub/Skadi/SkadiStatusEffects.cs +++ b/JotunnModStub/Skadi/SkadiStatusEffects.cs @@ -27,8 +27,29 @@ namespace RacesOfValheim m_tooltip = "Empowered by the frost."; } + // What the last UpdateStats call actually wrote. SEMan.AddStatusEffect stores a Clone() of + // the registered prototype, so the effect running on the player is a separate object that + // has to be refreshed too (SkadiRace.Update does that) - and both of them are asked to + // update every frame. Rebuilding the mod list each time would churn a List per frame per + // instance, so nothing is rewritten until a tier change actually moves a value. These + // fields are not serialized, so a fresh clone starts at "never applied" and rebuilds once. + private bool statsApplied = false; + private float appliedFrostResistance = 0f; + private float appliedEitrRegenMultiplier = 0f; + public void UpdateStats(SkadiProgression.FormRules rules) { + if (statsApplied && + rules.FrostResistance == appliedFrostResistance && + rules.EitrRegenMultiplier == appliedEitrRegenMultiplier) + { + return; + } + + statsApplied = true; + appliedFrostResistance = rules.FrostResistance; + appliedEitrRegenMultiplier = rules.EitrRegenMultiplier; + m_mods = new List(); if (rules.FrostResistance >= 1f) { diff --git a/README.md b/README.md index adafefb..e6d041d 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ Full details under [Sverm](#10-sverm) and [Sverm Progression](#race-progressions ![Fenrir3](https://wiki.aledanidev.ovh/assets/images/fenrir3.gif) - **Beast Form:** Transform into a wolf-like beast. - **Cultist Form:** Transform into a Cultist to use fire abilities. -- **Cursed Claws:** The wolf's hands, kept on in the man's shape — see [Permanent Claws](#permanent-claws). +- **Cursed Claws:** The wolf's hands, kept on in the man's shape — see [Claws](#claws). - **A Pack of Your Own:** The Pack Trough keeps a standing pack of wolves, ulvs and, late, fenrir — see [Race Stations](#race-stations--companions). - **Progression:** Forms grow as you defeat bosses, unlocking new powers and reducing cooldowns. Immune to fall damage. @@ -53,10 +53,10 @@ Full details under [Sverm](#10-sverm) and [Sverm Progression](#race-progressions ![Aswid](https://wiki.aledanidev.ovh/assets/images/aswidchallenge.gif) - **The Vampire:** Life-draining abilities. - **Bat Form:** Press G to become a bat and fly. -- **Blood Magic:** Block to activate a life-draining aura (radius doubled at night, only in Bat or Mist Form). +- **Vampiric Aura:** A passive life-draining aura around you, always on in every form (half damage as human, full as bat, double as mist) — no key to hold. Press **[I]** to toggle it (and Devour) off, e.g. before trading with Haldor or Hildir, since it does not recognize traders from monsters. - **Blood Magic Mastery:** Cast Blood Magic items with infinite Eitr (health cost only). - **Benedictus et Afflictus:** Passive speed/jump bonuses double at night. -- **Claws of the Beast:** Blackened claws you did not forge and cannot put down — see [Permanent Claws](#permanent-claws). +- **Claws of the Beast:** Press [K] to grow blackened claws for a limited time — see [Claws](#claws). - **Burning Eyes:** Spectral green sockets, smoke trailing off them, that hold a red glow only in the final stage. - **Undead Vigor:** Infinite stamina. Consume the lifeforce of enemies instead of eating normal food. @@ -95,7 +95,7 @@ Full details under [Sverm](#10-sverm) and [Sverm Progression](#race-progressions ### 10. Sverm - **Chitin Plating:** You never dress. Chest, legs and helm are carapace worth a full set of the biome ahead of you at every tier — best quality, weightless, no movement penalty. Only cloak and trinket may still be worn. -- **Chitin Claws:** Your hands are the weapon — see [Permanent Claws](#permanent-claws). +- **Chitin Claws:** Your hands are the weapon — see [Claws](#claws). - **Hive Pheromones:** No invertebrate attacks you — leeches, ticks, deathsquitos, seekers and bees all ignore you, from tier zero. - **Toxin Immunity:** Poison cannot touch you. Blunt and fire hit you 40% harder — until Fader, when the fire weakness burns out and comes back as a resistance. - **The Colony:** After the Elder, a Brood Mound, a Hive Market and a roster of insect troops bought with digested biomass. @@ -103,13 +103,15 @@ Full details under [Sverm](#10-sverm) and [Sverm Progression](#race-progressions --- -## Permanent Claws +## Claws -Three races grow a pair of their own. The terms are identical for all three: issued once, never dropped or traded, refused by the holster key, and back in your hands the moment your hands are free — draw a sword and the claws wait, sheathe it and they are back. Damage is measured against **one** yardstick rather than against the models each race wears, so the same tier is worth the same whichever race you are, and it climbs with every boss. No pair counts while you are wearing another body: a bat, a mist, a wolf or a deathsquito does its own damage with its own hands. +Three races grow a pair of their own, refused by the holster key and never draggable, moveable or dropped while grown — draw a sword and the claws wait, sheathe it and they are back. Damage is measured against **one** yardstick rather than against the models each race wears, so the same tier is worth the same whichever race you are, and it climbs with every boss. No pair counts while you are wearing another body: a bat, a mist, a wolf or a deathsquito does its own damage with its own hands. - **Aswid — Claws of the Beast:** burned almost black. Lands the whole of it as slash. - **Fenrir — Cursed Claws:** the flesh rippers worn as the game made them. Also pure slash. -- **Sverm — Chitin Claws:** splits the same weight three ways, and sets it alight at Fader. +- **Sverm — Chitin Claws:** splits the same weight three ways, and sets it alight at Fader. Permanent, like the rest of the Sverm's carapace — never times out. + +**Aswid and Fenrir claws are a timed skill, not a permanent fixture:** press **[K]** to grow them for 120 seconds (configurable in Configuration Manager under "Race Claws"); casting again mid-window restarts the timer instead of stacking. When time runs out they retract and are removed from your inventory outright, so they never sit as a dead, unremovable item in a slot between fights. The damage bonus only applies while they are actually equipped. --- @@ -402,6 +404,13 @@ The **Sverm** belongs to no faction. Its Hive Pheromones make every invertebrate ## Changelog +### v1.4.5 +- **CHANGED - Claws are now a timed skill (Aswid & Fenrir):** press **[K]** to grow Claws of the Beast / Cursed Claws for 120 seconds (configurable) instead of holding them forever — they retract and are removed from your inventory when the timer ends, so they never sit as a permanent dead item in a slot. The damage bonus only applies while they're actually equipped. Sverm's Chitin Claws are untouched and stay permanent. Along the way, fixed the Fenrir claws never registering at all (a .NET static-initialization order bug that left Fenrir's set out of the roster while Aswid's worked fine) and a race-detection bug where "Human" written to the ZDO by `resetrace` could shadow a correctly-chosen race. +- **Fix - Vampiric Aura vs traders (Aswid):** the passive aura doesn't distinguish traders from monsters and could execute Haldor, Hildir or other faction merchants on approach. Press **[I]** (same key as Devour) to toggle the Aura off before trading. +- **Fix - Skadi cold resistance:** the race's own frost-check patch was zeroing out *all* frost resistance during the environmental check, including a wolf/lox cape, frost resistance mead or food — so a Skadi with that gear still froze or caught Cold where an equipped human wouldn't. Now only the race's own passive contribution is discounted; worn/drunk resistance counts again. +- **Fix - Skadi aura mid-session:** frost immunity and the Eitr regen bonus only updated on the next relog after a boss kill, because the live status effect was a frozen clone of the one last rebuilt. Both now update immediately — most noticeable at the Queen tier, where Immune replaces Resistant instantly. +- **Compendium/README:** Vampiric Aura and Claws entries rewritten to match current behavior — no longer describe the old block-to-channel aura or the old always-permanent claws. + ### v1.4.4 - **NEW - Bone Servants (Skeleton & Skadi):** two disarmed skeletons, the **Bone Smith** and the **Bone Cook**, summoned at their own table to fetch material from marked chests and keep nearby stations fed — the Smith works the Forge family for Skeleton or Skadi, the Cook works cooking stations and the fermenter for Skadi alone. Full details under [Skeleton & Skadi — Bone Servants](#skeleton--skadi--bone-servants). - **Fix - Race Change:** switching race no longer leaves permanent claws (Aswid, Fenrir, Sverm) stuck in your inventory — resetting your race now strips them along with the rest of that race's stats. diff --git a/manifest.json b/manifest.json index 660f981..78d5bdf 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "name": "RacesOfValheim", "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.4", + "version_number": "1.4.5", "website_url": "", "dependencies": [ "denikson-BepInExPack_Valheim-5.4.2333",