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.
207 lines
8.4 KiB
C#
207 lines
8.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace RacesOfValheim
|
|
{
|
|
/// <summary>
|
|
/// The Dvergar's two eitr abilities.
|
|
///
|
|
/// Runic Ping (Yagluth) - spend eitr to light up ore veins and hidden enemies nearby.
|
|
/// Runic Overcharge (Fader) - spend eitr to load the next blow of a favoured weapon.
|
|
///
|
|
/// Both are driven from DvergarRace.Update and both read their cost, radius, duration and
|
|
/// cooldown out of DvergarConfig.
|
|
/// </summary>
|
|
public static class DvergarAbilities
|
|
{
|
|
private static float lastPingTime = -1000f;
|
|
private static float lastOverchargeTime = -1000f;
|
|
|
|
public static void Tick(Player player, int state)
|
|
{
|
|
// Ability input is gated exactly like every other race's: RaceInput mirrors
|
|
// Player.TakeInput, so nothing fires while a map, chest or chat window has focus.
|
|
if (!RaceInput.Allowed) return;
|
|
|
|
DvergarProgression.DvergarRules rules = DvergarProgression.GetRules(state);
|
|
|
|
if (rules.RunicPing && DvergarConfigManagement.RunicPingKey.Value.IsDownIgnoringHeldKeys())
|
|
{
|
|
TryRunicPing(player);
|
|
}
|
|
|
|
if (rules.RunicOvercharge && DvergarConfigManagement.RunicOverchargeKey.Value.IsDownIgnoringHeldKeys())
|
|
{
|
|
TryRunicOvercharge(player);
|
|
}
|
|
}
|
|
|
|
// ─── Runic Ping ──────────────────────────────────────────────────────
|
|
|
|
private static void TryRunicPing(Player player)
|
|
{
|
|
if (Time.time - lastPingTime < DvergarConfig.RunicPingCooldown) return;
|
|
|
|
if (player.GetEitr() < DvergarConfig.RunicPingEitrCost)
|
|
{
|
|
player.Message(MessageHud.MessageType.Center, "Not enough eitr");
|
|
return;
|
|
}
|
|
|
|
player.UseEitr(DvergarConfig.RunicPingEitrCost);
|
|
lastPingTime = Time.time;
|
|
DvergarStatusEffects.ApplyCooldownIcon(DvergarConfig.RunicPingCdSE, DvergarConfig.RunicPingCooldown);
|
|
|
|
int marked = MarkSurroundings(player);
|
|
player.Message(MessageHud.MessageType.Center,
|
|
marked > 0 ? $"Runic Ping: {marked} echoes answer" : "Runic Ping: the stone is silent");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Lights every ore vein and every hostile within the radius for the duration. The marker
|
|
/// is a local point light parented to the target, the same trick the Aswid's Auspex uses -
|
|
/// nothing is replicated, so it costs other players nothing.
|
|
/// </summary>
|
|
private static int MarkSurroundings(Player player)
|
|
{
|
|
Vector3 center = player.transform.position;
|
|
HashSet<GameObject> alreadyMarked = new HashSet<GameObject>();
|
|
int marked = 0;
|
|
|
|
foreach (Collider collider in Physics.OverlapSphere(center, DvergarConfig.RunicPingRadius))
|
|
{
|
|
if (collider == null) continue;
|
|
|
|
GameObject vein = FindVeinRoot(collider);
|
|
if (vein == null || !alreadyMarked.Add(vein)) continue;
|
|
|
|
SpawnMarker(vein.transform, DvergarConfig.RunicPingOreColor);
|
|
marked++;
|
|
}
|
|
|
|
foreach (Character character in Character.GetAllCharacters())
|
|
{
|
|
if (character == null || character == player || character.IsDead() || character.IsTamed()) continue;
|
|
if (Vector3.Distance(character.transform.position, center) > DvergarConfig.RunicPingRadius) continue;
|
|
if (!BaseAI.IsEnemy(player, character)) continue;
|
|
if (!alreadyMarked.Add(character.gameObject)) continue;
|
|
|
|
SpawnMarker(character.transform, DvergarConfig.RunicPingEnemyColor);
|
|
marked++;
|
|
}
|
|
|
|
return marked;
|
|
}
|
|
|
|
/// <summary>
|
|
/// The mineable object a collider belongs to, or null. Both halves matter: the component
|
|
/// check keeps ordinary terrain out, and the name check keeps plain rock and trees out of
|
|
/// what is meant to read as an ore reading.
|
|
/// </summary>
|
|
private static GameObject FindVeinRoot(Collider collider)
|
|
{
|
|
GameObject root = null;
|
|
|
|
MineRock5 mineRock5 = collider.GetComponentInParent<MineRock5>();
|
|
if (mineRock5 != null) root = mineRock5.gameObject;
|
|
|
|
if (root == null)
|
|
{
|
|
MineRock mineRock = collider.GetComponentInParent<MineRock>();
|
|
if (mineRock != null) root = mineRock.gameObject;
|
|
}
|
|
|
|
if (root == null)
|
|
{
|
|
Destructible destructible = collider.GetComponentInParent<Destructible>();
|
|
if (destructible != null && destructible.m_destructibleType != DestructibleType.Tree)
|
|
{
|
|
root = destructible.gameObject;
|
|
}
|
|
}
|
|
|
|
if (root == null) return null;
|
|
|
|
string name = root.name.ToLower();
|
|
foreach (string veinName in DvergarConfig.RunicPingVeinNames)
|
|
{
|
|
if (name.Contains(veinName)) return root;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private static void SpawnMarker(Transform target, Color color)
|
|
{
|
|
GameObject markerObj = new GameObject("DvergarRunicMark");
|
|
markerObj.transform.SetParent(target, false);
|
|
markerObj.transform.localPosition = Vector3.up;
|
|
|
|
Light light = markerObj.AddComponent<Light>();
|
|
light.type = LightType.Point;
|
|
light.color = color;
|
|
light.range = DvergarConfig.RunicPingLightRange;
|
|
light.intensity = DvergarConfig.RunicPingLightIntensity;
|
|
light.shadows = LightShadows.None;
|
|
|
|
if (DvergarRace.Instance != null)
|
|
{
|
|
DvergarRace.Instance.StartCoroutine(DestroyAfter(markerObj, DvergarConfig.RunicPingDuration));
|
|
}
|
|
else
|
|
{
|
|
// No driver to run the coroutine on: better a marker that never appears than one
|
|
// that never goes away.
|
|
Object.Destroy(markerObj);
|
|
}
|
|
}
|
|
|
|
private static IEnumerator DestroyAfter(GameObject obj, float seconds)
|
|
{
|
|
yield return new WaitForSeconds(seconds);
|
|
if (obj != null) Object.Destroy(obj);
|
|
}
|
|
|
|
// ─── Runic Overcharge ────────────────────────────────────────────────
|
|
|
|
private static void TryRunicOvercharge(Player player)
|
|
{
|
|
if (Time.time - lastOverchargeTime < DvergarConfig.RunicOverchargeCooldown) return;
|
|
|
|
int overchargeHash = DvergarConfig.OverchargeSE.GetStableHashCode();
|
|
if (player.GetSEMan().HaveStatusEffect(overchargeHash)) return; // already loaded
|
|
|
|
if (player.GetEitr() < DvergarConfig.RunicOverchargeEitrCost)
|
|
{
|
|
player.Message(MessageHud.MessageType.Center, "Not enough eitr");
|
|
return;
|
|
}
|
|
|
|
player.UseEitr(DvergarConfig.RunicOverchargeEitrCost);
|
|
lastOverchargeTime = Time.time;
|
|
DvergarStatusEffects.ApplyCooldownIcon(DvergarConfig.OverchargeCdSE, DvergarConfig.RunicOverchargeCooldown);
|
|
|
|
player.GetSEMan().AddStatusEffect(overchargeHash, true);
|
|
StatusEffect se = player.GetSEMan().GetStatusEffect(overchargeHash);
|
|
// The charge is held, not permanent: it lapses if no favoured blow lands in time.
|
|
if (se != null) se.m_ttl = DvergarConfig.RunicOverchargeWindow;
|
|
|
|
player.Message(MessageHud.MessageType.Center, "Runic Overcharge: your next blow is loaded");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Spends a held charge. Called from the damage patch once it has confirmed the blow was
|
|
/// struck with a weapon the Dvergar is at home with.
|
|
/// </summary>
|
|
public static bool ConsumeOvercharge(Player player)
|
|
{
|
|
if (player == null) return false;
|
|
|
|
int hash = DvergarConfig.OverchargeSE.GetStableHashCode();
|
|
if (!player.GetSEMan().HaveStatusEffect(hash)) return false;
|
|
|
|
player.GetSEMan().RemoveStatusEffect(hash, true);
|
|
return true;
|
|
}
|
|
}
|
|
}
|