fix(forms): Skadi melee hits the training dummy on the clip's hit frame, Ravager attacks get Brute sounds and scale with Unarmed

This commit is contained in:
kanym 2026-11-11 15:56:01 +01:00
commit caaa233392
6 changed files with 223 additions and 41 deletions

View file

@ -311,6 +311,29 @@ namespace RacesOfValheim
return true;
}
/// <summary>
/// How many hit events the form's clips have sent: the dragon's own "Hit" event, which
/// CharacterAnimEvent hands to the player's OnAttackTrigger and SkadiBlockAttackTriggerPatch
/// counts here instead of letting it through. FenrirForms.AttackEvents, the same idea.
/// </summary>
public static int AttackEvents { get; private set; }
public static void NotifyAttackTrigger() => AttackEvents++;
// Longest a melee waits for its Hit event before landing anyway, from the trigger. The
// slowest blow is the Moder's claw at 2.0 s of 3.75 s; a clip that never sends one must
// not leave the swing hitting nothing.
private const float HitEventTimeout = 3f;
/// <summary>
/// Waits for the clip's own blow. A fixed 0.5 s used to land every melee early, read off the
/// game's clips: Moder bite 0.60 s and claws 2.0 s, Fader bite 1.27 s, claws 1.24 s, spin 1.30 s.
/// </summary>
private IEnumerator WaitForHit(int baseline, float started)
{
while (AttackEvents == baseline && Time.time - started < HitEventTimeout) yield return null;
}
private IEnumerator PerformAttackCoroutine(int button)
{
lastAttackTime = Time.time;
@ -409,13 +432,18 @@ namespace RacesOfValheim
breathingUntil = Time.time + projDelay + projCount * 0.05f + 0.5f;
}
int hitBaseline = AttackEvents;
float triggeredAt = Time.time;
SetAttackTrigger(attackTrigger);
yield return new WaitForSeconds(projDelay);
if (isMelee)
{
ExecuteMeleeDamage(MODER_MELEE_DAMAGE, MELEE_RADIUS);
yield return WaitForHit(hitBaseline, triggeredAt);
ExecuteMeleeDamage(MODER_MELEE_DAMAGE, MELEE_RADIUS, MeleeWeapon(attackTrigger));
}
else
{
yield return new WaitForSeconds(projDelay);
}
if (!isMelee && projName != null)
@ -515,13 +543,18 @@ namespace RacesOfValheim
breathingUntil = Time.time + projDelay + projCount * 0.05f + 0.5f;
}
int hitBaseline = AttackEvents;
float triggeredAt = Time.time;
SetAttackTrigger(attackTrigger);
yield return new WaitForSeconds(projDelay);
if (isMelee)
{
ExecuteMeleeDamage(meleeDamage, meleeRadius);
yield return WaitForHit(hitBaseline, triggeredAt);
ExecuteMeleeDamage(meleeDamage, meleeRadius, MeleeWeapon(attackTrigger));
}
else
{
yield return new WaitForSeconds(projDelay);
}
if (!isMelee && projName != null)
@ -583,7 +616,28 @@ namespace RacesOfValheim
// The dragon forms never go through Humanoid.StartAttack - SkadiAttackPatch blocks it, and
// they carry no weapon - so the bite, claw and spin animations landed no damage at all and
// simply burned eitr. Sweep for targets the way FenrirBehaviors does for its claws.
private void ExecuteMeleeDamage(float baseDamage, float radius)
private string FormLabel => formRules != null ? formRules.Form.ToString() : "Skadi form";
/// <summary>
/// The real creature's attack item behind each melee trigger, for its impact sound. The
/// Fader's spin has no item of its own in the game's manifest, so it borrows the claw's.
/// </summary>
private string MeleeWeapon(string trigger)
{
bool fader = formRules != null && formRules.Form == SkadiProgression.FormType.SkeletonDragon;
switch (trigger)
{
case "attack_bite": return fader ? "Fader_Bite" : "dragon_bite";
case "attack_claw_left": return "dragon_claw_left";
case "attack_claw_right": return "dragon_claw_right";
case "attack_ClawL": return "Fader_Claw_Left";
case "attack_ClawR": return "Fader_Claw_Right";
case "attack_Spin": return "Fader_Claw_Left";
default: return null;
}
}
private void ExecuteMeleeDamage(float baseDamage, float radius, string weapon)
{
if (Player.m_localPlayer == null) return;
@ -598,6 +652,8 @@ namespace RacesOfValheim
int layerMask = LayerMask.GetMask("Default", "static_solid", "Default_small", "piece", "piece_nonsolid", "terrain", "character", "character_net", "character_ghost", "hitbox", "character_noenv", "vehicle");
Collider[] hits = Physics.OverlapSphere(attackPoint, radius, layerMask);
FormMelee.LogSwing(FormLabel, hits.Length);
ItemDrop.ItemData.SharedData shared = FormMelee.CreatureWeapon(weapon);
System.Collections.Generic.HashSet<GameObject> hitObjects = new System.Collections.Generic.HashSet<GameObject>();
bool hitCreature = false;
@ -613,18 +669,29 @@ namespace RacesOfValheim
if (characterTarget != null && characterTarget == Player.m_localPlayer) continue;
GameObject targetObj = (target as MonoBehaviour)?.gameObject;
if (targetObj != null)
{
if (hitObjects.Contains(targetObj)) continue;
hitObjects.Add(targetObj);
}
// Marked only once it is hit, further down: marking it here let the first collider
// found (a limb outside the arc) rule out a body squarely in the swing.
if (targetObj != null && hitObjects.Contains(targetObj)) continue;
Vector3 targetCenter = hit.bounds.center;
Vector3 dirToTarget = (targetCenter - playerPos).normalized;
if (!fullCircle && Vector3.Angle(forward, dirToTarget) >= 70f) continue;
float angle = Vector3.Angle(forward, dirToTarget);
if (!fullCircle && angle >= 70f)
{
FormMelee.LogMiss(FormLabel, hit, $"outside the swing arc ({angle:0} deg)");
continue;
}
// FormMelee.CanReach, not a bare Linecast. The Linecast tested the piece layer and
// counted the target's own collider as cover, so anything living on that layer
// could never be hit: the T.W.I.G. training dummy is a Humanoid whose only collider
// is on "piece". Wildlife sits on "character" and was never affected.
Vector3 eyePos = playerPos + Vector3.up * 1.5f;
if (Physics.Linecast(eyePos, targetCenter, out RaycastHit rayHit, LayerMask.GetMask("Default", "static_solid", "terrain", "piece"))) continue;
if (!FormMelee.CanReach(eyePos, attackPoint, hit, target, out string cover))
{
FormMelee.LogMiss(FormLabel, hit, "no clear line, blocked by '" + cover + "'");
continue;
}
HitData hitData = new HitData();
// Frost-flavoured maul; SkadiDamagePatch tops this up with the per-tier frost bonus.
@ -640,8 +707,11 @@ namespace RacesOfValheim
hitData.m_toolTier = 0;
hitData.SetAttacker(Player.m_localPlayer);
if (targetObj != null) hitObjects.Add(targetObj);
FormMelee.LogHit(FormLabel, target, totalDamage);
target.Damage(hitData);
FormMelee.GrantAdrenaline(target);
shared?.m_hitEffect.Create(targetCenter, Quaternion.identity);
if (characterTarget != null) hitCreature = true;
}