An eighth race built on the existing per-race pattern: a MonoBehaviour driver registered from Awake, a progression table keyed on the boss state, an SE_Stats carrier, and Harmony patches for the individual perks. The helmet slot stays free. Whatever the player equips keeps every one of its stats and only its mesh is swapped for the dvergr hood, which is the Skeleton's helmet handling turned into a replacement rather than a plain hide. Every percentage the spec left open lives in DvergurConfig as a named value and is marked TODO there, so tuning the race never means touching the logic. The knobs are static readonly rather than const so that switching a perk off with a zero does not fold its guard into dead code.
207 lines
8.3 KiB
C#
207 lines
8.3 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace RacesOfValheim
|
|
{
|
|
/// <summary>
|
|
/// The Dvergur'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 DvergurRace.Update and both read their cost, radius, duration and
|
|
/// cooldown out of DvergurConfig.
|
|
/// </summary>
|
|
public static class DvergurAbilities
|
|
{
|
|
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;
|
|
|
|
DvergurProgression.DvergurRules rules = DvergurProgression.GetRules(state);
|
|
|
|
if (rules.RunicPing && Input.GetKeyDown(DvergurConfig.RunicPingKey))
|
|
{
|
|
TryRunicPing(player);
|
|
}
|
|
|
|
if (rules.RunicOvercharge && Input.GetKeyDown(DvergurConfig.RunicOverchargeKey))
|
|
{
|
|
TryRunicOvercharge(player);
|
|
}
|
|
}
|
|
|
|
// ─── Runic Ping ──────────────────────────────────────────────────────
|
|
|
|
private static void TryRunicPing(Player player)
|
|
{
|
|
if (Time.time - lastPingTime < DvergurConfig.RunicPingCooldown) return;
|
|
|
|
if (player.GetEitr() < DvergurConfig.RunicPingEitrCost)
|
|
{
|
|
player.Message(MessageHud.MessageType.Center, "Not enough eitr");
|
|
return;
|
|
}
|
|
|
|
player.UseEitr(DvergurConfig.RunicPingEitrCost);
|
|
lastPingTime = Time.time;
|
|
DvergurStatusEffects.ApplyCooldownIcon(DvergurConfig.RunicPingCdSE, DvergurConfig.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, DvergurConfig.RunicPingRadius))
|
|
{
|
|
if (collider == null) continue;
|
|
|
|
GameObject vein = FindVeinRoot(collider);
|
|
if (vein == null || !alreadyMarked.Add(vein)) continue;
|
|
|
|
SpawnMarker(vein.transform, DvergurConfig.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) > DvergurConfig.RunicPingRadius) continue;
|
|
if (!BaseAI.IsEnemy(player, character)) continue;
|
|
if (!alreadyMarked.Add(character.gameObject)) continue;
|
|
|
|
SpawnMarker(character.transform, DvergurConfig.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 DvergurConfig.RunicPingVeinNames)
|
|
{
|
|
if (name.Contains(veinName)) return root;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private static void SpawnMarker(Transform target, Color color)
|
|
{
|
|
GameObject markerObj = new GameObject("DvergurRunicMark");
|
|
markerObj.transform.SetParent(target, false);
|
|
markerObj.transform.localPosition = Vector3.up;
|
|
|
|
Light light = markerObj.AddComponent<Light>();
|
|
light.type = LightType.Point;
|
|
light.color = color;
|
|
light.range = DvergurConfig.RunicPingLightRange;
|
|
light.intensity = DvergurConfig.RunicPingLightIntensity;
|
|
light.shadows = LightShadows.None;
|
|
|
|
if (DvergurRace.Instance != null)
|
|
{
|
|
DvergurRace.Instance.StartCoroutine(DestroyAfter(markerObj, DvergurConfig.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 < DvergurConfig.RunicOverchargeCooldown) return;
|
|
|
|
int overchargeHash = DvergurConfig.OverchargeSE.GetStableHashCode();
|
|
if (player.GetSEMan().HaveStatusEffect(overchargeHash)) return; // already loaded
|
|
|
|
if (player.GetEitr() < DvergurConfig.RunicOverchargeEitrCost)
|
|
{
|
|
player.Message(MessageHud.MessageType.Center, "Not enough eitr");
|
|
return;
|
|
}
|
|
|
|
player.UseEitr(DvergurConfig.RunicOverchargeEitrCost);
|
|
lastOverchargeTime = Time.time;
|
|
DvergurStatusEffects.ApplyCooldownIcon(DvergurConfig.OverchargeCdSE, DvergurConfig.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 = DvergurConfig.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 Dvergur is at home with.
|
|
/// </summary>
|
|
public static bool ConsumeOvercharge(Player player)
|
|
{
|
|
if (player == null) return false;
|
|
|
|
int hash = DvergurConfig.OverchargeSE.GetStableHashCode();
|
|
if (!player.GetSEMan().HaveStatusEffect(hash)) return false;
|
|
|
|
player.GetSEMan().RemoveStatusEffect(hash, true);
|
|
return true;
|
|
}
|
|
}
|
|
}
|