fix: a stagger cancels the form's attack

A form swing waits for its clip's hit event and lands on a timeout if none comes,
so a stagger that cut the clip short still dealt the blow. Attacks are marked as
they start (TrySpendStamina, Ravager AttackRoutine) and their hits are dropped if
a stagger began since. No attack or Cultist breath starts while staggered.
This commit is contained in:
kanym 2026-10-29 13:53:04 +01:00
commit beffd0bee6
5 changed files with 28 additions and 7 deletions

View file

@ -726,7 +726,7 @@ namespace RacesOfValheim
private void ExecuteClawDamage(float baseDamage)
{
if (Player.m_localPlayer == null) return;
if (Player.m_localPlayer == null || FormStagger.AttackInterrupted) return;
Vector3 playerPos = Player.m_localPlayer.transform.position;
Vector3 attackPoint = playerPos + Player.m_localPlayer.transform.forward * 1.5f + Vector3.up * 1f;
@ -842,7 +842,7 @@ namespace RacesOfValheim
bool canAct = RaceInput.Allowed;
// Fire attack on Right Click
if (canAct && RaceInput.AttackHeld(1))
if (canAct && RaceInput.AttackHeld(1) && !Player.m_localPlayer.IsStaggering())
{
if (Player.m_localPlayer.GetEitr() > 0)
{
@ -1161,7 +1161,7 @@ namespace RacesOfValheim
private void ExecuteClawDamage(float baseDamage)
{
if (Player.m_localPlayer == null) return;
if (Player.m_localPlayer == null || FormStagger.AttackInterrupted) return;
Vector3 playerPos = Player.m_localPlayer.transform.position;
Vector3 attackPoint = playerPos + Player.m_localPlayer.transform.forward * 1.5f + Vector3.up * 1f;
@ -1375,7 +1375,7 @@ namespace RacesOfValheim
private void ExecuteBiteDamage(float baseDamage)
{
if (Player.m_localPlayer == null) return;
if (Player.m_localPlayer == null || FormStagger.AttackInterrupted) return;
Vector3 playerPos = Player.m_localPlayer.transform.position;
// Il lupo è basso, abbassiamo l'altezza dell'attacco
@ -1584,7 +1584,7 @@ namespace RacesOfValheim
private void ExecuteBiteDamage(float baseDamage)
{
if (Player.m_localPlayer == null) return;
if (Player.m_localPlayer == null || FormStagger.AttackInterrupted) return;
Vector3 playerPos = Player.m_localPlayer.transform.position;
Vector3 attackPoint = playerPos + Player.m_localPlayer.transform.forward * 1.5f + Vector3.up * 0.5f;

View file

@ -373,10 +373,14 @@ namespace RacesOfValheim
/// 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.
/// A staggered player cannot attack at all, and an attack that may start is marked for
/// FormStagger, so a stagger before its hit cancels it.
/// </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 && player.IsStaggering()) return false;
FormStagger.MarkAttack();
if (player == null || baseCost <= 0f) return true;
float cost = baseCost * (1f + player.GetEquipmentAttackStaminaModifier());