From d9bca1934fb9b5df8b78ba258e4d58d0a07c40a5 Mon Sep 17 00:00:00 2001 From: kanym Date: Fri, 6 Nov 2026 21:21:11 +0100 Subject: [PATCH 1/5] fix(skills): hand-built attacks level the skill they scale with Form attacks and powers called Damage directly, and vanilla only raises a skill inside Attack and Projectile.OnHit, so the skill never moved. FormMelee.RaiseSkill pays once per swing or tick that hit a creature. - Fenrir forms' claws and bites: Unarmed; Cultist fire: Elemental Magic - Skadi drake melee and Trenta stomp: Unarmed - Aswid aura: Blood Magic, 0.1 per second like the Frost Aura - Alfar Geisli and Ljosstorm: Elemental Magic; Sameining pulse 0.1/s - Trenta Purple Rain scales with Blood Magic (two new bonus keys) and levels it once per cast that reaches someone besides the caster --- JotunnModStub/Alfar/AlfarArchon.cs | 5 ++++- JotunnModStub/Alfar/AlfarPowers.cs | 20 ++++++++++++++++--- JotunnModStub/Aswid/AswidRace.cs | 7 +++++++ JotunnModStub/Fenrir/FenrirBehaviors.cs | 20 +++++++++++++++++++ JotunnModStub/Fenrir/FenrirFormShared.cs | 15 ++++++++++++++ JotunnModStub/RaceCompendium.cs | 4 ++-- JotunnModStub/Skadi/DrakeFormBehavior.cs | 4 ++++ JotunnModStub/Trenta/TrentaAbilities.cs | 17 +++++++++++++--- JotunnModStub/Trenta/TrentaConfig.cs | 10 ++++++++++ .../Trenta/TrentaConfigManagement.cs | 6 ++++++ JotunnModStub/Trenta/TrentaMuspell.cs | 6 ++++++ 11 files changed, 105 insertions(+), 9 deletions(-) diff --git a/JotunnModStub/Alfar/AlfarArchon.cs b/JotunnModStub/Alfar/AlfarArchon.cs index 0be4415..079d7a6 100644 --- a/JotunnModStub/Alfar/AlfarArchon.cs +++ b/JotunnModStub/Alfar/AlfarArchon.cs @@ -119,7 +119,10 @@ namespace RacesOfValheim if (Time.time >= nextPulse) { nextPulse = Time.time + AlfarPowerConfig.ArchonPulseInterval.Value; - AlfarPowers.Pulse(player, AlfarPowerConfig.ArchonPulseRadius.Value, AlfarPowerConfig.ArchonPulseDamage.Value); + // The pulse fires on its own while the form lasts, so it earns what an aura does: + // a tenth of a hit per second, once per pulse that struck something. + if (AlfarPowers.Pulse(player, AlfarPowerConfig.ArchonPulseRadius.Value, AlfarPowerConfig.ArchonPulseDamage.Value)) + FormMelee.RaiseSkill(Skills.SkillType.ElementalMagic, 0.1f * AlfarPowerConfig.ArchonPulseInterval.Value); } } diff --git a/JotunnModStub/Alfar/AlfarPowers.cs b/JotunnModStub/Alfar/AlfarPowers.cs index 82aca06..6b0ea70 100644 --- a/JotunnModStub/Alfar/AlfarPowers.cs +++ b/JotunnModStub/Alfar/AlfarPowers.cs @@ -148,12 +148,17 @@ namespace RacesOfValheim } /// A pulse of lightning on every hostile creature within a radius of the Alfr. - public static void Pulse(Player player, float radius, float damage) + /// True if it struck at least one creature. + public static bool Pulse(Player player, float radius, float damage) { + bool struck = false; foreach (Character character in CharactersIn(player.transform.position, radius)) { - if (IsHostile(player, character)) Strike(player, character, damage, character.GetCenterPoint()); + if (!IsHostile(player, character)) continue; + Strike(player, character, damage, character.GetCenterPoint()); + struck = true; } + return struck; } private static IEnumerable CharactersIn(Vector3 center, float radius) @@ -396,7 +401,11 @@ namespace RacesOfValheim AlfarEitr.Spend(player, cost); } - if (IsHostile(player, target)) Strike(player, target, AlfarPowerConfig.BeamDps.Value * tick, end); + if (IsHostile(player, target)) + { + Strike(player, target, AlfarPowerConfig.BeamDps.Value * tick, end); + FormMelee.RaiseSkill(Skills.SkillType.ElementalMagic, tick); // a full hit per second on target + } } private static void RaiseHand(Player player) @@ -548,14 +557,19 @@ namespace RacesOfValheim const float tick = 0.5f; nextTick = Time.time + tick; + bool struck = false; foreach (Collider collider in Physics.OverlapSphere(transform.position, Radius, ~0, QueryTriggerInteraction.Ignore)) { Character character = collider.GetComponentInParent(); if (character == null || character == Owner || character.IsDead() || character.IsTamed()) continue; if (!BaseAI.IsEnemy(Owner, character)) continue; AlfarPowers.Strike(Owner, character, DamagePerSecond * tick, character.GetCenterPoint()); + struck = true; } + // Once per tick, not per creature: a full hit per second the storm strikes something. + if (struck && Owner == Player.m_localPlayer) FormMelee.RaiseSkill(Skills.SkillType.ElementalMagic, tick); + Vector2 offset = Random.insideUnitCircle * Radius; AlfarFx.Spawn("fx_JotunWitch_LightningBolt_Explosion", transform.position + new Vector3(offset.x, 0f, offset.y)); } diff --git a/JotunnModStub/Aswid/AswidRace.cs b/JotunnModStub/Aswid/AswidRace.cs index d05d8bb..8367a64 100644 --- a/JotunnModStub/Aswid/AswidRace.cs +++ b/JotunnModStub/Aswid/AswidRace.cs @@ -1191,6 +1191,7 @@ namespace RacesOfValheim int layerMask = LayerMask.GetMask("character", "character_net", "character_ghost"); var colliders = Physics.OverlapSphere(center, radius, layerMask); + bool hitCreature = false; foreach (var col in colliders) { @@ -1241,10 +1242,16 @@ namespace RacesOfValheim // kill). ApplyDamage() skipped all of that: it edited the local copy of a // character we usually do not own, and the owner overwrote it on the next sync. c.Damage(hd); + hitCreature = true; SpawnBloodVFX(c); } } + + // The aura scales with Blood Magic but called Damage directly, so it never paid + // the skill back. Passive and always on, so it earns what the Skadi's Frost Aura + // does: a tenth of a hit per second of draining, once per tick, not per victim. + if (hitCreature) FormMelee.RaiseSkill(Skills.SkillType.BloodMagic, 0.1f * AswidConfig.AuraTickInterval.Value); } catch (Exception ex) { diff --git a/JotunnModStub/Fenrir/FenrirBehaviors.cs b/JotunnModStub/Fenrir/FenrirBehaviors.cs index b702a20..d0dd0cd 100644 --- a/JotunnModStub/Fenrir/FenrirBehaviors.cs +++ b/JotunnModStub/Fenrir/FenrirBehaviors.cs @@ -774,6 +774,7 @@ namespace RacesOfValheim Collider[] hits = Physics.OverlapSphere(attackPoint, attackRadius, layerMask); FormMelee.LogSwing(FormLabel, hits.Length); System.Collections.Generic.HashSet hitObjects = new System.Collections.Generic.HashSet(); + bool hitCreature = false; foreach (Collider hit in hits) { @@ -823,10 +824,13 @@ namespace RacesOfValheim FormMelee.LogHit(FormLabel, target, totalDamage); target.Damage(hitData); FormMelee.GrantAdrenaline(target); + if (target is Character) hitCreature = true; } } } } + + if (hitCreature) FormMelee.RaiseSkill(Skills.SkillType.Unarmed); } } @@ -1067,6 +1071,7 @@ namespace RacesOfValheim Collider[] hits = Physics.OverlapSphere(attackPoint, attackRadius, layerMask); FormMelee.LogSwing(FormLabel, hits.Length); System.Collections.Generic.HashSet hitObjects = new System.Collections.Generic.HashSet(); + bool hitCreature = false; foreach (Collider hit in hits) { @@ -1106,6 +1111,7 @@ namespace RacesOfValheim FormMelee.LogHit(FormLabel, target, totalDamage); target.Damage(hitData); FormMelee.GrantAdrenaline(target, 0.2f); // one 0.2s tick: a full hit per second of breath + if (target is Character) hitCreature = true; if (ZNetScene.instance != null) { @@ -1115,6 +1121,8 @@ namespace RacesOfValheim } } } + + if (hitCreature) FormMelee.RaiseSkill(Skills.SkillType.ElementalMagic, 0.2f); // one 0.2s tick: a full swing's worth per second of breath } private IEnumerator ClawRoutine() @@ -1231,6 +1239,7 @@ namespace RacesOfValheim Collider[] hits = Physics.OverlapSphere(attackPoint, attackRadius, layerMask); FormMelee.LogSwing(FormLabel, hits.Length); System.Collections.Generic.HashSet hitObjects = new System.Collections.Generic.HashSet(); + bool hitCreature = false; foreach (Collider hit in hits) { @@ -1280,10 +1289,13 @@ namespace RacesOfValheim FormMelee.LogHit(FormLabel, target, totalDamage); target.Damage(hitData); FormMelee.GrantAdrenaline(target); + if (target is Character) hitCreature = true; } } } } + + if (hitCreature) FormMelee.RaiseSkill(Skills.SkillType.Unarmed); } } @@ -1446,6 +1458,7 @@ namespace RacesOfValheim Collider[] hits = Physics.OverlapSphere(attackPoint, attackRadius, layerMask); FormMelee.LogSwing(FormLabel, hits.Length); System.Collections.Generic.HashSet hitObjects = new System.Collections.Generic.HashSet(); + bool hitCreature = false; foreach (Collider hit in hits) { @@ -1495,10 +1508,13 @@ namespace RacesOfValheim FormMelee.LogHit(FormLabel, target, totalDamage); target.Damage(hitData); FormMelee.GrantAdrenaline(target); + if (target is Character) hitCreature = true; } } } } + + if (hitCreature) FormMelee.RaiseSkill(Skills.SkillType.Unarmed); } } @@ -1654,6 +1670,7 @@ namespace RacesOfValheim Collider[] hits = Physics.OverlapSphere(attackPoint, attackRadius, layerMask); FormMelee.LogSwing(FormLabel, hits.Length); System.Collections.Generic.HashSet hitObjects = new System.Collections.Generic.HashSet(); + bool hitCreature = false; foreach (Collider hit in hits) { @@ -1703,10 +1720,13 @@ namespace RacesOfValheim FormMelee.LogHit(FormLabel, target, totalDamage); target.Damage(hitData); FormMelee.GrantAdrenaline(target); + if (target is Character) hitCreature = true; } } } } + + if (hitCreature) FormMelee.RaiseSkill(Skills.SkillType.Unarmed); } private IEnumerator UlvJumpAttackRoutine() diff --git a/JotunnModStub/Fenrir/FenrirFormShared.cs b/JotunnModStub/Fenrir/FenrirFormShared.cs index a26c6ed..259fc08 100644 --- a/JotunnModStub/Fenrir/FenrirFormShared.cs +++ b/JotunnModStub/Fenrir/FenrirFormShared.cs @@ -368,6 +368,21 @@ namespace RacesOfValheim player.AddAdrenaline(perHit * character.m_enemyAdrenalineMultiplier * scale); } + /// + /// The skill experience vanilla gives for a weapon hit, which a hand-built hit never got. + /// Vanilla raises the skill inside Attack (once per swing that landed on a creature) and + /// inside Projectile.OnHit; Character.Damage never does, so a form that calls Damage + /// directly left its skill at whatever level the player brought in. Call it once per + /// swing or tick, after the loop, never once per target. amount lets a damage-over-time + /// tick pay a fraction of a swing. + /// + public static void RaiseSkill(Skills.SkillType skill, float amount = 1f) + { + Player player = Player.m_localPlayer; + if (player == null || amount <= 0f) return; + player.RaiseSkill(skill, amount); + } + /// /// Charges a form attack's stamina the way vanilla charges a weapon's (Attack.GetAttackStamina): /// the equipment modifier, status effects (meads, race passives), then up to a third off with diff --git a/JotunnModStub/RaceCompendium.cs b/JotunnModStub/RaceCompendium.cs index c609ab2..1505ac1 100644 --- a/JotunnModStub/RaceCompendium.cs +++ b/JotunnModStub/RaceCompendium.cs @@ -874,8 +874,8 @@ namespace RacesOfValheim int foodDuration = Mathf.RoundToInt(TrentaConfig.FoodDurationMultiplier); int purpleRainRadius = Mathf.RoundToInt(TrentaConfig.PurpleRainRadius); - int purpleRainHeal = Mathf.RoundToInt(TrentaConfig.PurpleRainHealAmount); - int purpleRainPoison = Mathf.RoundToInt(TrentaConfig.PurpleRainPoisonDamage); + int purpleRainHeal = Mathf.RoundToInt(TrentaConfig.PurpleRainHealFor(Player.m_localPlayer)); + int purpleRainPoison = Mathf.RoundToInt(TrentaConfig.PurpleRainPoisonFor(Player.m_localPlayer)); int purpleRainCooldown = Mathf.RoundToInt(TrentaConfigManagement.PurpleRainCooldown.Value); int purpleRainMuspellCooldown = Mathf.RoundToInt(TrentaConfigManagement.MuspellPurpleRainCooldown.Value); diff --git a/JotunnModStub/Skadi/DrakeFormBehavior.cs b/JotunnModStub/Skadi/DrakeFormBehavior.cs index eeed348..f1335bf 100644 --- a/JotunnModStub/Skadi/DrakeFormBehavior.cs +++ b/JotunnModStub/Skadi/DrakeFormBehavior.cs @@ -599,6 +599,7 @@ namespace RacesOfValheim int layerMask = LayerMask.GetMask("Default", "static_solid", "Default_small", "piece", "piece_nonsolid", "terrain", "character", "character_net", "character_ghost", "hitbox", "character_noenv", "vehicle"); Collider[] hits = Physics.OverlapSphere(attackPoint, radius, layerMask); System.Collections.Generic.HashSet hitObjects = new System.Collections.Generic.HashSet(); + bool hitCreature = false; foreach (Collider hit in hits) { @@ -641,7 +642,10 @@ namespace RacesOfValheim target.Damage(hitData); FormMelee.GrantAdrenaline(target); + if (characterTarget != null) hitCreature = true; } + + if (hitCreature) FormMelee.RaiseSkill(Skills.SkillType.Unarmed); } private void OnDestroy() diff --git a/JotunnModStub/Trenta/TrentaAbilities.cs b/JotunnModStub/Trenta/TrentaAbilities.cs index 3809865..088ec3a 100644 --- a/JotunnModStub/Trenta/TrentaAbilities.cs +++ b/JotunnModStub/Trenta/TrentaAbilities.cs @@ -196,7 +196,14 @@ namespace RacesOfValheim // The Trenta stands in its own rain and is healed by it too. It used to be left out, so // a lone Trenta cast a heal that never touched anyone. - player.Heal(TrentaConfig.PurpleRainHealAmount, true); + float heal = TrentaConfig.PurpleRainHealFor(player); + float poison = TrentaConfig.PurpleRainPoisonFor(player); + player.Heal(heal, true); + + // Blood Magic experience once per cast that reached someone besides the caster, the + // way a vanilla staff pays per cast: healing only yourself earns nothing, or the + // skill would level by casting into an empty field on cooldown. + bool reachedSomeone = false; HashSet hit = new HashSet(); foreach (Collider collider in Physics.OverlapSphere(player.transform.position, TrentaConfig.PurpleRainRadius)) @@ -209,16 +216,20 @@ namespace RacesOfValheim if (BaseAI.IsEnemy(player, character)) { HitData hitData = new HitData(); - hitData.m_damage.m_poison = TrentaConfig.PurpleRainPoisonDamage; + hitData.m_damage.m_poison = poison; + hitData.m_skill = Skills.SkillType.BloodMagic; hitData.SetAttacker(player); hitData.m_dir = Vector3.zero; character.Damage(hitData); } else { - character.Heal(TrentaConfig.PurpleRainHealAmount, true); + character.Heal(heal, true); } + reachedSomeone = true; } + + if (reachedSomeone) FormMelee.RaiseSkill(Skills.SkillType.BloodMagic); } /// diff --git a/JotunnModStub/Trenta/TrentaConfig.cs b/JotunnModStub/Trenta/TrentaConfig.cs index 35fc25d..f3a1972 100644 --- a/JotunnModStub/Trenta/TrentaConfig.cs +++ b/JotunnModStub/Trenta/TrentaConfig.cs @@ -120,6 +120,16 @@ namespace RacesOfValheim public static float PurpleRainRadius => TrentaConfigManagement.PurpleRainRadius.Value; public static float PurpleRainHealAmount => TrentaConfigManagement.PurpleRainHealAmount.Value; public static float PurpleRainPoisonDamage => TrentaConfigManagement.PurpleRainPoisonDamage.Value; + + // The base figures plus the Blood Magic bonus, scaled linearly up to the full bonus at + // level 100 - the same shape as the Aswid's Vampiric Aura. The compendium reads these + // too, so its numbers follow the player's skill. + public static float PurpleRainHealFor(Player player) => + PurpleRainHealAmount + BloodMagicFactor(player) * TrentaConfigManagement.PurpleRainBloodMagicHeal.Value; + public static float PurpleRainPoisonFor(Player player) => + PurpleRainPoisonDamage + BloodMagicFactor(player) * TrentaConfigManagement.PurpleRainBloodMagicPoison.Value; + private static float BloodMagicFactor(Player player) => + player != null ? player.GetSkillFactor(Skills.SkillType.BloodMagic) : 0f; // A Poison-type hit; vanilla's own // poison-on-hit handling takes over from // there, same as SkeletonRace's fire aura diff --git a/JotunnModStub/Trenta/TrentaConfigManagement.cs b/JotunnModStub/Trenta/TrentaConfigManagement.cs index 556edf9..09b5752 100644 --- a/JotunnModStub/Trenta/TrentaConfigManagement.cs +++ b/JotunnModStub/Trenta/TrentaConfigManagement.cs @@ -45,6 +45,8 @@ namespace RacesOfValheim public static ConfigEntry PurpleRainRadius; public static ConfigEntry PurpleRainHealAmount; public static ConfigEntry PurpleRainPoisonDamage; + public static ConfigEntry PurpleRainBloodMagicHeal; + public static ConfigEntry PurpleRainBloodMagicPoison; // ─── Bonemass (tier 4+, passive) ────────────────────────────────────── public static ConfigEntry SwimStaminaRegen; @@ -116,6 +118,10 @@ namespace RacesOfValheim new ConfigDescription("Flat heal applied to you and to every ally hit.", new AcceptableValueRange(0f, 200f))); PurpleRainPoisonDamage = config.Bind(purpleRain, "Enemy Poison Damage", 40f, new ConfigDescription("Flat poison damage applied to every enemy hit.", new AcceptableValueRange(0f, 200f))); + PurpleRainBloodMagicHeal = config.Bind(purpleRain, "Blood Magic Heal Bonus", 40f, + new ConfigDescription("Extra heal at 100 Blood Magic skill, added to Ally Heal Amount (scales linearly from 0).", new AcceptableValueRange(0f, 200f))); + PurpleRainBloodMagicPoison = config.Bind(purpleRain, "Blood Magic Poison Bonus", 40f, + new ConfigDescription("Extra poison damage at 100 Blood Magic skill, added to Enemy Poison Damage (scales linearly from 0).", new AcceptableValueRange(0f, 200f))); const string bonemass = "Trenta - Bonemass"; SwimStaminaRegen = config.Bind(bonemass, "Swim Stamina Regen", 0.1f, diff --git a/JotunnModStub/Trenta/TrentaMuspell.cs b/JotunnModStub/Trenta/TrentaMuspell.cs index 3dadb33..a75f761 100644 --- a/JotunnModStub/Trenta/TrentaMuspell.cs +++ b/JotunnModStub/Trenta/TrentaMuspell.cs @@ -435,6 +435,7 @@ namespace RacesOfValheim float totalDamage = baseDamage + unarmedSkillLevel; HashSet hit = new HashSet(); + bool hitCreature = false; foreach (Collider collider in Physics.OverlapSphere(center, radius)) { Character target = collider.GetComponentInParent(); @@ -442,7 +443,12 @@ namespace RacesOfValheim if (!BaseAI.IsEnemy(player, target)) continue; DealDamage(player, target, totalDamage, HitData.DamageType.Blunt, Vector3.zero); + hitCreature = true; } + + // The spike projectile levels Unarmed through vanilla's Projectile.OnHit; the stomp + // calls Damage directly and has to raise the skill itself. + if (hitCreature) FormMelee.RaiseSkill(Skills.SkillType.Unarmed); } /// From 4ee98d90cb962de8f5aac8b55477e1b1365be005 Mon Sep 17 00:00:00 2001 From: kanym Date: Fri, 6 Nov 2026 21:21:20 +0100 Subject: [PATCH 2/5] fix(factions): the player can strike allied creatures again Valheim 1.0's hit filters (Attack melee/area, Projectile OnHit/DoAOE/ IsValidTarget, Aoe.ShouldHit) skip a target when BaseAI.IsEnemy says false and the attacker is a player without PvP. The truce said false for every allied creature, so the blow passed through: no damage, no grudge, nothing for kin to join. RaceGrudge.StrikeScope opens a scope around those six methods in which both truce patches stand down for the player's own hit; everything else keeps the truce. --- .../Factions/FactionHostilityPatch.cs | 4 ++ JotunnModStub/RaceGrudge.cs | 50 +++++++++++++++++++ JotunnModStub/RaceHostilityManager.cs | 3 ++ 3 files changed, 57 insertions(+) diff --git a/JotunnModStub/Factions/FactionHostilityPatch.cs b/JotunnModStub/Factions/FactionHostilityPatch.cs index 04f9e46..2bc10ce 100644 --- a/JotunnModStub/Factions/FactionHostilityPatch.cs +++ b/JotunnModStub/Factions/FactionHostilityPatch.cs @@ -165,6 +165,10 @@ namespace RacesOfValheim if (!__result) return; // already not enemies, nothing to add if (a == null || b == null) return; + // The player's own blow. Peace is the creature's choice, not a shield. See + // RaceGrudge.StrikeScope. + if (RaceGrudge.PlayerStrikes(a)) return; + if (IsThrallTruce(a, b) || IsThrallTruce(b, a)) { __result = false; diff --git a/JotunnModStub/RaceGrudge.cs b/JotunnModStub/RaceGrudge.cs index eb45794..944a260 100644 --- a/JotunnModStub/RaceGrudge.cs +++ b/JotunnModStub/RaceGrudge.cs @@ -125,6 +125,56 @@ namespace RacesOfValheim } } + // How deep we are inside one of vanilla's hit filters (see StrikeScope). A counter rather + // than a bool because Projectile.OnHit calls DoAOE, and the inner exit must not end the + // outer scope. + private static int strikeDepth = 0; + + /// + /// True while vanilla is deciding whether 's own weapon, arrow or + /// area hit lands. Both truce postfixes stand down for that question: the truce is about + /// who a creature attacks, never about whether the player is allowed to strike it. + /// + public static bool PlayerStrikes(Character attacker) + { + return strikeDepth > 0 && attacker != null && attacker.IsPlayer(); + } + + /// + /// THE PLAYER COULD NOT HIT THEIR OWN FACTION AT ALL. Valheim 1.0's hit filters (Attack's + /// melee and area swings, Projectile's direct hit, its AoE and its IsValidTarget, Aoe's + /// ShouldHit) ask BaseAI.IsEnemy(attacker, target) and skip the target when it answers false + /// and the attacker is a player without PvP on - vanilla's guard for tames. Our truce + /// answers false for every allied creature, so the blow passed through it, it took no + /// damage, BaseAI.OnDamaged never ran and no grudge was ever born. That is both reports at + /// once: "it will not allow me" to attack, and kin that never fight back, group grudge on or + /// off, because nobody was ever hit. With PvP on the filter let the hit through, which is + /// why it looked fine in some tests. + /// + /// The scope is open only around those six methods, so everything else that asks IsEnemy + /// with the player first keeps the truce: the green health bar on allied creatures, sneaking + /// past them, the Aswid's aura leaving kin alone. + /// + [HarmonyPatch] + public static class StrikeScope + { + public static IEnumerable TargetMethods() + { + yield return AccessTools.Method(typeof(Attack), "DoMeleeAttack"); + yield return AccessTools.Method(typeof(Attack), "DoAreaAttack"); + yield return AccessTools.Method(typeof(Projectile), "DoAOE"); + yield return AccessTools.Method(typeof(Projectile), "IsValidTarget"); + yield return AccessTools.Method(typeof(Projectile), "OnHit"); + yield return AccessTools.Method(typeof(Aoe), "ShouldHit"); + } + + public static void Prefix() => strikeDepth++; + + // Finalizer rather than Postfix: the count has to come down even when the method + // throws, or every IsEnemy afterwards would ignore the truce. + public static void Finalizer() => strikeDepth--; + } + /// /// Vanilla's Dvergr camp, for every faction ("Grudge spreads to kin", off by default): hit /// a creature that is at peace with you and its kin around it take up the same grudge. diff --git a/JotunnModStub/RaceHostilityManager.cs b/JotunnModStub/RaceHostilityManager.cs index 03f9fa4..13ed8ed 100644 --- a/JotunnModStub/RaceHostilityManager.cs +++ b/JotunnModStub/RaceHostilityManager.cs @@ -22,6 +22,9 @@ namespace RacesOfValheim if (a == null || b == null) return; + // The player's own blow lands on kin too. See RaceGrudge.StrikeScope. + if (RaceGrudge.PlayerStrikes(a)) return; + Character playerCharacter = a.IsPlayer() ? a : (b.IsPlayer() ? b : null); Character monster = a.IsPlayer() ? b : (b.IsPlayer() ? a : null); From c1c1c763606e7dcb8a92a7d76f31b83c6b01b004 Mon Sep 17 00:00:00 2001 From: kanym Date: Fri, 6 Nov 2026 21:21:20 +0100 Subject: [PATCH 3/5] fix(aswid): pukeberries empty the fourth stomach too SE_Puke calls RemoveOneFood, which only picks from vanilla's three slots, so the Aswid's fourth meal survived the berries. It now joins the same random draw, the way the Trol's extra slots do. --- JotunnModStub/Aswid/AswidPatches.cs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/JotunnModStub/Aswid/AswidPatches.cs b/JotunnModStub/Aswid/AswidPatches.cs index b799936..b607ad9 100644 --- a/JotunnModStub/Aswid/AswidPatches.cs +++ b/JotunnModStub/Aswid/AswidPatches.cs @@ -931,6 +931,30 @@ namespace RacesOfValheim } } + /// + /// Pukeberries empty the fourth stomach too. + /// + /// SE_Puke calls RemoveOneFood once a second, and vanilla only ever picks from its own three + /// slots, so the Aswid's fourth meal survived the berries. It now goes into the same random + /// draw as the other three, the way the Trol's extra slots do. + /// + [HarmonyPatch(typeof(Player), "RemoveOneFood")] + public static class Aswid_PlayerRemoveOneFood_Patch + { + public static bool Prefix(Player __instance, System.Collections.Generic.List ___m_foods, ref bool __result) + { + if (__instance != Player.m_localPlayer || !AswidRace.IsAswid()) return true; + if (!AswidFoodManager.ExtraFoods.TryGetValue(__instance, out Player.Food extraFood) || extraFood == null) return true; + + int vanillaCount = ___m_foods != null ? ___m_foods.Count : 0; + if (Random.Range(0, vanillaCount + 1) < vanillaCount) return true; // one of vanilla's three + + AswidFoodManager.ClearFood(__instance); + __result = true; + return false; + } + } + [HarmonyPatch(typeof(Player), "ClearFood")] public static class Aswid_Player_ClearFood_Patch { From 7a618936f251d39fbb2ca02b291e5509d619b613 Mon Sep 17 00:00:00 2001 From: kanym Date: Fri, 6 Nov 2026 21:28:13 +0100 Subject: [PATCH 4/5] fix(factions): grudges survive an owner change and reach kin owned elsewhere The grudge was a dictionary in the owner's memory: when another client took over the creature mid-fight, its copy made peace on the next UpdateTarget. Grudge spreads to kin also skipped kin owned by another client. The grudge now lives on the creature's ZDO (attacker ZDOID and an end time in network time), written only by the owner; kin owned elsewhere get an RPC that their owner handles. --- JotunnModStub/Factions/FactionsConfig.cs | 5 +- JotunnModStub/RaceGrudge.cs | 129 ++++++++++++++--------- 2 files changed, 81 insertions(+), 53 deletions(-) diff --git a/JotunnModStub/Factions/FactionsConfig.cs b/JotunnModStub/Factions/FactionsConfig.cs index 6086402..6535e12 100644 --- a/JotunnModStub/Factions/FactionsConfig.cs +++ b/JotunnModStub/Factions/FactionsConfig.cs @@ -59,8 +59,9 @@ namespace RacesOfValheim "Without this the truce is absolute in both directions: MonsterAI.UpdateTarget " + "throws away any target BaseAI.IsEnemy calls a non-enemy, so a truced mob could " + "not fight back even after being struck - it stood still, or fled because it " + - "was hurt and had no enemy it was allowed to have. The grudge is per attacker " + - "and per creature, on whichever machine runs that creature's AI. 0 restores the " + + "was hurt and had no enemy it was allowed to have. Each creature holds one " + + "grudge, against the last player who hit it, and keeps it when another player's " + + "game takes over running that creature. 0 restores the " + "old absolute truce.", new AcceptableValueRange(0f, 600f))); diff --git a/JotunnModStub/RaceGrudge.cs b/JotunnModStub/RaceGrudge.cs index 944a260..09bb834 100644 --- a/JotunnModStub/RaceGrudge.cs +++ b/JotunnModStub/RaceGrudge.cs @@ -25,11 +25,13 @@ namespace RacesOfValheim /// which means everything downstream - acquiring, chasing, retaliating, giving up - is vanilla /// behaviour rather than anything reimplemented here. /// - /// WHERE IT RUNS. On the client that owns the mob's AI, which is the only one whose UpdateTarget - /// matters and the only one that runs Character.ApplyDamage for it. BaseAI.OnDamaged is reached - /// through the character's damage callback on exactly that machine, so the record is made where - /// it will be read. Nothing is replicated and nothing needs to be: another client's copy of the - /// same mob is not the one deciding who it chases. + /// WHERE IT LIVES. On the creature's own ZDO: who it is angry at and until when, in network time. + /// The AI that reads it runs on whichever machine owns the creature, and that can change in the + /// middle of a fight (the owner walks off or logs out). A grudge kept in one machine's memory + /// went with it, and the new owner's copy of the creature made peace on its next UpdateTarget. + /// On the ZDO the new owner reads the same grudge. Only the owner writes it: a hit reaches the + /// owner through Character.Damage's RPC anyway, and kin owned elsewhere are told by an RPC of + /// our own (RpcName), so no client writes a ZDO it does not own. /// /// Vanilla has its own version of this idea in BaseAI.SetAggravated, and it is not usable here: /// it does nothing unless the prefab sets m_aggravatable, which only the dvergr and the seekers @@ -37,67 +39,96 @@ namespace RacesOfValheim /// public static class RaceGrudge { - private struct Grudge - { - public ZDOID Attacker; - public float Until; - } + private const string RpcName = "RacesOfValheim_Grudge"; - // One grudge per mob, against the last thing that hit it. A creature can only chase one - // target anyway, and if two players of the same race are both poking it, the one it wants - // is whoever hit it last. - private static readonly Dictionary grudges = new Dictionary(); - private static float lastSweep = 0f; + // One grudge per creature, against the last player that hit it. A creature can only chase + // one target anyway, and if two players of the same race are both poking it, the one it + // wants is whoever hit it last. + private static readonly KeyValuePair AttackerKey = ZDO.GetHashZDOID("RacesOfValheim_GrudgeAttacker"); + private static readonly int UntilKey = "RacesOfValheim_GrudgeUntil".GetStableHashCode(); private static float Duration => FactionsConfig.GrudgeSeconds; + // Network time, the same on every machine, so an end time written by one owner means the + // same thing to the next. Milliseconds in a long: ZDO has no double. + private static long NowMs => ZNet.instance != null ? (long)(ZNet.instance.GetTimeSeconds() * 1000.0) : 0L; + + private static ZDO ZdoOf(Character character) + { + if (character == null || ZDOMan.instance == null) return null; + ZDOID id = character.GetZDOID(); + return id.IsNone() ? null : ZDOMan.instance.GetZDO(id); + } + /// /// True while is owed a hit by . Both - /// truce postfixes ask this first and leave IsEnemy alone when it answers yes. + /// truce postfixes ask this first and leave IsEnemy alone when it answers yes. Read on any + /// machine; it only matters on the owner's. /// public static bool Holds(Character monster, Character player) { if (monster == null || player == null) return false; if (Duration <= 0f) return false; - if (!grudges.TryGetValue(monster.GetZDOID(), out Grudge grudge)) return false; - if (Time.time >= grudge.Until) return false; + ZDO zdo = ZdoOf(monster); + if (zdo == null) return false; - return grudge.Attacker == player.GetZDOID(); - } + long until = zdo.GetLong(UntilKey, 0L); + if (until == 0L || NowMs >= until) return false; - public static void Remember(Character monster, Character attacker) - { - if (monster == null || attacker == null) return; - if (Duration <= 0f) return; - - grudges[monster.GetZDOID()] = new Grudge - { - Attacker = attacker.GetZDOID(), - Until = Time.time + Duration - }; - - Sweep(); + return zdo.GetZDOID(AttackerKey) == player.GetZDOID(); } /// - /// Drops grudges nobody is owed any more. At most once per duration: a fight is a burst of - /// damage events and the list should not be walked on each one. + /// Writes the grudge on the creature's ZDO if this machine owns it, and otherwise asks the + /// owner to. Returns true when it was written here. /// - private static void Sweep() + public static bool Remember(Character monster, Character attacker) { - if (Time.time - lastSweep < Duration) return; - lastSweep = Time.time; + if (monster == null || attacker == null) return false; + if (Duration <= 0f) return false; - List expired = null; - foreach (var entry in grudges) + ZNetView nview = monster.GetComponent(); + if (nview == null || !nview.IsValid()) return false; + + if (!nview.IsOwner()) { - if (Time.time < entry.Value.Until) continue; - if (expired == null) expired = new List(); - expired.Add(entry.Key); + nview.InvokeRPC(RpcName, attacker.GetZDOID()); + return false; + } + + Write(nview.GetZDO(), attacker.GetZDOID()); + return true; + } + + private static void Write(ZDO zdo, ZDOID attacker) + { + zdo.Set(AttackerKey, attacker); + zdo.Set(UntilKey, NowMs + (long)(Duration * 1000f)); + } + + /// + /// Every creature can be told about a grudge by a machine that does not own it. ZNetView's + /// InvokeRPC routes to the owner, so the handler always runs where the ZDO may be written, + /// and the owner checks it is still the owner: ownership can move while the RPC travels. + /// + [HarmonyPatch(typeof(Character), "Awake")] + public static class Character_Awake_GrudgeRpc_Patch + { + public static void Postfix(Character __instance) + { + if (__instance.IsPlayer()) return; + ZNetView nview = __instance.GetComponent(); + if (nview == null || !nview.IsValid()) return; + + nview.Register(RpcName, (sender, attacker) => + { + if (__instance == null || !nview.IsValid() || !nview.IsOwner()) return; + if (attacker.IsNone() || Duration <= 0f) return; + Write(nview.GetZDO(), attacker); + __instance.GetBaseAI()?.Alert(); + }); } - if (expired == null) return; - foreach (ZDOID id in expired) grudges.Remove(id); } /// @@ -179,10 +210,8 @@ namespace RacesOfValheim /// Vanilla's Dvergr camp, for every faction ("Grudge spreads to kin", off by default): hit /// a creature that is at peace with you and its kin around it take up the same grudge. /// - /// Only the creatures this machine runs the AI for are told, because a grudge is read where - /// the AI runs (see WHERE IT RUNS above). The creatures around the one that was hit are - /// nearly always simulated by the same client; one owned by another player's machine stays - /// at peace until it is hit itself. + /// Kin this machine owns are written here; kin owned by another player's machine are told + /// through RpcName, and their owner writes the grudge and alerts them. /// private static void SpreadToKin(Character monster, Player player) { @@ -194,12 +223,10 @@ namespace RacesOfValheim foreach (Character other in Character.GetAllCharacters()) { if (other == null || other == monster || other.IsPlayer() || other.IsDead() || other.IsTamed()) continue; - if (!other.IsOwner()) continue; if (Vector3.Distance(other.transform.position, center) > radius) continue; if (!FactionHostilityPatch.IsAlliedMob(race, other.gameObject.name)) continue; - Remember(other, player); - other.GetBaseAI()?.Alert(); + if (Remember(other, player)) other.GetBaseAI()?.Alert(); } } } From 2d865f5bb0909fa57f86a37ed1fd4c9deaf4408f Mon Sep 17 00:00:00 2001 From: kanym Date: Fri, 6 Nov 2026 21:45:11 +0100 Subject: [PATCH 5/5] docs: v1.6.9 changelog and version bump, hitting your own faction, grudges in multiplayer, race attacks train their skills --- JotunnModStub/Package/manifest.json | 2 +- JotunnModStub/RacesOfValheim.cs | 2 +- README.md | 18 +++++++++++++++--- manifest.json | 2 +- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/JotunnModStub/Package/manifest.json b/JotunnModStub/Package/manifest.json index 12e83af..677943e 100644 --- a/JotunnModStub/Package/manifest.json +++ b/JotunnModStub/Package/manifest.json @@ -1,7 +1,7 @@ { "name": "RacesOfValheim", "description": "A Valheim mod that adds eleven custom playable races (Alfar, 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.6.8", + "version_number": "1.6.9", "website_url": "", "dependencies": [ "denikson-BepInExPack_Valheim-5.4.2333", diff --git a/JotunnModStub/RacesOfValheim.cs b/JotunnModStub/RacesOfValheim.cs index 8301b43..4236e5f 100644 --- a/JotunnModStub/RacesOfValheim.cs +++ b/JotunnModStub/RacesOfValheim.cs @@ -16,7 +16,7 @@ namespace RacesOfValheim { public const string PluginGUID = "com.nandor.racesofvalheim"; public const string PluginName = "Races Of Valheim"; - public const string PluginVersion = "1.6.8"; + public const string PluginVersion = "1.6.9"; private readonly Harmony harmony = new Harmony(PluginGUID); diff --git a/README.md b/README.md index a1be455..8325a1f 100644 --- a/README.md +++ b/README.md @@ -15,9 +15,9 @@ Support the mod: [Patreon — NandorTheModder](https://www.patreon.com/c/NandorT --- -## New in v1.6.8 +## New in v1.6.9 -**A Skeleton that eats, a bat that can't flee mid-fight, and a cheaper marble hall.** Each Skeleton player can choose to eat real food and to spend stamina. The Aswid can't take bat form until a few seconds after the last hit. The Dvergar build the black marble and Yggdrasil wood pieces with stone and fine wood. A faction can now fight as a group if you hit one of its own, and Valheim 1.0's new skeletons keep the swamp truce. Full details in the [changelog](#v168). +**Your own faction can be hit again, and race attacks train their skills.** Since Valheim 1.0 your blows passed straight through creatures of your own faction unless PvP was on, so no grudge ever started. That works again, in multiplayer too. Form attacks and powers now give XP to the skill they scale with, and Purple Rain grows with Blood Magic. Full details in the [changelog](#v169). --- @@ -296,7 +296,7 @@ Build a **Brood Mound** with the hammer — no more than two within its density - **Base:** Tree-Born. Green skin/branches, plant diet, food lasts 2x. Photosynthesis: stand still in daylight for 10s = heal 10% max HP/sec for 8s, Rested buff (5 min +1min per boss). Greylings, greydwarves, fulings, trolls, leeches and deathsquitos ignore you. - **Eikthyr:** Awakened Seeds – eat seeds/cones/acorns/mushrooms for strong food buffs. -- **Elder:** Purple Rain (G): 8m toxic pollen heals you and your allies, poisons enemies, 20s CD. +- **Elder:** Purple Rain (G): 8m toxic pollen heals you and your allies, poisons enemies, 20s CD. Heal and poison grow with Blood Magic (+40 each at level 100), and a cast that reaches someone else trains it. - **Bonemass:** Swim uses no stamina and stamina comes back slowly in the water, immune to Poison/Wet. - **Moder:** Last Stand – armor rises as health falls (up to +50%), Thorns (reflects 20% damage). - **Yagluth:** Homecoming Portal (H): portal to respawn point, anyone can use, 5min CD. @@ -492,6 +492,18 @@ Both halves have an off switch under `Factions` in Configuration Manager: **Fact ## Changelog +### v1.6.9 +- **Fix - you couldn't hit your own faction:** since Valheim 1.0, a player's hit passes through any creature the game calls friendly unless PvP is on, and the faction truce called every creature of your faction friendly. Your blows did nothing, no grudge started, and `Grudge spreads to kin` had nothing to spread. Hitting one of your own works again, and it and its kin fight back as intended. The truce still keeps them off you; it no longer shields them from you. Thanks to Joacwoo and CrimsonAiro for the reports. Not tested in game yet. +- **Fix - grudges in multiplayer:** a creature now keeps its grudge when another player's game takes over running it mid-fight, for example when the first player walks away or logs out. `Grudge spreads to kin` now also reaches kin that another player's game is running; before, they stayed calm until hit themselves. Every player needs this version: a creature run by an older client behaves the old way. Not tested in multiplayer yet. +- **New - race attacks train their skills:** many attacks grew with a skill but gave no XP for it, so the skill never moved. Now an attack that lands on a creature gives the XP a weapon hit gives, and damage over time gives a share per second. Hitting trees or rocks gives nothing. Not tested in game yet. + - Fenrir: the Fenring, Cultist, Wolf and Ulv claws and bites train Unarmed. The Cultist's fire breath trains Elemental Magic. + - Skadi: the Drake forms' bites and claws train Unarmed. + - Trenta: the Muspell stomp trains Unarmed. + - Aswid: the Vampiric Aura slowly trains Blood Magic. + - Alfar: Geisli and Ljosstorm train Elemental Magic. The Sameining pulse trains it slowly. +- **Change - Purple Rain grows with Blood Magic:** at level 100 it heals and poisons for 40 more than its base 40. The bonus has two new keys under `Trenta - Purple Rain`: `Blood Magic Heal Bonus` and `Blood Magic Poison Bonus`. A cast that reaches anyone besides you trains Blood Magic, and the Compendium shows your current numbers. Not tested in game yet. +- **Fix - pukeberries and the Aswid's fourth stomach:** pukeberries emptied only the three vanilla food slots, so the Aswid's fourth meal stayed. It now goes like the others. Thanks to Joacwoo for the report. + ### v1.6.8 - **New - Skeleton Mortal Habits:** two options under `Skeleton - Mortal Habits`, both off by default, each player picking their own. *Eats Mortal Food*: the Skeleton eats like the living, and its health and stamina come from its meals. The boss-tier health bonus goes away, since it stood in for food. *Feels Fatigue*: the Skeleton spends stamina; if it doesn't eat, its stamina grows with its standing. Every other Skeleton power stays. Thanks to Celepito for the request. Not tested in game yet. - **New - Aswid bat form waits out a fight:** you can't take bat form until 2.5 seconds after you last lost health, from a hit or a tick of fire, poison or bleeding. Turning back is never blocked, and a hit still doesn't knock you out of bat form. `Aswid - Bat Form` → `Combat Lock` sets the time; 0 turns it off. Not tested in game yet. diff --git a/manifest.json b/manifest.json index 12e83af..677943e 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "name": "RacesOfValheim", "description": "A Valheim mod that adds eleven custom playable races (Alfar, 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.6.8", + "version_number": "1.6.9", "website_url": "", "dependencies": [ "denikson-BepInExPack_Valheim-5.4.2333",