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.
This commit is contained in:
kanym 2026-10-29 02:28:23 +01:00
commit ac4ce4c636
5 changed files with 114 additions and 11 deletions

View file

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

View file

@ -47,6 +47,20 @@ namespace RacesOfValheim
public static ConfigEntry<float> WolfFormFallDamageReduction;
public static ConfigEntry<float> FormStaminaRegenMultiplier;
public static ConfigEntry<float> FormStaminaDrainReduction;
public static ConfigEntry<float> FormAdrenalineMultiplier;
// ─── Form attack stamina (base cost, before the Unarmed skill discount) ─
public static ConfigEntry<float> FenringLightClawStamina;
public static ConfigEntry<float> FenringHeavyClawStamina;
public static ConfigEntry<float> FenringJumpAttackStamina;
public static ConfigEntry<float> CultistClawStamina;
public static ConfigEntry<float> CultistDoubleClawStamina;
public static ConfigEntry<float> WolfAttack1Stamina;
public static ConfigEntry<float> WolfAttack2Stamina;
public static ConfigEntry<float> WolfAttack3Stamina;
public static ConfigEntry<float> UlvBiteStamina;
public static ConfigEntry<float> UlvHeavyBiteStamina;
public static ConfigEntry<float> UlvJumpAttackStamina;
// ─── Fenring form attacks ─────────────────────────────────────────────
public static ConfigEntry<float> FenringHeavyClawDamage;
@ -194,6 +208,35 @@ namespace RacesOfValheim
UlvPushForce = config.Bind(ulv, "Push Force", 25f,
new ConfigDescription("Knockback applied on a hit.", new AcceptableValueRange<float>(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<float>(0f, 5f)));
FenringLightClawStamina = config.Bind(fenring, "Light Claw Stamina", 6f,
new ConfigDescription("Stamina for the light claw (Left Mouse)." + staminaNote, new AcceptableValueRange<float>(0f, 50f)));
FenringHeavyClawStamina = config.Bind(fenring, "Heavy Claw Stamina", 10f,
new ConfigDescription("Stamina for the heavy claw (Right Mouse)." + staminaNote, new AcceptableValueRange<float>(0f, 50f)));
FenringJumpAttackStamina = config.Bind(fenring, "Jump Attack Stamina", 16f,
new ConfigDescription("Stamina for the leaping attack (Middle Mouse)." + staminaNote, new AcceptableValueRange<float>(0f, 50f)));
CultistClawStamina = config.Bind(cultist, "Claw Stamina", 6f,
new ConfigDescription("Stamina for the single claw (Left Mouse)." + staminaNote, new AcceptableValueRange<float>(0f, 50f)));
CultistDoubleClawStamina = config.Bind(cultist, "Double Claw Stamina", 12f,
new ConfigDescription("Stamina for the double claw (Middle Mouse)." + staminaNote, new AcceptableValueRange<float>(0f, 50f)));
WolfAttack1Stamina = config.Bind(wolf, "Attack 1 Stamina", 4f,
new ConfigDescription("Stamina for the Left Mouse attack." + staminaNote, new AcceptableValueRange<float>(0f, 50f)));
WolfAttack2Stamina = config.Bind(wolf, "Attack 2 Stamina", 6f,
new ConfigDescription("Stamina for the Right Mouse attack." + staminaNote, new AcceptableValueRange<float>(0f, 50f)));
WolfAttack3Stamina = config.Bind(wolf, "Attack 3 Stamina", 10f,
new ConfigDescription("Stamina for the Middle Mouse attack." + staminaNote, new AcceptableValueRange<float>(0f, 50f)));
UlvBiteStamina = config.Bind(ulv, "Bite Stamina", 5f,
new ConfigDescription("Stamina for the Left Mouse bite." + staminaNote, new AcceptableValueRange<float>(0f, 50f)));
UlvHeavyBiteStamina = config.Bind(ulv, "Heavy Bite Stamina", 8f,
new ConfigDescription("Stamina for the Right Mouse bite." + staminaNote, new AcceptableValueRange<float>(0f, 50f)));
UlvJumpAttackStamina = config.Bind(ulv, "Jump Attack Stamina", 14f,
new ConfigDescription("Stamina for the leaping Middle Mouse attack." + staminaNote, new AcceptableValueRange<float>(0f, 50f)));
// The whole section stays local - see ConfigSync.LocalSections.
const string appearance = "Fenrir - Appearance";
ReadyMessage = config.Bind(appearance, "Ready Message", true,

View file

@ -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);
}
/// <summary>
/// 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.
/// </summary>
/// <returns>True if the attack may start; the stamina is already spent.</returns>
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;

View file

@ -56,6 +56,10 @@ namespace RacesOfValheim
public static ConfigEntry<float> TrueFormTrollDamageShare;
public static ConfigEntry<float> TrueFormAttackReach;
public static ConfigEntry<bool> TrueFormSlamCrater;
public static ConfigEntry<float> TrueFormPunchStamina;
public static ConfigEntry<float> TrueFormSlamStamina;
public static ConfigEntry<float> TrueFormLogSwingStamina;
public static ConfigEntry<float> TrueFormLogOverheadStamina;
// ─── Log Weapon (tier 7+) ──────────────────────────────────────────────
public static ConfigEntry<float> 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<float>(0f, 60f)));
TrueFormSlamStamina = config.Bind(trueForm, "Ground Slam Stamina", 18f,
new ConfigDescription("Stamina for the ground slam (Middle Mouse)." + staminaNote, new AcceptableValueRange<float>(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<float>(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<float>(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<float>(1f, 50f)));

View file

@ -143,6 +143,20 @@ namespace RacesOfValheim
}
}
/// <summary>What a swing costs, by the button pressed. Until these existed every troll
/// blow was free.</summary>
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