fix(trenta): stamina trickles back while a Bonemass Trenta swims

Vanilla Player.UpdateStats stops stamina regen while swimming off the
ground, and drowning starts at 0 stamina. The Bonemass unlock only
waived the stroke cost, so a Trenta who went into the water empty never
got a point back and drowned in water it swims for free.

A postfix on UpdateStats adds the regen vanilla held back, with the same
formula, times the new Trenta - Bonemass / Swim Stamina Regen (0.1, slow
on purpose). The compendium line says so in all three languages.
This commit is contained in:
kanym 2026-10-29 02:21:24 +01:00
commit fdc0fdcedc
5 changed files with 48 additions and 3 deletions

View file

@ -125,6 +125,44 @@ namespace RacesOfValheim
}
}
/// <summary>
/// A trickle of stamina regen while swimming, for a Bonemass-tier Trenta. Vanilla's
/// Player.UpdateStats stops regen outright while swimming off the ground, and drowning starts
/// at 0 stamina, so the free stroke above was not enough: a Trenta who went in empty never
/// got a point back and drowned in water it swims for free. The same formula vanilla uses on
/// land, times Swim Stamina Regen (slow on purpose).
/// </summary>
[HarmonyPatch(typeof(Player), "UpdateStats", new[] { typeof(float) })]
public static class Trenta_Player_SwimStaminaRegen_Patch
{
private static readonly AccessTools.FieldRef<Player, float> RegenTimer =
AccessTools.FieldRefAccess<Player, float>("m_staminaRegenTimer");
public static void Postfix(Player __instance, float dt)
{
if (__instance != Player.m_localPlayer || !TrentaRace.IsTrenta()) return;
if (BossProgressionManager.GetCurrentProgressionState() < TrentaConfig.BonemassDefeatedState) return;
// Only where vanilla held regen at zero for the water alone.
if (!__instance.IsSwimming() || __instance.IsOnGround()) return;
if (__instance.InAttack() || __instance.InDodge() || __instance.IsEncumbered()) return;
float share = TrentaConfigManagement.SwimStaminaRegen.Value;
if (share <= 0f || RegenTimer(__instance) > 0f) return;
float max = __instance.GetMaxStamina();
float stamina = __instance.GetStamina();
if (max <= 0f || stamina >= max) return;
float regen = __instance.m_staminaRegen +
(1f - stamina / max) * __instance.m_staminaRegen * __instance.m_staminaRegenTimeMultiplier;
float multiplier = 1f;
__instance.GetSEMan().ModifyStaminaRegen(ref multiplier);
__instance.AddStamina(regen * multiplier * share * dt * Game.m_staminaRegenRate);
}
}
/// <summary>
/// Blocks the Wet status effect from ever landing on a Bonemass-tier Trenta.
///