Merge branch 'fix-skadi-fader-moder-attack-overlap' into main

Two fixes:
- abilities no longer stop responding while a movement key is held
  (BepInEx KeyboardShortcut.IsDown blocks on any other held key);
  affects every race, not just Skadi.
- the dragon breath and the model's own breath VFX now travel the same
  way instead of drifting apart.
This commit is contained in:
kanym 2026-08-09 12:36:41 +02:00
commit 4c3da61c3c
11 changed files with 154 additions and 34 deletions

View file

@ -529,7 +529,7 @@ namespace RacesOfValheim
ZNetView nview = __instance.GetComponent<ZNetView>(); ZNetView nview = __instance.GetComponent<ZNetView>();
if (nview != null && nview.IsValid() && nview.GetZDO().GetString("RacesOfValheim_Race", "Human") == "Aswid") if (nview != null && nview.IsValid() && nview.GetZDO().GetString("RacesOfValheim_Race", "Human") == "Aswid")
{ {
if (__instance == Player.m_localPlayer && RaceInput.Allowed && AswidConfig.ToggleDevourKey.Value.IsDown()) if (__instance == Player.m_localPlayer && RaceInput.Allowed && AswidConfig.ToggleDevourKey.Value.IsDownIgnoringHeldKeys())
{ {
AswidRace.DevourEnabled = !AswidRace.DevourEnabled; AswidRace.DevourEnabled = !AswidRace.DevourEnabled;
string msg = AswidRace.DevourEnabled ? "Devour Ability: ENABLED" : "Devour Ability: DISABLED"; string msg = AswidRace.DevourEnabled ? "Devour Ability: ENABLED" : "Devour Ability: DISABLED";

View file

@ -387,14 +387,14 @@ namespace RacesOfValheim
if (RaceInput.Allowed) if (RaceInput.Allowed)
{ {
if (AswidConfig.BatFormKey.Value.IsDown()) { TryTransformWithRules(AswidProgression.GetGKeyRules(state)); return; } if (AswidConfig.BatFormKey.Value.IsDownIgnoringHeldKeys()) { TryTransformWithRules(AswidProgression.GetGKeyRules(state)); return; }
if (AswidConfig.MistFormKey.Value.IsDown()) { TryToggleMistForm(); return; } if (AswidConfig.MistFormKey.Value.IsDownIgnoringHeldKeys()) { TryToggleMistForm(); return; }
if (AswidConfig.EclipseKey.Value.IsDown()) if (AswidConfig.EclipseKey.Value.IsDownIgnoringHeldKeys())
{ {
TryCastEclipse(state); TryCastEclipse(state);
return; return;
} }
if (AswidConfig.TameKey.Value.IsDown()) if (AswidConfig.TameKey.Value.IsDownIgnoringHeldKeys())
{ {
TryTameHoverObject(state); TryTameHoverObject(state);
return; return;

View file

@ -26,12 +26,12 @@ namespace RacesOfValheim
DvergarProgression.DvergarRules rules = DvergarProgression.GetRules(state); DvergarProgression.DvergarRules rules = DvergarProgression.GetRules(state);
if (rules.RunicPing && DvergarConfigManagement.RunicPingKey.Value.IsDown()) if (rules.RunicPing && DvergarConfigManagement.RunicPingKey.Value.IsDownIgnoringHeldKeys())
{ {
TryRunicPing(player); TryRunicPing(player);
} }
if (rules.RunicOvercharge && DvergarConfigManagement.RunicOverchargeKey.Value.IsDown()) if (rules.RunicOvercharge && DvergarConfigManagement.RunicOverchargeKey.Value.IsDownIgnoringHeldKeys())
{ {
TryRunicOvercharge(player); TryRunicOvercharge(player);
} }

View file

@ -58,7 +58,7 @@ namespace RacesOfValheim
} }
if (isGrounded && RaceInput.Allowed) if (isGrounded && RaceInput.Allowed)
{ {
if (FenrirConfig.HowlKey.Value.IsDown()) if (FenrirConfig.HowlKey.Value.IsDownIgnoringHeldKeys())
{ {
StartCoroutine(HowlRoutine()); StartCoroutine(HowlRoutine());
} }
@ -339,7 +339,7 @@ namespace RacesOfValheim
StopFire(); StopFire();
} }
if (canAct && FenrirConfig.HowlKey.Value.IsDown()) if (canAct && FenrirConfig.HowlKey.Value.IsDownIgnoringHeldKeys())
{ {
StartCoroutine(HowlRoutine()); StartCoroutine(HowlRoutine());
} }

View file

@ -152,9 +152,9 @@ namespace RacesOfValheim {
int state = BossProgressionManager.GetCurrentProgressionState(); int state = BossProgressionManager.GetCurrentProgressionState();
if (FenrirConfig.WolfFormKey.Value.IsDown()) { TryTransformWithRules(FenrirProgression.GetGKeyRules(state)); return; } if (FenrirConfig.WolfFormKey.Value.IsDownIgnoringHeldKeys()) { TryTransformWithRules(FenrirProgression.GetGKeyRules(state)); return; }
if (FenrirConfig.FenrirFormKey.Value.IsDown()) { TryTransformWithRules(FenrirProgression.GetHKeyRules(state)); return; } if (FenrirConfig.FenrirFormKey.Value.IsDownIgnoringHeldKeys()) { TryTransformWithRules(FenrirProgression.GetHKeyRules(state)); return; }
if (FenrirConfig.CultistFormKey.Value.IsDown()) { TryTransformWithRules(FenrirProgression.GetJKeyRules(state)); return; } if (FenrirConfig.CultistFormKey.Value.IsDownIgnoringHeldKeys()) { TryTransformWithRules(FenrirProgression.GetJKeyRules(state)); return; }
} }
private void TryTransformWithRules(FenrirProgression.FormRules rules) private void TryTransformWithRules(FenrirProgression.FormRules rules)

View file

@ -1,4 +1,5 @@
using System.Reflection; using System.Reflection;
using BepInEx.Configuration;
using HarmonyLib; using HarmonyLib;
using UnityEngine; using UnityEngine;
@ -48,6 +49,45 @@ namespace RacesOfValheim
{ {
SuppressGuardianPowerUntil = Time.time + seconds; SuppressGuardianPowerUntil = Time.time + seconds;
} }
/// <summary>
/// What KeyboardShortcut.IsDown() should have been for a game key.
///
/// BepInEx's own IsDown() ends in a check that no key outside the shortcut is being held
/// (ModifierKeyTest -> _modifierBlockKeyCodes.All(c => !GetKey(c) || allKeys.Contains(c))),
/// which is right for a config-menu hotkey and completely wrong for a game ability: it
/// only exempts the mouse buttons, so holding W - or any other movement key - silently
/// killed every bound ability in the mod, in every race, including the ones bound to mouse
/// buttons. Vanilla attacks kept working because they go through ZInput instead, which is
/// what made it look like the abilities specifically had broken.
///
/// This keeps the part that matters (main key down, every modifier held) and drops the
/// blocking rule, so an ability fires while the player is moving.
/// </summary>
public static bool IsDownIgnoringHeldKeys(this KeyboardShortcut shortcut)
{
if (shortcut.MainKey == KeyCode.None) return false;
if (!Input.GetKeyDown(shortcut.MainKey)) return false;
foreach (KeyCode modifier in shortcut.Modifiers)
{
if (!Input.GetKey(modifier)) return false;
}
return true;
}
/// <summary>Held-down counterpart of <see cref="IsDownIgnoringHeldKeys"/>.</summary>
public static bool IsPressedIgnoringHeldKeys(this KeyboardShortcut shortcut)
{
if (shortcut.MainKey == KeyCode.None) return false;
if (!Input.GetKey(shortcut.MainKey)) return false;
foreach (KeyCode modifier in shortcut.Modifiers)
{
if (!Input.GetKey(modifier)) return false;
}
return true;
}
} }
[HarmonyPatch(typeof(Player), "ActivateGuardianPower")] [HarmonyPatch(typeof(Player), "ActivateGuardianPower")]

View file

@ -20,6 +20,19 @@ namespace RacesOfValheim
// Read by RacesVisualController on other clients so they can keep this character airborne. // Read by RacesVisualController on other clients so they can keep this character airborne.
public const string FlyingKey = "RacesOfValheim_SkadiFlying"; public const string FlyingKey = "RacesOfValheim_SkadiFlying";
/// <summary>
/// Time.time until which a breath is still streaming. Read by SkadiReverseFacingPatch to
/// hold the body on the aim for the duration.
///
/// A deadline rather than a bool on purpose: the attack coroutine has several early exits
/// (a missing prefab, not enough stamina) and can be cut short outright when the form is
/// destroyed mid-breath, so a flag would leak set and pin the body forever. A timestamp
/// cannot leak - it expires on its own however the coroutine ends.
/// </summary>
private static float breathingUntil = -1f;
public static bool IsBreathing => Time.time < breathingUntil;
private void SetFlying(bool value) private void SetFlying(bool value)
{ {
HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_flying").SetValue(value); HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_flying").SetValue(value);
@ -85,18 +98,41 @@ namespace RacesOfValheim
{ {
Active = this; Active = this;
anim = GetComponentInChildren<Animator>(); anim = GetComponentInChildren<Animator>();
if (Player.m_localPlayer != null) if (Player.m_localPlayer != null)
{ {
SetFlying(false); SetFlying(false);
} }
} }
/// <summary>
/// Animator.SetTrigger on a name the controller does not have is silently ignored by Unity,
/// so a wrong trigger looks exactly like "the animation did not play" with nothing in the
/// log. Check before setting, while the form's real trigger names are still being pinned
/// down against the live prefabs.
/// </summary>
private void SetAttackTrigger(string trigger)
{
if (anim == null) return;
foreach (AnimatorControllerParameter p in anim.parameters)
{
if (p.type == AnimatorControllerParameterType.Trigger && p.name == trigger)
{
anim.SetTrigger(trigger);
return;
}
}
Jotunn.Logger.LogWarning($"[SkadiFormDebug] {formRules?.Form}: no trigger named '{trigger}' on this animator.");
}
private void Update() private void Update()
{ {
if (Player.m_localPlayer == null || Player.m_localPlayer.IsDead()) return; if (Player.m_localPlayer == null || Player.m_localPlayer.IsDead()) return;
// Handle Flight Toggle (Right Mouse by default, rebindable) - Disabled for Fader // Handle Flight Toggle (Right Mouse by default, rebindable) - Disabled for Fader
if (RaceInput.Allowed && SkadiConfig.FlightToggleKey.Value.IsDown() && formRules != null && formRules.Form != SkadiProgression.FormType.SkeletonDragon) if (RaceInput.Allowed && SkadiConfig.FlightToggleKey.Value.IsDownIgnoringHeldKeys() && formRules != null && formRules.Form != SkadiProgression.FormType.SkeletonDragon)
{ {
if (!isFlying && !isLanding) if (!isFlying && !isLanding)
{ {
@ -155,21 +191,21 @@ namespace RacesOfValheim
// as it did when these were raw mouse-button checks. // as it did when these were raw mouse-button checks.
if (CanAttackNow() && RaceInput.Allowed) if (CanAttackNow() && RaceInput.Allowed)
{ {
if (SkadiConfig.PrimaryAttackKey.Value.IsDown()) if (SkadiConfig.PrimaryAttackKey.Value.IsDownIgnoringHeldKeys())
{ {
if (HasAttackForButton(0) && Time.time - lastAttackTime >= ATTACK_COOLDOWN) if (HasAttackForButton(0) && Time.time - lastAttackTime >= ATTACK_COOLDOWN)
{ {
StartCoroutine(PerformAttackCoroutine(0)); StartCoroutine(PerformAttackCoroutine(0));
} }
} }
else if (SkadiConfig.BreathAttackKey.Value.IsDown()) else if (SkadiConfig.BreathAttackKey.Value.IsDownIgnoringHeldKeys())
{ {
if (Time.time - lastAttackTime >= ATTACK_COOLDOWN) if (Time.time - lastAttackTime >= ATTACK_COOLDOWN)
{ {
StartCoroutine(PerformAttackCoroutine(2)); StartCoroutine(PerformAttackCoroutine(2));
} }
} }
else if (SkadiConfig.SpinAttackKey.Value.IsDown() && formRules.Form == SkadiProgression.FormType.SkeletonDragon) // Fader Spin else if (SkadiConfig.SpinAttackKey.Value.IsDownIgnoringHeldKeys() && formRules.Form == SkadiProgression.FormType.SkeletonDragon) // Fader Spin
{ {
if (Time.time - lastAttackTime >= ATTACK_COOLDOWN) if (Time.time - lastAttackTime >= ATTACK_COOLDOWN)
{ {
@ -291,7 +327,19 @@ namespace RacesOfValheim
} }
if (!isMelee && !TrySpendVolleyStamina(projCount)) yield break; if (!isMelee && !TrySpendVolleyStamina(projCount)) yield break;
if (anim != null) anim.SetTrigger(attackTrigger);
// Committed for the same reason as Fader's below: a 16- or 20-projectile volley
// lasts long enough for the camera to swing away from where the animation is
// still breathing.
// Grounded, the same as Fader's below: the head is held on the aim and the breath
// comes out of it. In the air the flight patch already steers the body, so this
// stays out of its way and the volley simply follows the same muzzle.
if (!isMelee && !isFlying && !isLanding)
{
breathingUntil = Time.time + projDelay + projCount * 0.05f + 0.5f;
}
SetAttackTrigger(attackTrigger);
yield return new WaitForSeconds(projDelay); yield return new WaitForSeconds(projDelay);
@ -311,8 +359,8 @@ namespace RacesOfValheim
float vel = staffDrop.m_itemData.m_shared.m_attack.m_projectileVel; float vel = staffDrop.m_itemData.m_shared.m_attack.m_projectileVel;
for (int i = 0; i < projCount; i++) for (int i = 0; i < projCount; i++)
{ {
Vector3 spawnPos = Player.m_localPlayer.GetEyePoint() + Player.m_localPlayer.GetLookDir() * 3.0f; Vector3 targetDir = Player.m_localPlayer.transform.forward;
Vector3 targetDir = Player.m_localPlayer.GetLookDir(); Vector3 spawnPos = Player.m_localPlayer.GetEyePoint() + targetDir * 3.0f;
if (projCount > 1) if (projCount > 1)
{ {
@ -377,7 +425,26 @@ namespace RacesOfValheim
} }
if (!isMelee && !TrySpendVolleyStamina(projCount)) yield break; if (!isMelee && !TrySpendVolleyStamina(projCount)) yield break;
if (anim != null) anim.SetTrigger(attackTrigger);
// A breath is a stream, not a shot: 60 shards at 0.05 s each runs for about three
// seconds. Reading GetLookDir() fresh inside that loop let the ice track the
// crosshair live while the model's own breath VFX - baked into the animation, and
// so always leaving the muzzle - stayed with the body, which only turns at
// m_turnSpeed. Sweep the camera mid-breath and the two ended up pointing opposite
// ways. The direction is committed here instead, and the body is turned onto it.
// The breath follows the muzzle rather than a direction captured when the key went
// down. The model's own breath VFX is part of the animation and always leaves the
// mouth, so any direction the projectiles keep on their own drifts away from it -
// locking it at the press just swapped which of the two lagged. Pinning the body
// to the aim for the duration (breathingUntil, read by SkadiReverseFacingPatch)
// lets the mouse steer the head, and the projectiles below simply come out of
// wherever it has turned to, so ice and VFX cannot separate.
if (!isMelee)
{
breathingUntil = Time.time + projDelay + projCount * 0.05f + 0.5f;
}
SetAttackTrigger(attackTrigger);
yield return new WaitForSeconds(projDelay); yield return new WaitForSeconds(projDelay);
@ -397,8 +464,8 @@ namespace RacesOfValheim
float vel = staffDrop.m_itemData.m_shared.m_attack.m_projectileVel; float vel = staffDrop.m_itemData.m_shared.m_attack.m_projectileVel;
for (int i = 0; i < projCount; i++) for (int i = 0; i < projCount; i++)
{ {
Vector3 spawnPos = Player.m_localPlayer.GetEyePoint() + Player.m_localPlayer.GetLookDir() * 4.0f; Vector3 targetDir = Player.m_localPlayer.transform.forward;
Vector3 targetDir = Player.m_localPlayer.GetLookDir(); Vector3 spawnPos = Player.m_localPlayer.GetEyePoint() + targetDir * 4.0f;
if (projCount > 1) if (projCount > 1)
{ {

View file

@ -444,6 +444,19 @@ namespace RacesOfValheim
public static bool Prefix(Player __instance, ref bool __result) public static bool Prefix(Player __instance, ref bool __result)
{ {
if (__instance != Player.m_localPlayer) return true; if (__instance != Player.m_localPlayer) return true;
// A breath in progress holds the body on the aim, whether the player is moving or not.
// Character.UpdateRotation only steers by m_lookYaw when AlwaysRotateCamera() is true
// or the player is standing still - otherwise it faces m_moveDir. So running or
// strafing mid-breath turned the model (and the muzzle VFX baked into its animation)
// towards the run while our projectiles kept going where the player aimed, which is
// how the ice and the poison ended up pointing different ways.
if (DrakeFormBehavior.IsBreathing && DrakeFormBehavior.Active != null)
{
__result = true;
return false;
}
if (!SkadiDirectedFlightPatch.Reversing) return true; if (!SkadiDirectedFlightPatch.Reversing) return true;
DrakeFormBehavior form = DrakeFormBehavior.Active; DrakeFormBehavior form = DrakeFormBehavior.Active;
@ -473,7 +486,7 @@ namespace RacesOfValheim
// the live button state (via the configured shortcut, so a rebind stays in sync) // the live button state (via the configured shortcut, so a rebind stays in sync)
// rather than a flag set during our Update, so it does not depend on whether // rather than a flag set during our Update, so it does not depend on whether
// PlayerController's FixedUpdate happens to run first. // PlayerController's FixedUpdate happens to run first.
if (secondaryAttack && SkadiConfig.ColdSpellKey.Value.IsPressed() && if (secondaryAttack && SkadiConfig.ColdSpellKey.Value.IsPressedIgnoringHeldKeys() &&
SkadiRace.Instance != null && SkadiRace.Instance.IsSkadi()) SkadiRace.Instance != null && SkadiRace.Instance.IsSkadi())
{ {
var rules = SkadiProgression.GetRules(BossProgressionManager.GetCurrentProgressionState()); var rules = SkadiProgression.GetRules(BossProgressionManager.GetCurrentProgressionState());

View file

@ -244,9 +244,9 @@ namespace RacesOfValheim
if (!RaceInput.Allowed) return; if (!RaceInput.Allowed) return;
int state = BossProgressionManager.GetCurrentProgressionState(); int state = BossProgressionManager.GetCurrentProgressionState();
if (SkadiConfig.DrakeFormKey.Value.IsDown()) { TryTransformWithRules(SkadiProgression.GetGKeyRules(state)); return; } if (SkadiConfig.DrakeFormKey.Value.IsDownIgnoringHeldKeys()) { TryTransformWithRules(SkadiProgression.GetGKeyRules(state)); return; }
if (SkadiConfig.ModerFormKey.Value.IsDown()) { TryTransformWithRules(SkadiProgression.GetHKeyRules(state)); return; } if (SkadiConfig.ModerFormKey.Value.IsDownIgnoringHeldKeys()) { TryTransformWithRules(SkadiProgression.GetHKeyRules(state)); return; }
if (SkadiConfig.FaderFormKey.Value.IsDown()) { TryTransformWithRules(SkadiProgression.GetJKeyRules(state)); return; } if (SkadiConfig.FaderFormKey.Value.IsDownIgnoringHeldKeys()) { TryTransformWithRules(SkadiProgression.GetJKeyRules(state)); return; }
// Debug Dump // Debug Dump
if (Input.GetKeyDown(KeyCode.F8)) if (Input.GetKeyDown(KeyCode.F8))
@ -336,7 +336,7 @@ namespace RacesOfValheim
if (isTransformed) return; // Do not cast human spell while in dragon form if (isTransformed) return; // Do not cast human spell while in dragon form
// Middle Mouse Button to cast, by default - rebindable via SkadiConfig.ColdSpellKey. // Middle Mouse Button to cast, by default - rebindable via SkadiConfig.ColdSpellKey.
if (SkadiConfig.ColdSpellKey.Value.IsDown()) if (SkadiConfig.ColdSpellKey.Value.IsDownIgnoringHeldKeys())
{ {
// The improved cast is a burst rather than a rapid-fire, so it waits longer. // The improved cast is a burst rather than a rapid-fire, so it waits longer.
float cooldown = rules.ImprovedColdSpell ? IMPROVED_SPELL_COOLDOWN : SPELL_COOLDOWN; float cooldown = rules.ImprovedColdSpell ? IMPROVED_SPELL_COOLDOWN : SPELL_COOLDOWN;

View file

@ -23,17 +23,17 @@ namespace RacesOfValheim
// Player.TakeInput, so nothing fires while a map, chest or chat window has focus. // Player.TakeInput, so nothing fires while a map, chest or chat window has focus.
if (!RaceInput.Allowed) return; if (!RaceInput.Allowed) return;
if (state >= TrentaConfig.PurpleRainUnlockState && TrentaConfigManagement.PurpleRainKey.Value.IsDown()) if (state >= TrentaConfig.PurpleRainUnlockState && TrentaConfigManagement.PurpleRainKey.Value.IsDownIgnoringHeldKeys())
{ {
TryPurpleRain(player); TryPurpleRain(player);
} }
if (state >= TrentaConfig.PortalUnlockState && TrentaConfigManagement.PortalKey.Value.IsDown()) if (state >= TrentaConfig.PortalUnlockState && TrentaConfigManagement.PortalKey.Value.IsDownIgnoringHeldKeys())
{ {
TryOpenPortal(player); TryOpenPortal(player);
} }
if (state >= TrentaConfig.MuspellUnlockState && TrentaConfigManagement.MuspellKey.Value.IsDown()) if (state >= TrentaConfig.MuspellUnlockState && TrentaConfigManagement.MuspellKey.Value.IsDownIgnoringHeldKeys())
{ {
TrentaMuspell.Toggle(player); TrentaMuspell.Toggle(player);
} }

View file

@ -125,17 +125,17 @@ namespace RacesOfValheim
if (RaceInput.Allowed) if (RaceInput.Allowed)
{ {
if (TrolConfig.ThrowRockKey.Value.IsDown()) if (TrolConfig.ThrowRockKey.Value.IsDownIgnoringHeldKeys())
{ {
TryThrowRock(); TryThrowRock();
} }
if (TrolConfig.TrueFormKey.Value.IsDown()) if (TrolConfig.TrueFormKey.Value.IsDownIgnoringHeldKeys())
{ {
TryTrueForm(); TryTrueForm();
} }
if (TrolConfig.GrabLogKey.Value.IsDown()) if (TrolConfig.GrabLogKey.Value.IsDownIgnoringHeldKeys())
{ {
TryGrabLog(); TryGrabLog();
} }