fix(input): abilities no longer die while a movement key is held
BepInEx's KeyboardShortcut.IsDown() ends in ModifierKeyTest, which requires that no key outside the shortcut is currently held - it only exempts the mouse buttons. That is right for a config-menu hotkey and wrong for a game ability: holding W (or any other movement key) made every bound ability in the mod stop responding, for every race, mouse bindings included. Vanilla attacks kept working because they go through ZInput, which is what made it look like a Skadi/dragon bug. Adds RaceInput.IsDownIgnoringHeldKeys / IsPressedIgnoringHeldKeys - main key down plus every modifier held, without the blocking rule - and switches all 27 call sites across Aswid, Dvergar, Fenrir, Skadi, Trenta and Trol over to them. Arrived with the rebindable-keybind work that shipped in 1.4.0.
This commit is contained in:
parent
a38d1ec4b7
commit
25795a05e9
9 changed files with 62 additions and 22 deletions
|
|
@ -1,4 +1,5 @@
|
|||
using System.Reflection;
|
||||
using BepInEx.Configuration;
|
||||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
|
||||
|
|
@ -48,6 +49,45 @@ namespace RacesOfValheim
|
|||
{
|
||||
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")]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue