From ac4ce4c6364e6e57641c4039ac8e9750fa19f8c2 Mon Sep 17 00:00:00 2001 From: kanym Date: Thu, 29 Oct 2026 02:28:23 +0100 Subject: [PATCH] feat(forms): Trol True Form and Fenrir form attacks cost stamina Every form swing was free. FormMelee.TrySpendStamina charges a form attack the way Attack.GetAttackStamina charges a weapon: equipment modifier, status effects, up to a third off with the skill. Short of stamina, the attack does not start and the bar flashes. Trol True Form (Clubs skill), priced by the troll's damage, the slam dearer for hitting all around: punch 10, side log swing 10, overhead log 12, ground slam 18. Fenrir forms (Unarmed), cheaper than weapons: Fenring 6/10/16, Wolf 4/6/10, Ulv 5/8/14, Cultist claw 6 and double claw 12. In exchange each form hit gives 1.5x adrenaline (Fenrir - Form Buffs / Form Adrenaline Multiplier), in Fenrir forms only. Every cost is its own config entry beside the attack's damage. --- JotunnModStub/Fenrir/FenrirBehaviors.cs | 22 +++++------ JotunnModStub/Fenrir/FenrirConfig.cs | 43 ++++++++++++++++++++++ JotunnModStub/Fenrir/FenrirFormShared.cs | 28 ++++++++++++++ JotunnModStub/Trol/TrolConfig.cs | 17 +++++++++ JotunnModStub/Trol/TrolTrueFormBehavior.cs | 15 ++++++++ 5 files changed, 114 insertions(+), 11 deletions(-) diff --git a/JotunnModStub/Fenrir/FenrirBehaviors.cs b/JotunnModStub/Fenrir/FenrirBehaviors.cs index e1df615..46110cb 100644 --- a/JotunnModStub/Fenrir/FenrirBehaviors.cs +++ b/JotunnModStub/Fenrir/FenrirBehaviors.cs @@ -550,15 +550,15 @@ namespace RacesOfValheim { StartCoroutine(HowlRoutine()); } - else if (RaceInput.AttackDown(1)) // Tasto destro (Heavy Claw) + else if (RaceInput.AttackDown(1) && FormMelee.TrySpendStamina(Player.m_localPlayer, FenrirConfig.FenringHeavyClawStamina.Value, Skills.SkillType.Unarmed)) // Tasto destro (Heavy Claw) { StartCoroutine(ClawRoutine("attack_claw1", FenrirConfig.FenringHeavyClawDamage.Value, 1.2f, 0.5f)); } - else if (RaceInput.AttackDown(0)) // Tasto sinistro + else if (RaceInput.AttackDown(0) && FormMelee.TrySpendStamina(Player.m_localPlayer, FenrirConfig.FenringLightClawStamina.Value, Skills.SkillType.Unarmed)) // Tasto sinistro { StartCoroutine(ClawRoutine("attack_claw0", FenrirConfig.FenringLightClawDamage.Value, 1.0f, 0.4f)); } - else if (RaceInput.AttackDown(2)) // Tasto centrale + else if (RaceInput.AttackDown(2) && FormMelee.TrySpendStamina(Player.m_localPlayer, FenrirConfig.FenringJumpAttackStamina.Value, Skills.SkillType.Unarmed)) // Tasto centrale { StartCoroutine(JumpAttackRoutine()); } @@ -840,12 +840,12 @@ namespace RacesOfValheim } // Attacks on Left Click - if (canAct && RaceInput.AttackDown(0) && !isShootingFire) + if (canAct && RaceInput.AttackDown(0) && !isShootingFire && FormMelee.TrySpendStamina(Player.m_localPlayer, FenrirConfig.CultistClawStamina.Value, Skills.SkillType.Unarmed)) { StartCoroutine(ClawRoutine()); // Single claw } // Double claw on Middle Click - else if (canAct && RaceInput.AttackDown(2) && !isShootingFire) + else if (canAct && RaceInput.AttackDown(2) && !isShootingFire && FormMelee.TrySpendStamina(Player.m_localPlayer, FenrirConfig.CultistDoubleClawStamina.Value, Skills.SkillType.Unarmed)) { StartCoroutine(DoubleClawRoutine()); } @@ -1194,15 +1194,15 @@ namespace RacesOfValheim { StartCoroutine(WolfHowlRoutine()); } - else if (RaceInput.AttackDown(0)) // Left Click + else if (RaceInput.AttackDown(0) && FormMelee.TrySpendStamina(Player.m_localPlayer, FenrirConfig.WolfAttack1Stamina.Value, Skills.SkillType.Unarmed)) // Left Click { StartCoroutine(WolfAttackRoutine("attack1", FenrirConfig.WolfAttack1Damage.Value, 0.6f, 0.2f)); } - else if (RaceInput.AttackDown(1)) // Right Click + else if (RaceInput.AttackDown(1) && FormMelee.TrySpendStamina(Player.m_localPlayer, FenrirConfig.WolfAttack2Stamina.Value, Skills.SkillType.Unarmed)) // Right Click { StartCoroutine(WolfAttackRoutine("attack2", FenrirConfig.WolfAttack2Damage.Value, 0.8f, 0.3f)); } - else if (RaceInput.AttackDown(2)) // Middle Click + else if (RaceInput.AttackDown(2) && FormMelee.TrySpendStamina(Player.m_localPlayer, FenrirConfig.WolfAttack3Stamina.Value, Skills.SkillType.Unarmed)) // Middle Click { StartCoroutine(WolfAttackRoutine("attack3", FenrirConfig.WolfAttack3Damage.Value, 1.0f, 0.4f)); } @@ -1410,16 +1410,16 @@ namespace RacesOfValheim { StartCoroutine(UlvHowlRoutine()); } - else if (RaceInput.AttackDown(0)) // Left Click + else if (RaceInput.AttackDown(0) && FormMelee.TrySpendStamina(Player.m_localPlayer, FenrirConfig.UlvBiteStamina.Value, Skills.SkillType.Unarmed)) // Left Click { StartCoroutine(UlvAttackRoutine("attack_bite", FenrirConfig.UlvBiteDamage.Value, 0.6f, 0.2f)); } - else if (RaceInput.AttackDown(1)) // Right Click + else if (RaceInput.AttackDown(1) && FormMelee.TrySpendStamina(Player.m_localPlayer, FenrirConfig.UlvHeavyBiteStamina.Value, Skills.SkillType.Unarmed)) // Right Click { // Right click uses bite but as a heavier attack since slash is moved to jump StartCoroutine(UlvAttackRoutine("attack_bite", FenrirConfig.UlvHeavyBiteDamage.Value, 0.8f, 0.3f)); } - else if (RaceInput.AttackDown(2)) // Middle Click + else if (RaceInput.AttackDown(2) && FormMelee.TrySpendStamina(Player.m_localPlayer, FenrirConfig.UlvJumpAttackStamina.Value, Skills.SkillType.Unarmed)) // Middle Click { StartCoroutine(UlvJumpAttackRoutine()); } diff --git a/JotunnModStub/Fenrir/FenrirConfig.cs b/JotunnModStub/Fenrir/FenrirConfig.cs index e9dd6e5..9b2f85d 100644 --- a/JotunnModStub/Fenrir/FenrirConfig.cs +++ b/JotunnModStub/Fenrir/FenrirConfig.cs @@ -47,6 +47,20 @@ namespace RacesOfValheim public static ConfigEntry WolfFormFallDamageReduction; public static ConfigEntry FormStaminaRegenMultiplier; public static ConfigEntry FormStaminaDrainReduction; + public static ConfigEntry FormAdrenalineMultiplier; + + // ─── Form attack stamina (base cost, before the Unarmed skill discount) ─ + public static ConfigEntry FenringLightClawStamina; + public static ConfigEntry FenringHeavyClawStamina; + public static ConfigEntry FenringJumpAttackStamina; + public static ConfigEntry CultistClawStamina; + public static ConfigEntry CultistDoubleClawStamina; + public static ConfigEntry WolfAttack1Stamina; + public static ConfigEntry WolfAttack2Stamina; + public static ConfigEntry WolfAttack3Stamina; + public static ConfigEntry UlvBiteStamina; + public static ConfigEntry UlvHeavyBiteStamina; + public static ConfigEntry UlvJumpAttackStamina; // ─── Fenring form attacks ───────────────────────────────────────────── public static ConfigEntry FenringHeavyClawDamage; @@ -194,6 +208,35 @@ namespace RacesOfValheim UlvPushForce = config.Bind(ulv, "Push Force", 25f, new ConfigDescription("Knockback applied on a hit.", new AcceptableValueRange(0f, 100f))); + // Form attack stamina, beside each form's damage. Lower than a weapon's on purpose: the + // forms pay less per swing and fill the adrenaline bar faster instead (Form Adrenaline + // Multiplier). For scale, vanilla fists cost 4, Bjorn claws 6, Fenris claws 10. + const string staminaNote = " Base stamina, cut by up to a third with the Unarmed skill as a weapon's is. 0 makes it free."; + FormAdrenalineMultiplier = config.Bind(buffs, "Form Adrenaline Multiplier", 1.5f, + new ConfigDescription("Adrenaline per form hit, times the bare-handed amount, in any Fenrir form.", new AcceptableValueRange(0f, 5f))); + FenringLightClawStamina = config.Bind(fenring, "Light Claw Stamina", 6f, + new ConfigDescription("Stamina for the light claw (Left Mouse)." + staminaNote, new AcceptableValueRange(0f, 50f))); + FenringHeavyClawStamina = config.Bind(fenring, "Heavy Claw Stamina", 10f, + new ConfigDescription("Stamina for the heavy claw (Right Mouse)." + staminaNote, new AcceptableValueRange(0f, 50f))); + FenringJumpAttackStamina = config.Bind(fenring, "Jump Attack Stamina", 16f, + new ConfigDescription("Stamina for the leaping attack (Middle Mouse)." + staminaNote, new AcceptableValueRange(0f, 50f))); + CultistClawStamina = config.Bind(cultist, "Claw Stamina", 6f, + new ConfigDescription("Stamina for the single claw (Left Mouse)." + staminaNote, new AcceptableValueRange(0f, 50f))); + CultistDoubleClawStamina = config.Bind(cultist, "Double Claw Stamina", 12f, + new ConfigDescription("Stamina for the double claw (Middle Mouse)." + staminaNote, new AcceptableValueRange(0f, 50f))); + WolfAttack1Stamina = config.Bind(wolf, "Attack 1 Stamina", 4f, + new ConfigDescription("Stamina for the Left Mouse attack." + staminaNote, new AcceptableValueRange(0f, 50f))); + WolfAttack2Stamina = config.Bind(wolf, "Attack 2 Stamina", 6f, + new ConfigDescription("Stamina for the Right Mouse attack." + staminaNote, new AcceptableValueRange(0f, 50f))); + WolfAttack3Stamina = config.Bind(wolf, "Attack 3 Stamina", 10f, + new ConfigDescription("Stamina for the Middle Mouse attack." + staminaNote, new AcceptableValueRange(0f, 50f))); + UlvBiteStamina = config.Bind(ulv, "Bite Stamina", 5f, + new ConfigDescription("Stamina for the Left Mouse bite." + staminaNote, new AcceptableValueRange(0f, 50f))); + UlvHeavyBiteStamina = config.Bind(ulv, "Heavy Bite Stamina", 8f, + new ConfigDescription("Stamina for the Right Mouse bite." + staminaNote, new AcceptableValueRange(0f, 50f))); + UlvJumpAttackStamina = config.Bind(ulv, "Jump Attack Stamina", 14f, + new ConfigDescription("Stamina for the leaping Middle Mouse attack." + staminaNote, new AcceptableValueRange(0f, 50f))); + // The whole section stays local - see ConfigSync.LocalSections. const string appearance = "Fenrir - Appearance"; ReadyMessage = config.Bind(appearance, "Ready Message", true, diff --git a/JotunnModStub/Fenrir/FenrirFormShared.cs b/JotunnModStub/Fenrir/FenrirFormShared.cs index 84dc78a..f837528 100644 --- a/JotunnModStub/Fenrir/FenrirFormShared.cs +++ b/JotunnModStub/Fenrir/FenrirFormShared.cs @@ -353,9 +353,37 @@ namespace RacesOfValheim ItemDrop unarmed = player.m_unarmedWeapon; float perHit = unarmed != null ? unarmed.m_itemData.m_shared.m_attack.m_attackAdrenaline : 1f; + // The Fenrir forms trade cheaper swings for a faster bar; the other races' forms do not. + if (FenrirForms.LocalInForm(player)) perHit *= FenrirConfig.FormAdrenalineMultiplier.Value; player.AddAdrenaline(perHit * character.m_enemyAdrenalineMultiplier * scale); } + /// + /// 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 + /// the attack's skill. Without enough, the attack does not start and the stamina bar flashes, + /// as it does for a weapon. A cost of 0 is free and always goes through. + /// + /// True if the attack may start; the stamina is already spent. + public static bool TrySpendStamina(Player player, float baseCost, Skills.SkillType skill) + { + if (player == null || baseCost <= 0f) return true; + + float cost = baseCost * (1f + player.GetEquipmentAttackStaminaModifier()); + player.GetSEMan().ModifyAttackStaminaUsage(cost, ref cost); + cost -= cost * 0.33f * player.GetSkillFactor(skill); + if (cost <= 0f) return true; + + if (!player.HaveStamina(cost + 0.1f)) + { + if (player == Player.m_localPlayer && Hud.instance != null) Hud.instance.StaminaBarEmptyFlash(); + return false; + } + + player.UseStamina(cost); + return true; + } + public static void LogHit(string form, IDestructible target, float damage) { if (!FenrirConfig.DebugFormHits.Value) return; diff --git a/JotunnModStub/Trol/TrolConfig.cs b/JotunnModStub/Trol/TrolConfig.cs index 5521be7..b6a2437 100644 --- a/JotunnModStub/Trol/TrolConfig.cs +++ b/JotunnModStub/Trol/TrolConfig.cs @@ -56,6 +56,10 @@ namespace RacesOfValheim public static ConfigEntry TrueFormTrollDamageShare; public static ConfigEntry TrueFormAttackReach; public static ConfigEntry TrueFormSlamCrater; + public static ConfigEntry TrueFormPunchStamina; + public static ConfigEntry TrueFormSlamStamina; + public static ConfigEntry TrueFormLogSwingStamina; + public static ConfigEntry TrueFormLogOverheadStamina; // ─── Log Weapon (tier 7+) ────────────────────────────────────────────── public static ConfigEntry LogWeaponMaxDurability; @@ -149,6 +153,19 @@ namespace RacesOfValheim TrueFormSlamCrater = config.Bind(trueForm, "Ground Slam Crater", true, new ConfigDescription("The ground slam digs into the ground where it lands, like a pickaxe blow. Never inside a ward you have no access to.")); + // Priced by the troll's own damage (punch and side log swing 60 blunt, slam and overhead + // log 70), with the slam dearer because it hits all around: vanilla charges a sledge about + // twice a mace for similar damage. An iron mace swing costs 10, an iron sledge 20. + const string staminaNote = " Base stamina, cut by up to a third with the Clubs skill as a club's is. 0 makes it free."; + TrueFormPunchStamina = config.Bind(trueForm, "Punch Stamina", 10f, + new ConfigDescription("Stamina for the punch (Left Mouse)." + staminaNote, new AcceptableValueRange(0f, 60f))); + TrueFormSlamStamina = config.Bind(trueForm, "Ground Slam Stamina", 18f, + new ConfigDescription("Stamina for the ground slam (Middle Mouse)." + staminaNote, new AcceptableValueRange(0f, 60f))); + TrueFormLogSwingStamina = config.Bind(trueForm, "Log Swing Stamina", 10f, + new ConfigDescription("Stamina for the side swing with a log in hand (Left Mouse)." + staminaNote, new AcceptableValueRange(0f, 60f))); + TrueFormLogOverheadStamina = config.Bind(trueForm, "Log Overhead Stamina", 12f, + new ConfigDescription("Stamina for the overhead swing with a log in hand (Middle Mouse)." + staminaNote, new AcceptableValueRange(0f, 60f))); + const string logWeapon = "Trol - Log Weapon"; LogWeaponMaxDurability = config.Bind(logWeapon, "Max Durability", 6f, new ConfigDescription("Hits a grabbed log weapon survives before breaking, tier 7+.", new AcceptableValueRange(1f, 50f))); diff --git a/JotunnModStub/Trol/TrolTrueFormBehavior.cs b/JotunnModStub/Trol/TrolTrueFormBehavior.cs index 710f2b2..57fd627 100644 --- a/JotunnModStub/Trol/TrolTrueFormBehavior.cs +++ b/JotunnModStub/Trol/TrolTrueFormBehavior.cs @@ -143,6 +143,20 @@ namespace RacesOfValheim } } + /// What a swing costs, by the button pressed. Until these existed every troll + /// blow was free. + private static float StaminaFor(TrolTrueFormModel.AttackKind kind) + { + switch (kind) + { + case TrolTrueFormModel.AttackKind.Punch: return TrolConfig.TrueFormPunchStamina.Value; + case TrolTrueFormModel.AttackKind.Slam: return TrolConfig.TrueFormSlamStamina.Value; + case TrolTrueFormModel.AttackKind.LogSwingH: return TrolConfig.TrueFormLogSwingStamina.Value; + case TrolTrueFormModel.AttackKind.LogSwingV: return TrolConfig.TrueFormLogOverheadStamina.Value; + default: return 0f; + } + } + private void Play(TrolTrueFormModel.AttackKind kind) { TrolTrueFormModel.Profile profile = TrolTrueFormModel.Get(kind); @@ -150,6 +164,7 @@ namespace RacesOfValheim if (profile == null && kind == TrolTrueFormModel.AttackKind.LogSwingH) profile = TrolTrueFormModel.Get(TrolTrueFormModel.AttackKind.Punch); if (profile == null && kind == TrolTrueFormModel.AttackKind.LogSwingV) profile = TrolTrueFormModel.Get(TrolTrueFormModel.AttackKind.Slam); if (profile == null) return; + if (!FormMelee.TrySpendStamina(Player.m_localPlayer, StaminaFor(kind), Skills.SkillType.Clubs)) return; bool log = kind == TrolTrueFormModel.AttackKind.LogSwingH || kind == TrolTrueFormModel.AttackKind.LogSwingV; // The slam goes by what the key means, not by the troll's attack type: troll_groundslam