diff --git a/JotunnModStub/Fenrir/FenrirBehaviors.cs b/JotunnModStub/Fenrir/FenrirBehaviors.cs
index 10be548..40901e4 100644
--- a/JotunnModStub/Fenrir/FenrirBehaviors.cs
+++ b/JotunnModStub/Fenrir/FenrirBehaviors.cs
@@ -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;
diff --git a/JotunnModStub/Fenrir/FenrirFormShared.cs b/JotunnModStub/Fenrir/FenrirFormShared.cs
index fcaecf1..a26c6ed 100644
--- a/JotunnModStub/Fenrir/FenrirFormShared.cs
+++ b/JotunnModStub/Fenrir/FenrirFormShared.cs
@@ -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.
///
/// 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 && player.IsStaggering()) return false;
+ FormStagger.MarkAttack();
if (player == null || baseCost <= 0f) return true;
float cost = baseCost * (1f + player.GetEquipmentAttackStaminaModifier());
diff --git a/JotunnModStub/FormStagger.cs b/JotunnModStub/FormStagger.cs
index 4543ef6..db71448 100644
--- a/JotunnModStub/FormStagger.cs
+++ b/JotunnModStub/FormStagger.cs
@@ -21,6 +21,11 @@ namespace RacesOfValheim
/// The cue is Character.IsStaggering(), which reads the player's Animator state. The player's
/// triggers are replicated, so this holds for onlookers' copies of the form too, with nothing
/// published of its own. Fired once, as the stagger starts.
+ ///
+ /// A stagger also cancels the local form's attack, as it cancels a weapon's in vanilla. The
+ /// form's 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 1.5 s later. MarkAttack is called as an
+ /// attack starts, and AttackInterrupted tells the hit whether a stagger began since.
///
internal static class FormStagger
{
@@ -32,6 +37,15 @@ namespace RacesOfValheim
private static readonly HashSet staggering = new HashSet();
private static readonly List animators = new List();
+ // Staggers of the local player so far, and the count when the current attack started.
+ private static int localStaggers;
+ private static int attackMark;
+
+ public static void MarkAttack() => attackMark = localStaggers;
+
+ /// True if the local player has been staggered since the last MarkAttack.
+ public static bool AttackInterrupted => localStaggers != attackMark;
+
public static void Tick(Player player)
{
int id = player.GetInstanceID();
@@ -41,6 +55,7 @@ namespace RacesOfValheim
return;
}
if (!staggering.Add(id)) return;
+ if (player == Player.m_localPlayer) localStaggers++;
Animator own = AnimatorRef(player);
RuntimeAnimatorController ownController = own != null ? own.runtimeAnimatorController : null;
diff --git a/JotunnModStub/Sverm/SvermRavagerForm.cs b/JotunnModStub/Sverm/SvermRavagerForm.cs
index 22af4ba..52262b1 100644
--- a/JotunnModStub/Sverm/SvermRavagerForm.cs
+++ b/JotunnModStub/Sverm/SvermRavagerForm.cs
@@ -744,7 +744,7 @@ namespace RacesOfValheim
wasGrounded = grounded;
- if (!RaceInput.Allowed || !grounded) return;
+ if (!RaceInput.Allowed || !grounded || player.IsStaggering()) return;
// Right click rams, left click bites, middle click slams. All three read the device
// directly (mouse, or its gamepad counterpart - see RaceInput.AttackDown) rather than
@@ -782,6 +782,7 @@ namespace RacesOfValheim
float radius, bool slam, bool lunge)
{
isAttacking = true;
+ FormStagger.MarkAttack();
bool played = StartAttackState(profile);
if (rootMotion != null) rootMotion.Active = lunge;
@@ -791,6 +792,7 @@ namespace RacesOfValheim
yield return FollowAttackState(stateName, played, 0f, () =>
{
+ if (FormStagger.AttackInterrupted) return;
if (slam) Slam(profile, radius, leftY, rightY, dropSamples);
else ExecuteDamage(profile, radius);
}, () =>
diff --git a/JotunnModStub/Trol/TrolTrueFormBehavior.cs b/JotunnModStub/Trol/TrolTrueFormBehavior.cs
index 8e65624..34540b8 100644
--- a/JotunnModStub/Trol/TrolTrueFormBehavior.cs
+++ b/JotunnModStub/Trol/TrolTrueFormBehavior.cs
@@ -211,7 +211,7 @@ namespace RacesOfValheim
yield return null;
}
- if (player != null && !player.IsDead())
+ if (player != null && !player.IsDead() && !FormStagger.AttackInterrupted)
{
float scale = transform.localScale.x;
int landed;