Rename covers the folder, all seven filenames and every identifier, status effect name and display string. Valheim's own Dverger/dvergr prefab references are untouched - the names never collided. The race id is what sits in m_customData and the ZDO, so renaming it alone would have handed every existing character the selection menu again. DvergarRace migrates the old id on spawn, before anything else reads it. Runic Spark is modelled on Skadi's Ice Affinity and deliberately shares its shape: live from the base tier and growing a flat step per progression state, so +2 at Base through +16 after Fader. Lightning rather than frost, and like Skadi's it rides every blow rather than melee only. AddFlat gained the elemental channels while it was there - lightning would otherwise have landed in generic damage. The Trol remote-sync trace fired on a two-second timer for as long as a remote player existed, which in the main menu is forever: Player.m_localPlayer is null there, so the character preview counts as remote and it never stopped. Keyed on the state it reports instead, so it still catches a remote player being sized wrongly without narrating an idle menu.
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 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 && Input.GetKeyDown(DvergarConfig.RunicPingKey))
|
|
{
|
|
TryRunicPing(player);
|
|
}
|
|
|
|
if (rules.RunicOvercharge && Input.GetKeyDown(DvergarConfig.RunicOverchargeKey))
|
|
{
|
|
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;
|
|
}
|
|
}
|
|
}
|