warvulture

This commit is contained in:
Ferdinando 2026-08-18 16:51:07 +02:00
commit 4559e0b9e1
14 changed files with 455 additions and 48 deletions

View file

@ -5,9 +5,10 @@ namespace RacesOfValheim
/// <summary>
/// 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

View file

@ -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,

View file

@ -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);
}

View file

@ -832,11 +832,18 @@ namespace RacesOfValheim
private float damageTickTimer = 0f;
/// <summary>
/// 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.
/// </summary>
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)

View file

@ -5,9 +5,10 @@ namespace RacesOfValheim
/// <summary>
/// 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.

View file

@ -1,33 +1,42 @@
using System.Collections.Generic;
using HarmonyLib;
using Jotunn.Entities;
using Jotunn.Managers;
using UnityEngine;
namespace RacesOfValheim
{
/// <summary>
/// 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.
/// </summary>
public abstract class RaceClawSet
{
@ -69,21 +78,52 @@ namespace RacesOfValheim
// ─── Registry ────────────────────────────────────────────────────────
private static readonly List<RaceClawSet> sets = new List<RaceClawSet>();
private static bool rosterBuilt;
/// <summary>
/// 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.
/// </summary>
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<string> names = new List<string>();
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
/// <summary>
/// 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.
/// </summary>
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";
}
/// <summary>
/// Both raw values the race is read from, for the diagnostic line. Kept next to GetRace so
/// the two cannot drift apart.
/// </summary>
internal static string DescribeRaceSources(Player player)
{
if (player == null) return "player is null";
ZNetView nview = player.GetComponent<ZNetView>();
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();
}
/// <summary>
/// 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.
/// </summary>
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<StatusEffect>();
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 ─────────────────────────────────
/// <summary>
/// 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.
/// </summary>
private float activeUntil = -1f;
/// <summary>True while the two-minute window is still running.</summary>
public bool IsActive => Time.time < activeUntil;
/// <summary>Seconds left on the window, floored at zero. What the HUD timer counts down.</summary>
public float SecondsRemaining => Mathf.Max(0f, activeUntil - Time.time);
/// <summary>
/// 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.
/// </summary>
private const string ClawsActiveZdoKey = "RacesOfValheim_ClawsActive";
/// <summary>
/// Grows the claws for RaceClawsConfig.DurationSeconds. Safe to call again mid-window - it
/// just restarts the timer rather than stacking or refusing.
/// </summary>
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);
}
/// <summary>
/// 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).
/// </summary>
private static void PlayGrowAnimation(Player player)
{
ZSyncAnimation zanim = player.GetComponent<ZSyncAnimation>();
if (zanim != null) zanim.SetTrigger("equip_hip");
}
// ─── The buff the player sees ────────────────────────────────────────
/// <summary>
/// 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.
/// </summary>
private string ActiveSeName => "SE_" + ItemName + "Active";
/// <summary>
/// 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.
/// </summary>
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;
}
/// <summary>
/// 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.
/// </summary>
private void ClearActiveIcon(Player player)
{
if (player == null) return;
player.GetSEMan().RemoveStatusEffect(ActiveSeName.GetStableHashCode(), true);
}
// ─── Issue and re-equip ──────────────────────────────────────────────
/// <summary>
@ -320,8 +548,9 @@ namespace RacesOfValheim
private static bool maintaining;
/// <summary>
/// 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.
/// </summary>
public void Maintain(Player player)
{
@ -340,11 +569,29 @@ namespace RacesOfValheim
EnsureRegistered();
RefreshTint();
ZNetView nview = player.GetComponent<ZNetView>();
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
}
/// <summary>
/// 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<ZNetView>();
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 ─────────────────────────────────────────────────────────────
/// <summary>
/// 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.
/// </summary>
[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
}
/// <summary>
/// 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.
/// </summary>
[HarmonyPatch(typeof(Character), nameof(Character.Damage))]
public static class RaceClaws_Damage_Patch

View file

@ -0,0 +1,33 @@
using UnityEngine;
using BepInEx.Configuration;
namespace RacesOfValheim
{
/// <summary>
/// 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.
/// </summary>
public static class RaceClawsConfig
{
public static ConfigEntry<KeyboardShortcut> ActivateKey;
public static ConfigEntry<float> 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<float>(10f, 600f)));
}
}
}

View file

@ -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<string, string> knownTexts, int state)

View file

@ -15,7 +15,7 @@ namespace RacesOfValheim
{
public const string PluginGUID = "com.nandor.racesofvalheim";
public const string PluginName = "Races Of Valheim";
public const string PluginVersion = "1.4.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<FenrirRace>();
gameObject.AddComponent<SkadiRace>();

View file

@ -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<HitData.DamageModPair> NoMods = new List<HitData.DamageModPair>();
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<HitData.DamageModPair> 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;
}
}
}

View file

@ -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)

View file

@ -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<HitData.DamageModPair>();
if (rules.FrostResistance >= 1f)
{