bugfix 06/10/26 + bone ship

This commit is contained in:
Ferdinando 2026-10-06 11:36:18 +02:00
commit 553303d0fd
27 changed files with 3206 additions and 226 deletions

View file

@ -513,6 +513,7 @@ namespace RacesOfValheim
private Animator fenrirAnim;
private readonly FormLocomotion locomotion = new FormLocomotion();
private float busySince = -1f;
private bool isAttacking = false;
void Start()
@ -525,6 +526,12 @@ namespace RacesOfValheim
void Update()
{
if (FormAnimGuard.Stuck(isAttacking, ref busySince))
{
StopAllCoroutines();
isAttacking = false;
}
if (playerAnim == null || fenrirAnim == null) return;
// Se stiamo attaccando, l'Update smette di inviare costantemente
@ -590,6 +597,7 @@ namespace RacesOfValheim
private IEnumerator ClawRoutine(string triggerName, float baseDamage, float lockDuration, float dmgDelay)
{
isAttacking = true;
FormAnimGuard.LeaveHowl(fenrirAnim);
fenrirAnim.SetFloat("forward_speed", 0f);
fenrirAnim.SetFloat("sideway_speed", 0f);
@ -624,6 +632,7 @@ namespace RacesOfValheim
private IEnumerator JumpAttackRoutine()
{
isAttacking = true;
FormAnimGuard.LeaveHowl(fenrirAnim);
fenrirAnim.SetFloat("forward_speed", 0f);
fenrirAnim.SetFloat("sideway_speed", 0f);
@ -756,6 +765,7 @@ namespace RacesOfValheim
private Animator cultistAnim;
private readonly FormLocomotion locomotion = new FormLocomotion();
private float busySince = -1f;
private bool isAttacking = false;
private bool isShootingFire = false;
private float fireTimer = 0f;
@ -769,6 +779,12 @@ namespace RacesOfValheim
}
void Update()
{
if (FormAnimGuard.Stuck(isAttacking, ref busySince))
{
StopAllCoroutines();
isAttacking = false;
}
if (playerAnim == null || cultistAnim == null) return;
if (!isAttacking)
@ -889,6 +905,7 @@ namespace RacesOfValheim
if (Player.m_localPlayer == null || isShootingFire) return;
isShootingFire = true;
FormAnimGuard.LeaveHowl(cultistAnim);
cultistAnim.SetFloat("forward_speed", 0f);
cultistAnim.SetFloat("sideway_speed", 0f);
cultistAnim.SetBool("attack_fire", true);
@ -1003,6 +1020,7 @@ namespace RacesOfValheim
private IEnumerator ClawRoutine()
{
isAttacking = true;
FormAnimGuard.LeaveHowl(cultistAnim);
cultistAnim.SetFloat("forward_speed", 0f);
cultistAnim.SetFloat("sideway_speed", 0f);
@ -1030,6 +1048,7 @@ namespace RacesOfValheim
private IEnumerator DoubleClawRoutine()
{
isAttacking = true;
FormAnimGuard.LeaveHowl(cultistAnim);
cultistAnim.SetFloat("forward_speed", 0f);
cultistAnim.SetFloat("sideway_speed", 0f);
@ -1130,6 +1149,7 @@ namespace RacesOfValheim
private Animator playerAnim;
private Animator wolfAnim;
private readonly FormLocomotion locomotion = new FormLocomotion();
private float busySince = -1f;
private bool isAttacking = false;
void Start()
@ -1142,6 +1162,12 @@ namespace RacesOfValheim
void Update()
{
if (FormAnimGuard.Stuck(isAttacking, ref busySince))
{
StopAllCoroutines();
isAttacking = false;
}
if (playerAnim == null || wolfAnim == null) return;
if (!isAttacking)
@ -1195,49 +1221,64 @@ namespace RacesOfValheim
{
isAttacking = true;
try { wolfAnim.SetFloat("forward_speed", 0f); } catch {}
try { wolfAnim.SetFloat("sideway_speed", 0f); } catch {}
try
{
try { wolfAnim.SetFloat("forward_speed", 0f); } catch {}
try { wolfAnim.SetFloat("sideway_speed", 0f); } catch {}
FenrirCreatureSound.Howl(wolfAnim, "Wolf", Player.m_localPlayer.transform.position);
FenrirCreatureSound.Howl(wolfAnim, "Wolf", Player.m_localPlayer.transform.position);
// The wolf's howl clip runs 3.13s. Held a little past it so the form does not snap back
// into a bite the instant the sound ends.
yield return new WaitForSeconds(3.3f);
isAttacking = false;
// The wolf's howl clip runs 3.13s. Held a little past it so the form does not snap back
// into a bite the instant the sound ends.
yield return new WaitForSeconds(3.3f);
}
finally
{
isAttacking = false;
}
}
private IEnumerator WolfAttackRoutine(string triggerName, float baseDamage, float lockDuration, float dmgDelay)
{
isAttacking = true;
try { wolfAnim.SetFloat("forward_speed", 0f); } catch {}
try { wolfAnim.SetFloat("sideway_speed", 0f); } catch {}
wolfAnim.SetTrigger(triggerName);
FenrirAttackSync.Publish(triggerName, "sfx_wolf_attack");
yield return new WaitForSeconds(dmgDelay);
if (ZNetScene.instance != null)
// finally and not a plain assignment at the end: an exception anywhere below used to
// leave isAttacking true for good, and Update does nothing at all while it is.
try
{
GameObject attackSfx = ZNetScene.instance.GetPrefab("sfx_wolf_attack");
if (attackSfx != null)
// Out of the howl first - see FormAnimGuard.
FormAnimGuard.LeaveHowl(wolfAnim);
try { wolfAnim.SetFloat("forward_speed", 0f); } catch {}
try { wolfAnim.SetFloat("sideway_speed", 0f); } catch {}
wolfAnim.SetTrigger(triggerName);
FenrirAttackSync.Publish(triggerName, "sfx_wolf_attack");
yield return new WaitForSeconds(dmgDelay);
if (ZNetScene.instance != null)
{
FenrirCreatureSound.Spawn(attackSfx, Player.m_localPlayer.transform.position);
GameObject attackSfx = ZNetScene.instance.GetPrefab("sfx_wolf_attack");
if (attackSfx != null)
{
FenrirCreatureSound.Spawn(attackSfx, Player.m_localPlayer.transform.position);
}
}
ExecuteBiteDamage(baseDamage);
float remainingTimeToIdle = lockDuration - dmgDelay;
if (remainingTimeToIdle > 0)
{
yield return new WaitForSeconds(remainingTimeToIdle);
}
}
ExecuteBiteDamage(baseDamage);
float remainingTimeToIdle = lockDuration - dmgDelay;
if (remainingTimeToIdle > 0)
finally
{
yield return new WaitForSeconds(remainingTimeToIdle);
try { wolfAnim.ResetTrigger(triggerName); } catch {}
isAttacking = false;
}
wolfAnim.ResetTrigger(triggerName);
isAttacking = false;
}
private void ExecuteBiteDamage(float baseDamage)
@ -1321,6 +1362,7 @@ namespace RacesOfValheim
private Animator ulvAnim;
private readonly FormLocomotion locomotion = new FormLocomotion();
private float busySince = -1f;
private bool isAttacking = false;
void Start()
@ -1332,6 +1374,12 @@ namespace RacesOfValheim
void Update()
{
if (FormAnimGuard.Stuck(isAttacking, ref busySince))
{
StopAllCoroutines();
isAttacking = false;
}
if (Player.m_localPlayer == null || playerAnim == null || ulvAnim == null) return;
if (!isAttacking)
@ -1402,6 +1450,7 @@ namespace RacesOfValheim
private IEnumerator UlvAttackRoutine(string triggerName, float baseDamage, float lockDuration, float dmgDelay)
{
isAttacking = true;
FormAnimGuard.LeaveHowl(ulvAnim);
try { ulvAnim.SetFloat("forward_speed", 0f); } catch {}
try { ulvAnim.SetFloat("sideway_speed", 0f); } catch {}
@ -1510,6 +1559,7 @@ namespace RacesOfValheim
private IEnumerator UlvJumpAttackRoutine()
{
isAttacking = true;
FormAnimGuard.LeaveHowl(ulvAnim);
try { ulvAnim.SetFloat("forward_speed", 0f); } catch {}
try { ulvAnim.SetFloat("sideway_speed", 0f); } catch {}

View file

@ -61,6 +61,67 @@ namespace RacesOfValheim
}
}
/// <summary>
/// Two ways a form's Animator and its attack lock got stuck, shared by all four forms.
///
/// The idle howl is a looping clip the attack triggers cannot leave: a click during it queued a
/// trigger the Animator never took, and the model stood frozen until the form was dropped.
/// And an exception inside an attack routine left isAttacking true for good - Update does
/// nothing at all while it is - so the watchdog gives any lock a ceiling.
/// </summary>
internal static class FormAnimGuard
{
/// <summary>Longer than the longest legitimate routine (the Ulv's howl, 3.8 s, plus a margin).</summary>
private const float MaxLockSeconds = 8f;
/// <summary>If the Animator is inside a howl clip, puts it back on its default state so the
/// trigger set next lands on the idle and not on the loop. Call after isAttacking is set.</summary>
public static void LeaveHowl(Animator animator)
{
if (animator == null) return;
try
{
foreach (AnimatorClipInfo clip in animator.GetCurrentAnimatorClipInfo(0))
{
if (clip.clip == null) continue;
string lower = clip.clip.name.ToLower();
if (!lower.Contains("hawl") && !lower.Contains("howl")) continue;
animator.Rebind();
animator.Update(0f);
return;
}
}
catch {}
}
/// <summary>True once the lock has been held longer than any routine can legitimately hold
/// it. Call every Update; <paramref name="since"/> is the caller's own field.</summary>
public static bool Stuck(bool locked, ref float since)
{
if (!locked)
{
since = -1f;
return false;
}
if (since < 0f)
{
since = Time.time;
return false;
}
if (Time.time - since <= MaxLockSeconds) return false;
since = -1f;
Jotunn.Logger.LogWarning("[FenrirForm] An attack lock held for more than " + MaxLockSeconds +
" s was released; something in a routine did not finish.");
return true;
}
}
/// <summary>
/// Whether a melee swing of a form can reach what it found, shared by the four claw and bite
/// attacks.