fix(fenrir): Cultist claws land on the clip's own hits

The single claw dealt its damage at a fixed 0.4 s, before the swing in
ClawAttackCultist (Hit event at 0.64 s of 1.33 s), and released the lock
at 0.5 s, so clicking again started a new claw mid-swing. The double
claw dealt one hit at 0.6 s although DoubleClawAttackCultist swipes
twice (Hit events at 0.64 s and 1.21 s).

BlockPlayerAttackTriggerPatch now counts the form's Hit events
(FenrirForms.AttackEvents) instead of only swallowing them. Both claws
wait for their events, with a timeout, and hold the lock until the clip
ends. Each double-claw swipe deals 60% of Double Claw Damage, 120% in
all for a slower swing that can be cut short.
This commit is contained in:
kanym 2026-10-29 02:23:27 +01:00
commit ffb45d1c1c
4 changed files with 73 additions and 17 deletions

View file

@ -1034,25 +1034,30 @@ namespace RacesOfValheim
cultistAnim.SetFloat("sideway_speed", 0f);
// Per il Cultista usiamo esplicitamente il trigger dell'artigliata
int baseline = FenrirForms.AttackEvents;
float started = Time.time;
cultistAnim.SetTrigger("attack_claw");
FenrirAttackSync.Publish("attack_claw", "sfx_fenring_claw_start");
yield return new WaitForSeconds(0.4f);
// The blow lands on the clip's own Hit event (ClawAttackCultist: 0.64 s of 1.33 s), and
// the lock holds until the clip is over. A fixed 0.4 s hit and a 0.5 s lock used to land
// the damage before the claw swung and let the next click start a new one mid-swing.
yield return null;
float length = ClipLength(1.33f);
yield return WaitForHit(baseline, started);
PlaySFX("sfx_fenring_claw_start");
ExecuteClawDamage(FenrirConfig.CultistClawDamage.Value);
float remainingTimeToIdle = 0.5f - 0.4f;
if (remainingTimeToIdle > 0)
{
yield return new WaitForSeconds(remainingTimeToIdle);
}
yield return WaitUntilClipEnds(length, started);
cultistAnim.ResetTrigger("attack_claw");
isAttacking = false;
}
// Each swipe of the double claw deals this share of Double Claw Damage. Two swipes give
// 120% of what the old single hit dealt: a little more, for a slower swing that can be cut short.
private const float DoubleClawHitShare = 0.6f;
private IEnumerator DoubleClawRoutine()
{
isAttacking = true;
@ -1061,24 +1066,63 @@ namespace RacesOfValheim
cultistAnim.SetFloat("forward_speed", 0f);
cultistAnim.SetFloat("sideway_speed", 0f);
int baseline = FenrirForms.AttackEvents;
float started = Time.time;
cultistAnim.SetTrigger("attack_claw_double");
FenrirAttackSync.Publish("attack_claw_double", "sfx_fenring_claw_start");
// L'animazione double claw è più lunga, facciamo il danno un po' dopo
yield return new WaitForSeconds(0.6f);
// DoubleClawAttackCultist carries two Hit events (0.64 s and 1.21 s of 1.83 s), one per
// swipe. It used to deal one hit at a fixed 0.6 s, so the second swipe did nothing.
yield return null;
float length = ClipLength(1.83f);
float damage = FenrirConfig.CultistDoubleClawDamage.Value * DoubleClawHitShare;
yield return WaitForHit(baseline, started);
PlaySFX("sfx_fenring_claw_start");
ExecuteClawDamage(damage);
ExecuteClawDamage(FenrirConfig.CultistDoubleClawDamage.Value);
// Attendiamo che l'animazione finisca (locking del giocatore)
// L'animazione doppia del cultista dura circa 1.5 - 2 secondi
yield return new WaitForSeconds(1.2f);
yield return WaitForHit(baseline + 1, started, HitEventTimeout + 0.6f);
PlaySFX("sfx_fenring_claw_start");
ExecuteClawDamage(damage);
yield return WaitUntilClipEnds(length, started);
cultistAnim.ResetTrigger("attack_claw_double");
isAttacking = false;
}
// Longest a swipe waits for its Hit event before landing anyway, measured from the trigger:
// a clip that never sends one must not leave the Cultist swinging at nothing.
private const float HitEventTimeout = 1.5f;
/// <summary>Waits until the clip has sent more than <paramref name="seen"/> hit events since
/// the trigger, or until the timeout.</summary>
private IEnumerator WaitForHit(int seen, float started, float timeout = HitEventTimeout)
{
while (FenrirForms.AttackEvents <= seen && Time.time - started < timeout)
{
yield return null;
}
}
/// <summary>The attack clip's length, read a frame after its trigger, when the transition
/// into it has begun. <paramref name="fallback"/> is the clip's length in the game files.</summary>
private float ClipLength(float fallback)
{
AnimatorClipInfo[] clips = cultistAnim.IsInTransition(0)
? cultistAnim.GetNextAnimatorClipInfo(0)
: cultistAnim.GetCurrentAnimatorClipInfo(0);
if (clips != null && clips.Length > 0 && clips[0].clip != null) return clips[0].clip.length;
return fallback;
}
/// <summary>Holds the lock until the clip has played out, clamped so a wrong reading can
/// neither cut a swing short nor freeze the form.</summary>
private IEnumerator WaitUntilClipEnds(float length, float started)
{
float remaining = Mathf.Clamp(length, 0.6f, 3f) - (Time.time - started);
if (remaining > 0f) yield return new WaitForSeconds(remaining);
}
private void ExecuteClawDamage(float baseDamage)
{
if (Player.m_localPlayer == null) return;

View file

@ -154,7 +154,7 @@ namespace RacesOfValheim
CultistClawDamage = config.Bind(cultist, "Claw Damage", 85f,
new ConfigDescription("Base damage of the single claw (Left Mouse), before the Unarmed skill bonus.", new AcceptableValueRange<float>(0f, 500f)));
CultistDoubleClawDamage = config.Bind(cultist, "Double Claw Damage", 140f,
new ConfigDescription("Base damage of the double claw (Middle Mouse), before the Unarmed skill bonus.", new AcceptableValueRange<float>(0f, 500f)));
new ConfigDescription("Base damage of the double claw (Middle Mouse), before the Unarmed skill bonus. Each of its two swipes deals 60% of it.", new AcceptableValueRange<float>(0f, 500f)));
CultistAttackRadius = config.Bind(cultist, "Claw Attack Radius", 2.5f,
new ConfigDescription("Hit-sweep radius for both claw attacks.", new AcceptableValueRange<float>(1f, 10f)));
CultistPushForce = config.Bind(cultist, "Claw Push Force", 30f,

View file

@ -18,6 +18,16 @@ namespace RacesOfValheim
/// form's own routines, and on every revert.</summary>
public static bool LocalAttacking { get; set; }
/// <summary>
/// How many hit events the local form's clips have fired: the creature's own "Hit" event,
/// which CharacterAnimEvent hands to the player's OnAttackTrigger, and BlockPlayerAttackTriggerPatch
/// counts here instead of letting it through. A swing waits for this to move, so its damage
/// lands on the clip's own blow (TrolTrueFormModel.AttackEvents, the same idea).
/// </summary>
public static int AttackEvents { get; private set; }
public static void NotifyAttackTrigger() => AttackEvents++;
public static bool LocalInForm(Character character)
{
if (character == null || character != Player.m_localPlayer) return false;

View file

@ -56,7 +56,9 @@ namespace RacesOfValheim
{
public static bool Prefix(Humanoid __instance)
{
return !FenrirForms.LocalInForm(__instance);
if (!FenrirForms.LocalInForm(__instance)) return true;
FenrirForms.NotifyAttackTrigger();
return false;
}
}