fix(fenrir): hidden human no longer attacks or blocks under a form

The attack block patched Character.StartAttack, which Humanoid overrides
without calling the base, so it never ran; and it covered the Fenring only.
Every form swing also fired the hidden human's attack: stamina spent,
regen held at zero while it played, and forward_speed dropped to 0. Patch
Humanoid.StartAttack for all four forms, and clear m_blocking after
SetControls so the pad's heavy attack stops raising the guard.

Forms treat the player as airborne only after 0.25 s off the ground, so
bumps no longer flicker run to idle. Melee reach ignores the target's own
colliders and accepts a clear line from the eyes or the attack point, with
an opt-in hit log. Sunrise names the key that still works by day.
This commit is contained in:
kanym 2026-09-28 22:19:37 +02:00
commit b4b6fe3758
8 changed files with 323 additions and 153 deletions

View file

@ -393,6 +393,7 @@ namespace RacesOfValheim
private ZNetView nview;
private string lastAttack;
private GameObject flames;
private readonly FormLocomotion locomotion = new FormLocomotion();
// The flames hang off the player, not this model, so they outlive it unless taken down.
private void OnDestroy()
@ -418,20 +419,10 @@ namespace RacesOfValheim
ReplayAttack();
ReplayFire();
bool grounded = playerAnim.GetBool("onGround");
// All four borrowed creatures answer to these, and they are still written through
// try/catch the way the local behaviours do it: a controller missing one of them would
// otherwise throw once per frame, for every onlooker.
try { formAnim.SetBool("onGround", grounded); } catch {}
try { formAnim.SetBool("inWater", playerAnim.GetBool("inWater")); } catch {}
// The same three cases the local behaviours use, so both views of the same wolf agree:
// airborne and crouching each read as standing still. Player.IsCrouching answers off
// the animator's current state, which is replicated, so it is true here too.
bool still = !grounded || player.IsCrouching();
try { formAnim.SetFloat("forward_speed", still ? 0f : playerAnim.GetFloat("forward_speed")); } catch {}
try { formAnim.SetFloat("sideway_speed", still ? 0f : playerAnim.GetFloat("sideway_speed")); } catch {}
// The same helper the local behaviours use, so both views of the same wolf agree.
// Player.IsCrouching answers off the animator's current state, which is replicated, so
// it is true here too.
locomotion.Mirror(formAnim, playerAnim, player.IsCrouching());
}
// Written every frame while the flag is set, and only when the controller has the bool: a
@ -516,8 +507,11 @@ namespace RacesOfValheim
public class FenrirFormBehavior : MonoBehaviour
{
private const string FormLabel = "Fenring";
private Animator playerAnim;
private Animator fenrirAnim;
private readonly FormLocomotion locomotion = new FormLocomotion();
private bool isAttacking = false;
@ -533,34 +527,13 @@ namespace RacesOfValheim
{
if (playerAnim == null || fenrirAnim == null) return;
// Se stiamo attaccando, l'Update smette di inviare costantemente
// "onGround", inWater, forward_speed ecc. alle variabili di base?
// Se stiamo attaccando, l'Update smette di inviare costantemente
// "onGround", inWater, forward_speed ecc. alle variabili di base?
// Meglio continuare a sincronizzare i movimenti base.
if (!isAttacking)
{
bool isGrounded = playerAnim.GetBool("onGround");
bool isGrounded = locomotion.Mirror(fenrirAnim, playerAnim, Player.m_localPlayer.IsCrouching());
fenrirAnim.SetBool("onGround", isGrounded);
fenrirAnim.SetBool("inWater", playerAnim.GetBool("inWater"));
if (!isGrounded)
{
fenrirAnim.SetFloat("forward_speed", 0f);
fenrirAnim.SetFloat("sideway_speed", 0f);
}
else
{
if (Player.m_localPlayer.IsCrouching())
{
fenrirAnim.SetFloat("forward_speed", 0f);
fenrirAnim.SetFloat("sideway_speed", 0f);
}
else
{
fenrirAnim.SetFloat("forward_speed", playerAnim.GetFloat("forward_speed"));
fenrirAnim.SetFloat("sideway_speed", playerAnim.GetFloat("sideway_speed"));
}
}
if (isGrounded && RaceInput.Allowed)
{
if (FenrirConfig.HowlKey.Value.IsDownIgnoringHeldKeys())
@ -717,6 +690,7 @@ 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, attackRadius, layerMask);
FormMelee.LogSwing(FormLabel, hits.Length);
System.Collections.Generic.HashSet<GameObject> hitObjects = new System.Collections.Generic.HashSet<GameObject>();
foreach (Collider hit in hits)
@ -731,21 +705,25 @@ namespace RacesOfValheim
Character characterTarget = target as Character;
if (characterTarget != null && characterTarget == Player.m_localPlayer) continue;
// Marked as hit only once it IS hit, further down. Marking it here let the first
// collider found decide for the whole creature: a limb outside the arc or behind
// cover ruled out a body that was squarely in the swing.
GameObject targetObj = (target as MonoBehaviour)?.gameObject;
if (targetObj != null)
{
if (hitObjects.Contains(targetObj)) continue;
hitObjects.Add(targetObj);
}
if (targetObj != null && hitObjects.Contains(targetObj)) continue;
Vector3 targetCenter = hit.bounds.center;
Vector3 dirToTarget = (targetCenter - playerPos).normalized;
float angle = Vector3.Angle(Player.m_localPlayer.transform.forward, dirToTarget);
if (angle < 70f)
if (angle >= 70f) FormMelee.LogMiss(FormLabel, hit, $"outside the swing arc ({angle:0} deg)");
else
{
Vector3 eyePos = playerPos + Vector3.up * 1.5f;
if (!Physics.Linecast(eyePos, targetCenter, out RaycastHit rayHit, LayerMask.GetMask("Default", "static_solid", "terrain", "piece")))
if (!FormMelee.CanReach(eyePos, attackPoint, hit, target, out string cover))
{
FormMelee.LogMiss(FormLabel, hit, "no clear line, blocked by '" + cover + "'");
}
else
{
HitData hitData = new HitData();
hitData.m_damage.m_slash = totalDamage;
@ -759,6 +737,8 @@ 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);
}
}
@ -770,8 +750,11 @@ namespace RacesOfValheim
// --- CLASSE CUSTOM PER L'ATTACCO "FIRE" DEL CULTIST ---
public class CultistFormBehavior : MonoBehaviour
{
private const string FormLabel = "Cultist";
private Animator playerAnim;
private Animator cultistAnim;
private readonly FormLocomotion locomotion = new FormLocomotion();
private bool isAttacking = false;
private bool isShootingFire = false;
@ -790,30 +773,8 @@ namespace RacesOfValheim
if (!isAttacking)
{
bool isGrounded = playerAnim.GetBool("onGround");
cultistAnim.SetBool("onGround", isGrounded);
cultistAnim.SetBool("inWater", playerAnim.GetBool("inWater"));
if (!isGrounded)
{
cultistAnim.SetFloat("forward_speed", 0f);
cultistAnim.SetFloat("sideway_speed", 0f);
}
else
{
// Se tiene premuto Ctrl (Crouch), rallenta o ferma il movimento per preparare l'attacco
if (Player.m_localPlayer.IsCrouching())
{
cultistAnim.SetFloat("forward_speed", 0f);
cultistAnim.SetFloat("sideway_speed", 0f);
}
else
{
cultistAnim.SetFloat("forward_speed", playerAnim.GetFloat("forward_speed"));
cultistAnim.SetFloat("sideway_speed", playerAnim.GetFloat("sideway_speed"));
}
}
// Se tiene premuto Ctrl (Crouch), ferma il movimento per preparare l'attacco
bool isGrounded = locomotion.Mirror(cultistAnim, playerAnim, Player.m_localPlayer.IsCrouching());
if (isGrounded)
{
@ -988,6 +949,7 @@ 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, attackRadius, layerMask);
FormMelee.LogSwing(FormLabel, hits.Length);
System.Collections.Generic.HashSet<GameObject> hitObjects = new System.Collections.Generic.HashSet<GameObject>();
foreach (Collider hit in hits)
@ -1002,12 +964,11 @@ namespace RacesOfValheim
Character characterTarget = target as Character;
if (characterTarget != null && characterTarget == Player.m_localPlayer) continue;
// Marked as hit only once it IS hit, further down. Marking it here let the first
// collider found decide for the whole creature: a limb outside the arc or behind
// cover ruled out a body that was squarely in the swing.
GameObject targetObj = (target as MonoBehaviour)?.gameObject;
if (targetObj != null)
{
if (hitObjects.Contains(targetObj)) continue;
hitObjects.Add(targetObj);
}
if (targetObj != null && hitObjects.Contains(targetObj)) continue;
Vector3 targetCenter = hit.bounds.center;
Vector3 dirToTarget = (targetCenter - playerPos).normalized;
@ -1025,6 +986,8 @@ namespace RacesOfValheim
hitData.m_hitType = HitData.HitType.PlayerHit;
hitData.SetAttacker(Player.m_localPlayer);
if (targetObj != null) hitObjects.Add(targetObj);
FormMelee.LogHit(FormLabel, target, totalDamage);
target.Damage(hitData);
if (ZNetScene.instance != null)
@ -1103,6 +1066,7 @@ 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, attackRadius, layerMask);
FormMelee.LogSwing(FormLabel, hits.Length);
System.Collections.Generic.HashSet<GameObject> hitObjects = new System.Collections.Generic.HashSet<GameObject>();
foreach (Collider hit in hits)
@ -1117,21 +1081,25 @@ namespace RacesOfValheim
Character characterTarget = target as Character;
if (characterTarget != null && characterTarget == Player.m_localPlayer) continue;
// Marked as hit only once it IS hit, further down. Marking it here let the first
// collider found decide for the whole creature: a limb outside the arc or behind
// cover ruled out a body that was squarely in the swing.
GameObject targetObj = (target as MonoBehaviour)?.gameObject;
if (targetObj != null)
{
if (hitObjects.Contains(targetObj)) continue;
hitObjects.Add(targetObj);
}
if (targetObj != null && hitObjects.Contains(targetObj)) continue;
Vector3 targetCenter = hit.bounds.center;
Vector3 dirToTarget = (targetCenter - playerPos).normalized;
float angle = Vector3.Angle(Player.m_localPlayer.transform.forward, dirToTarget);
if (angle < 70f)
if (angle >= 70f) FormMelee.LogMiss(FormLabel, hit, $"outside the swing arc ({angle:0} deg)");
else
{
Vector3 eyePos = playerPos + Vector3.up * 1.5f;
if (!Physics.Linecast(eyePos, targetCenter, out RaycastHit rayHit, LayerMask.GetMask("Default", "static_solid", "terrain", "piece")))
if (!FormMelee.CanReach(eyePos, attackPoint, hit, target, out string cover))
{
FormMelee.LogMiss(FormLabel, hit, "no clear line, blocked by '" + cover + "'");
}
else
{
HitData hitData = new HitData();
hitData.m_damage.m_slash = totalDamage;
@ -1145,6 +1113,8 @@ 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);
}
}
@ -1155,8 +1125,11 @@ namespace RacesOfValheim
public class WolfFormBehavior : MonoBehaviour
{
private const string FormLabel = "Wolf";
private Animator playerAnim;
private Animator wolfAnim;
private readonly FormLocomotion locomotion = new FormLocomotion();
private bool isAttacking = false;
void Start()
@ -1173,29 +1146,7 @@ namespace RacesOfValheim
if (!isAttacking)
{
bool isGrounded = playerAnim.GetBool("onGround");
try { wolfAnim.SetBool("onGround", isGrounded); } catch {}
try { wolfAnim.SetBool("inWater", playerAnim.GetBool("inWater")); } catch {}
if (!isGrounded)
{
try { wolfAnim.SetFloat("forward_speed", 0f); } catch {}
try { wolfAnim.SetFloat("sideway_speed", 0f); } catch {}
}
else
{
if (Player.m_localPlayer.IsCrouching())
{
try { wolfAnim.SetFloat("forward_speed", 0f); } catch {}
try { wolfAnim.SetFloat("sideway_speed", 0f); } catch {}
}
else
{
try { wolfAnim.SetFloat("forward_speed", playerAnim.GetFloat("forward_speed")); } catch {}
try { wolfAnim.SetFloat("sideway_speed", playerAnim.GetFloat("sideway_speed")); } catch {}
}
}
bool isGrounded = locomotion.Mirror(wolfAnim, playerAnim, Player.m_localPlayer.IsCrouching());
if (isGrounded && RaceInput.Allowed)
{
@ -1304,6 +1255,7 @@ 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, attackRadius, layerMask);
FormMelee.LogSwing(FormLabel, hits.Length);
System.Collections.Generic.HashSet<GameObject> hitObjects = new System.Collections.Generic.HashSet<GameObject>();
foreach (Collider hit in hits)
@ -1318,21 +1270,25 @@ namespace RacesOfValheim
Character characterTarget = target as Character;
if (characterTarget != null && characterTarget == Player.m_localPlayer) continue;
// Marked as hit only once it IS hit, further down. Marking it here let the first
// collider found decide for the whole creature: a limb outside the arc or behind
// cover ruled out a body that was squarely in the swing.
GameObject targetObj = (target as MonoBehaviour)?.gameObject;
if (targetObj != null)
{
if (hitObjects.Contains(targetObj)) continue;
hitObjects.Add(targetObj);
}
if (targetObj != null && hitObjects.Contains(targetObj)) continue;
Vector3 targetCenter = hit.bounds.center;
Vector3 dirToTarget = (targetCenter - playerPos).normalized;
float angle = Vector3.Angle(Player.m_localPlayer.transform.forward, dirToTarget);
if (angle < 70f)
if (angle >= 70f) FormMelee.LogMiss(FormLabel, hit, $"outside the swing arc ({angle:0} deg)");
else
{
Vector3 eyePos = playerPos + Vector3.up * 1.0f;
if (!Physics.Linecast(eyePos, targetCenter, out RaycastHit rayHit, LayerMask.GetMask("Default", "static_solid", "terrain", "piece")))
if (!FormMelee.CanReach(eyePos, attackPoint, hit, target, out string cover))
{
FormMelee.LogMiss(FormLabel, hit, "no clear line, blocked by '" + cover + "'");
}
else
{
HitData hitData = new HitData();
hitData.m_damage.m_slash = totalDamage;
@ -1346,6 +1302,8 @@ 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);
}
}
@ -1357,8 +1315,11 @@ namespace RacesOfValheim
// --- CLASSE CUSTOM PER L'ULV ---
public class UlvFormBehavior : MonoBehaviour
{
private const string FormLabel = "Ulv";
private Animator playerAnim;
private Animator ulvAnim;
private readonly FormLocomotion locomotion = new FormLocomotion();
private bool isAttacking = false;
@ -1375,29 +1336,7 @@ namespace RacesOfValheim
if (!isAttacking)
{
bool isGrounded = playerAnim.GetBool("onGround");
try { ulvAnim.SetBool("onGround", isGrounded); } catch {}
try { ulvAnim.SetBool("inWater", playerAnim.GetBool("inWater")); } catch {}
if (!isGrounded)
{
try { ulvAnim.SetFloat("forward_speed", 0f); } catch {}
try { ulvAnim.SetFloat("sideway_speed", 0f); } catch {}
}
else
{
if (Player.m_localPlayer.IsCrouching())
{
try { ulvAnim.SetFloat("forward_speed", 0f); } catch {}
try { ulvAnim.SetFloat("sideway_speed", 0f); } catch {}
}
else
{
try { ulvAnim.SetFloat("forward_speed", playerAnim.GetFloat("forward_speed")); } catch {}
try { ulvAnim.SetFloat("sideway_speed", playerAnim.GetFloat("sideway_speed")); } catch {}
}
}
bool isGrounded = locomotion.Mirror(ulvAnim, playerAnim, Player.m_localPlayer.IsCrouching());
if (isGrounded && RaceInput.Allowed)
{
@ -1512,6 +1451,7 @@ 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, attackRadius, layerMask);
FormMelee.LogSwing(FormLabel, hits.Length);
System.Collections.Generic.HashSet<GameObject> hitObjects = new System.Collections.Generic.HashSet<GameObject>();
foreach (Collider hit in hits)
@ -1526,21 +1466,25 @@ namespace RacesOfValheim
Character characterTarget = target as Character;
if (characterTarget != null && characterTarget == Player.m_localPlayer) continue;
// Marked as hit only once it IS hit, further down. Marking it here let the first
// collider found decide for the whole creature: a limb outside the arc or behind
// cover ruled out a body that was squarely in the swing.
GameObject targetObj = (target as MonoBehaviour)?.gameObject;
if (targetObj != null)
{
if (hitObjects.Contains(targetObj)) continue;
hitObjects.Add(targetObj);
}
if (targetObj != null && hitObjects.Contains(targetObj)) continue;
Vector3 targetCenter = hit.bounds.center;
Vector3 dirToTarget = (targetCenter - playerPos).normalized;
float angle = Vector3.Angle(Player.m_localPlayer.transform.forward, dirToTarget);
if (angle < 70f)
if (angle >= 70f) FormMelee.LogMiss(FormLabel, hit, $"outside the swing arc ({angle:0} deg)");
else
{
Vector3 eyePos = playerPos + Vector3.up * 1.0f;
if (!Physics.Linecast(eyePos, targetCenter, out RaycastHit rayHit, LayerMask.GetMask("Default", "static_solid", "terrain", "piece")))
if (!FormMelee.CanReach(eyePos, attackPoint, hit, target, out string cover))
{
FormMelee.LogMiss(FormLabel, hit, "no clear line, blocked by '" + cover + "'");
}
else
{
HitData hitData = new HitData();
hitData.m_damage.m_slash = totalDamage;
@ -1554,6 +1498,8 @@ 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);
}
}

View file

@ -82,6 +82,9 @@ namespace RacesOfValheim
public static ConfigEntry<float> UlvAttackRadius;
public static ConfigEntry<float> UlvPushForce;
// ─── Debug ─────────────────────────────────────────────────────────────
public static ConfigEntry<bool> DebugFormHits;
public static void Bind(ConfigFile config)
{
const string keybinds = "Fenrir - Keybinds";
@ -184,6 +187,10 @@ namespace RacesOfValheim
new ConfigDescription("Hit-sweep radius for all three attacks.", new AcceptableValueRange<float>(1f, 10f)));
UlvPushForce = config.Bind(ulv, "Push Force", 25f,
new ConfigDescription("Knockback applied on a hit.", new AcceptableValueRange<float>(0f, 100f)));
// "debug" in the key keeps it local - see ConfigSync.
DebugFormHits = config.Bind("Fenrir - Debug", "Debug: Log Form Hits", false,
new ConfigDescription("Writes one log line per claw or bite: what was in reach, what it hit, and why anything was skipped. For bug reports about attacks that do no damage."));
}
/// <summary>

View file

@ -0,0 +1,129 @@
using UnityEngine;
namespace RacesOfValheim
{
/// <summary>What every Fenrir form shares: whether the local player wears one at all.</summary>
internal static class FenrirForms
{
private static readonly int FenringHash = "SE_FenrirForm".GetStableHashCode();
private static readonly int WolfHash = "SE_WolfForm".GetStableHashCode();
private static readonly int CultistHash = "SE_CultistForm".GetStableHashCode();
/// <summary>
/// Any of the four forms. The Wolf and the Ulv share SE_WolfForm, the Fenring has
/// SE_FenrirForm and the Cultist SE_CultistForm. Checking only SE_FenrirForm, as the attack
/// block used to, left three of the four forms out.
/// </summary>
public static bool LocalInForm(Character character)
{
if (character == null || character != Player.m_localPlayer) return false;
SEMan seman = character.GetSEMan();
if (seman == null) return false;
return seman.HaveStatusEffect(FenringHash) || seman.HaveStatusEffect(WolfHash) || seman.HaveStatusEffect(CultistHash);
}
}
/// <summary>
/// The movement half of a form's Animator, copied from the hidden player's. Shared by the four
/// local behaviours and RemoteFenrirAnimator so both views of the same wolf agree.
///
/// WHY THE GRACE PERIOD. Valheim writes onGround = IsOnGround() every frame, and running over
/// uneven ground that drops to false for a frame or two at every bump. The player's own
/// controller rides that out on its transitions. The forms used to read it raw and zero the
/// speed the same frame, so the creature dropped from run to idle and back about once a second
/// on any hillside - the flicker a player reported in all four forms.
/// </summary>
internal class FormLocomotion
{
// Long enough to cover a bump, short enough that a real jump still reads as one.
private const float AirborneGrace = 0.25f;
private float airborneFor;
/// <summary>Copies the movement parameters, and says whether the form counts as grounded.</summary>
public bool Mirror(Animator form, Animator player, bool crouching)
{
bool touching = player.GetBool("onGround");
airborneFor = touching ? 0f : airborneFor + Time.deltaTime;
bool grounded = airborneFor <= AirborneGrace;
// try/catch as the behaviours always did it: a controller missing one of these must not
// throw once per frame.
try { form.SetBool("onGround", grounded); } catch {}
try { form.SetBool("inWater", player.GetBool("inWater")); } catch {}
// Airborne and crouching both read as standing still, as before.
bool still = !grounded || crouching;
try { form.SetFloat("forward_speed", still ? 0f : player.GetFloat("forward_speed")); } catch {}
try { form.SetFloat("sideway_speed", still ? 0f : player.GetFloat("sideway_speed")); } catch {}
return grounded;
}
}
/// <summary>
/// Whether a melee swing of a form can reach what it found, shared by the four claw and bite
/// attacks.
///
/// The old test was one Linecast from the eyes to the centre of the collider, against terrain,
/// pieces and the Default layer. Two ways it threw hits away: the line clipped the ground on
/// any slope or against anything lower than the eyes, and against a tree, a rock or a nest the
/// line hit the target's own collider - those live on exactly the layers it tested - so they
/// could never be damaged at all. Now the target's own colliders do not count as cover, and a
/// swing lands if either the eyes or the point of the attack have a clear line to it.
/// </summary>
internal static class FormMelee
{
private static readonly int CoverMask = LayerMask.GetMask("Default", "static_solid", "terrain", "piece");
private static readonly RaycastHit[] rayHits = new RaycastHit[16];
public static bool CanReach(Vector3 eye, Vector3 attackPoint, Collider hit, IDestructible target, out string blockedBy)
{
Bounds bounds = hit.bounds;
if (Clear(eye, bounds.center, target, out blockedBy)) return true;
return Clear(attackPoint, bounds.ClosestPoint(attackPoint), target, out _);
}
private static bool Clear(Vector3 from, Vector3 to, IDestructible target, out string blockedBy)
{
blockedBy = null;
Vector3 delta = to - from;
float distance = delta.magnitude;
if (distance < 0.01f) return true;
int count = Physics.RaycastNonAlloc(from, delta / distance, rayHits, distance, CoverMask);
for (int i = 0; i < count; i++)
{
Collider cover = rayHits[i].collider;
if (cover == null) continue;
if (ReferenceEquals(cover.GetComponentInParent<IDestructible>(), target)) continue;
blockedBy = cover.name;
return false;
}
return true;
}
/// <summary>
/// One line per rejected candidate while "Debug: Log Form Hits" is on, so the next "my bite
/// did nothing" report comes with the reason in the log.
/// </summary>
public static void LogMiss(string form, Collider hit, string reason)
{
if (!FenrirConfig.DebugFormHits.Value) return;
Jotunn.Logger.LogInfo($"[FenrirForm] {form} swing skipped '{hit.name}' (layer {LayerMask.LayerToName(hit.gameObject.layer)}): {reason}.");
}
public static void LogHit(string form, IDestructible target, float damage)
{
if (!FenrirConfig.DebugFormHits.Value) return;
string name = target is MonoBehaviour behaviour && behaviour != null ? behaviour.name : target.ToString();
Jotunn.Logger.LogInfo($"[FenrirForm] {form} swing hit '{name}' for {damage:0}.");
}
public static void LogSwing(string form, int candidates)
{
if (!FenrirConfig.DebugFormHits.Value) return;
Jotunn.Logger.LogInfo($"[FenrirForm] {form} swing: {candidates} collider(s) in reach.");
}
}
}

View file

@ -9,23 +9,33 @@ using UnityEngine.UI; // Added for UI
namespace RacesOfValheim
{
[HarmonyPatch(typeof(Character), nameof(Character.StartAttack))]
/// <summary>
/// The hidden human does not attack while a form does.
///
/// This patched Character.StartAttack, and it never ran once: Humanoid overrides StartAttack
/// without calling the base, and a player is a Humanoid. Skadi, the Aswid and the Sverm all
/// patch Humanoid, which is why their forms were clean and the Fenrir's were not. So every
/// claw and bite also fired the invisible human's own attack on the same button, and that
/// attack is what a player saw as three separate bugs:
/// - it spent stamina on every swing, and while its animation ran Player.UpdateStats held
/// stamina regen at zero (InAttack), so an empty bar did not come back mid-fight;
/// - a human mid-attack stands still, so the forward_speed the form copies dropped to 0 and
/// the creature fell back to idle in the middle of a fight;
/// - it did so with whatever weapon was in hand.
/// It also only ever looked at SE_FenrirForm, so even working it would have covered the Fenring
/// alone and left the Wolf, the Ulv and the Cultist out.
/// </summary>
[HarmonyPatch(typeof(Humanoid), nameof(Humanoid.StartAttack))]
public static class BlockPlayerLogicAttackPatch
{
public static bool Prefix(Character __instance)
public static bool Prefix(Humanoid __instance)
{
if (__instance != null && __instance == Player.m_localPlayer)
{
if (__instance.GetSEMan().HaveStatusEffect("SE_FenrirForm".GetStableHashCode()))
{
return false;
}
}
return true;
return !FenrirForms.LocalInForm(__instance);
}
}
// --- PATCH 2: BLOCCO ANIMAZIONI ED EFFETTI SONORI NATIVI ---
// Every form now, not the Fenring alone: see BlockPlayerLogicAttackPatch.
[HarmonyPatch(typeof(ZSyncAnimation), nameof(ZSyncAnimation.SetTrigger))]
public static class BlockPlayerAnimationsPatch
{
@ -33,7 +43,7 @@ namespace RacesOfValheim
{
if (Player.m_localPlayer != null && __instance.gameObject == Player.m_localPlayer.gameObject)
{
if (Player.m_localPlayer.GetSEMan().HaveStatusEffect("SE_FenrirForm".GetStableHashCode()))
if (FenrirForms.LocalInForm(Player.m_localPlayer))
{
string triggerName = name.ToLower();
if (triggerName.Contains("attack") || triggerName.Contains("swing") || triggerName.Contains("punch"))
@ -46,6 +56,28 @@ namespace RacesOfValheim
}
}
/// <summary>
/// The hidden human does not block while a form is up either. The forms put their heavy attack
/// on Right Mouse, and on a gamepad RaceInput maps that to JoyBlock, so every heavy bite also
/// raised the human's guard: it turned to face the camera and strafed (the form copies that
/// movement) and regenerated stamina at 80%. A wolf has no shield to raise.
///
/// Cleared after SetControls rather than by answering IsBlocking with false: Player also reads
/// the raw m_blocking flag for the strafe, and the block-and-jump dodge is worked out inside
/// SetControls before this runs, so the dodge still works.
/// </summary>
[HarmonyPatch(typeof(Player), nameof(Player.SetControls))]
public static class BlockPlayerGuardPatch
{
private static readonly AccessTools.FieldRef<Character, bool> Blocking =
AccessTools.FieldRefAccess<Character, bool>("m_blocking");
public static void Postfix(Player __instance)
{
if (FenrirForms.LocalInForm(__instance)) Blocking(__instance) = false;
}
}
[HarmonyPatch]
public static class FenrirDamagePatch
{

View file

@ -22,6 +22,8 @@ namespace RacesOfValheim {
private FenrirProgression.FormRules activeRules = null;
private bool wasNight = false;
private float sunSicknessTimer = 0f;
// Said instead of the usual "back to human" line by the next reversion, then cleared.
private string revertMessage;
private void Awake()
{
@ -142,6 +144,7 @@ namespace RacesOfValheim {
if (activeRules == null || activeRules.NeedsNight)
{
sunSicknessTimer = FenrirConfig.SunSicknessDuration.Value;
if (isTransformed) revertMessage = SunTookFormMessage();
ForceRevert();
}
}
@ -213,6 +216,46 @@ namespace RacesOfValheim {
StartCoroutine(TransformIntoWolfRoutine(rules));
}
/// <summary>
/// Says why sunrise took the form, and which key still works by day.
///
/// A player reported this as a bug: "sometimes" the day turned them human even though they
/// had unlocked day forms. Which forms go by day depends on the key as well as the tier - at
/// Moder the Ulv on the Wolf key walks by day while the Fenring on the Fenrir key is still
/// night-only - so from the outside the same sunrise looked random. The rule stays; this
/// makes it readable. Shown in place of "You returned to human form", which would otherwise
/// replace it on screen half a second later.
/// </summary>
private static string SunTookFormMessage()
{
int state = BossProgressionManager.GetCurrentProgressionState();
string[] day = DayFormFor(FenrirProgression.GetGKeyRules(state), FenrirConfig.WolfFormKey.Value)
?? DayFormFor(FenrirProgression.GetHKeyRules(state), FenrirConfig.FenrirFormKey.Value)
?? DayFormFor(FenrirProgression.GetJKeyRules(state), FenrirConfig.CultistFormKey.Value);
return day != null
? ModText.Get("rov_msg_fenrir_sun_takes_form_day_key", day[0], day[1])
: ModText.Get("rov_msg_fenrir_sun_takes_form");
}
// The form's name token and the key, or null when that key's form is night-only too.
private static string[] DayFormFor(FenrirProgression.FormRules rules, BepInEx.Configuration.KeyboardShortcut key)
{
if (rules == null || rules.Form == FenrirProgression.FormType.None || rules.NeedsNight) return null;
return new[] { FormNameToken(rules.Form), key.ToString() };
}
private static string FormNameToken(FenrirProgression.FormType form)
{
switch (form)
{
case FenrirProgression.FormType.Wolf: return "$rov_msg_fenrir_formname_wolf";
case FenrirProgression.FormType.Ulv: return "$rov_msg_fenrir_formname_ulv";
case FenrirProgression.FormType.Cultist: return "$rov_msg_fenrir_formname_cultist";
}
return "$rov_msg_fenrir_formname_fenrir";
}
public void ForceRevert()
{
if (isTransformed && !isTransformingSequence)
@ -481,7 +524,8 @@ namespace RacesOfValheim {
Player.m_localPlayer.GetSEMan().RemoveStatusEffect("SE_WolfForm".GetStableHashCode());
isTransformed = false;
Player.m_localPlayer.Message(MessageHud.MessageType.Center, ModText.Get("rov_msg_fenrir_returned_human_form"));
Player.m_localPlayer.Message(MessageHud.MessageType.Center, revertMessage ?? ModText.Get("rov_msg_fenrir_returned_human_form"));
revertMessage = null;
if (activeRules != null && activeRules.CooldownMinutes > 0)
{

View file

@ -94,10 +94,14 @@
"rov_msg_fenrir_form_cooldown": "$1 form is on cooldown ($2:$3).",
"rov_msg_fenrir_formname_cultist": "Cultist",
"rov_msg_fenrir_formname_fenrir": "Fenrir",
"rov_msg_fenrir_formname_ulv": "Ulv",
"rov_msg_fenrir_formname_wolf": "Wolf",
"rov_msg_fenrir_has_already_had_one": "It has already had one.",
"rov_msg_fenrir_only_breath_comes_out_fire": "Only breath comes out. The fire wants eitr.",
"rov_msg_fenrir_ready": "$1 is Ready!",
"rov_msg_fenrir_returned_human_form": "You returned to human form.",
"rov_msg_fenrir_sun_takes_form": "The sun takes the beast back. This form only answers at night.",
"rov_msg_fenrir_sun_takes_form_day_key": "The sun takes the beast back. This form only answers at night; by day, press $2 for the $1 form.",
"rov_msg_fenrir_trough_broken_will_not_outlast": "The trough is broken. $1 will not outlast it by long.",
"rov_msg_fenrir_trough_takes_line_runs_deeper": "The trough takes it. The line runs deeper now.",
"rov_msg_fenrir_wants_meat_any_meat": "It wants meat. Any meat.",

View file

@ -94,10 +94,14 @@
"rov_msg_fenrir_form_cooldown": "La forma $1 è in ricarica ($2:$3).",
"rov_msg_fenrir_formname_cultist": "Cultista",
"rov_msg_fenrir_formname_fenrir": "Fenrir",
"rov_msg_fenrir_formname_ulv": "Ulv",
"rov_msg_fenrir_formname_wolf": "Lupo",
"rov_msg_fenrir_has_already_had_one": "Ne ha già avuto uno.",
"rov_msg_fenrir_only_breath_comes_out_fire": "Esce solo fiato. Il fuoco vuole eitr.",
"rov_msg_fenrir_ready": "$1 è pronto!",
"rov_msg_fenrir_returned_human_form": "Sei tornato in forma umana.",
"rov_msg_fenrir_sun_takes_form": "Il sole si riprende la bestia. Questa forma risponde solo di notte.",
"rov_msg_fenrir_sun_takes_form_day_key": "Il sole si riprende la bestia. Questa forma risponde solo di notte; di giorno premi $2 per la forma $1.",
"rov_msg_fenrir_trough_broken_will_not_outlast": "La mangiatoia è distrutta. $1 non le sopravviveranno a lungo.",
"rov_msg_fenrir_trough_takes_line_runs_deeper": "La mangiatoia lo accetta. Ora la discendenza va più a fondo.",
"rov_msg_fenrir_wants_meat_any_meat": "Vuole carne. Qualsiasi carne.",