Merge branch 'feat-fenrir-senses': Fenrir forms sense nearby creatures

This commit is contained in:
kanym 2026-10-29 19:34:07 +01:00
commit 578ecbb591
8 changed files with 111 additions and 70 deletions

View file

@ -329,9 +329,6 @@ namespace RacesOfValheim
}
private float m_tintCheckTimer = 0f;
private float sensesCheckTimer = 0f;
private Dictionary<Character, GameObject> activeSensesLight = new Dictionary<Character, GameObject>();
public static float GetEnslaveCooldown()
{
@ -373,6 +370,7 @@ namespace RacesOfValheim
{
seman.RemoveStatusEffect(myHash);
}
HunterSenses.Clear();
return;
}
@ -381,64 +379,8 @@ namespace RacesOfValheim
seman.AddStatusEffect(myHash, true);
}
sensesCheckTimer -= Time.deltaTime;
if (sensesCheckTimer <= 0f)
{
sensesCheckTimer = AswidConfig.SensesRefreshInterval.Value; // TTL is 2s
List<Character> allChars = Character.GetAllCharacters();
Vector3 myPos = Player.m_localPlayer.transform.position;
int markHash = "SE_AswidSensesMark".GetStableHashCode();
HashSet<Character> inRangeChars = new HashSet<Character>();
foreach (var c in allChars)
{
if (c == null || c == Player.m_localPlayer || c.IsDead() || c.IsTamed()) continue;
float dist = Vector3.Distance(c.transform.position, myPos);
if (dist <= AswidConfig.SensesRadius.Value)
{
try
{
inRangeChars.Add(c);
c.GetSEMan().AddStatusEffect(markHash, true); // Keep the malus as requested
// Locally generate the visual
if (!activeSensesLight.ContainsKey(c))
{
GameObject lightObj = new GameObject("AswidSensesLight");
lightObj.transform.SetParent(c.transform);
lightObj.transform.position = c.GetCenterPoint();
Light pLight = lightObj.AddComponent<Light>();
pLight.type = LightType.Point;
pLight.color = Color.green;
pLight.range = AswidConfig.SensesLightRange.Value;
pLight.intensity = AswidConfig.SensesLightIntensity.Value;
pLight.shadows = LightShadows.None;
activeSensesLight[c] = lightObj;
}
}
catch (Exception ex)
{
Jotunn.Logger.LogError($"[Aswid] Error processing mob {c.name}: {ex}");
}
}
}
List<Character> keysToRemove = new List<Character>();
foreach (var kvp in activeSensesLight)
{
if (kvp.Key == null || kvp.Key.IsDead() || !inRangeChars.Contains(kvp.Key))
{
if (kvp.Value != null) Destroy(kvp.Value);
keysToRemove.Add(kvp.Key);
}
}
foreach (var k in keysToRemove) activeSensesLight.Remove(k);
}
HunterSenses.Tick(AswidConfig.SensesRadius.Value, c => c.GetSEMan().AddStatusEffect(markHash, true));
}
catch (Exception ex)
{
@ -446,15 +388,6 @@ namespace RacesOfValheim
}
}
private void ClearSuperhumanSenses()
{
foreach (var kvp in activeSensesLight)
{
if (kvp.Value != null) Destroy(kvp.Value);
}
activeSensesLight.Clear();
}
private bool? wasNight = null;
private void Update()

View file

@ -38,6 +38,7 @@ namespace RacesOfValheim
public static ConfigEntry<float> SpeedBonusPerState;
public static ConfigEntry<float> JumpBonusPerState;
public static ConfigEntry<float> SunSicknessDuration;
public static ConfigEntry<float> SensesRadius;
// ─── Form buffs (applied while transformed) ───────────────────────────
public static ConfigEntry<float> FullFormSpeedBonus;
@ -131,6 +132,10 @@ namespace RacesOfValheim
SunSicknessDuration = config.Bind(combat, "Sun Sickness Duration", 60f,
new ConfigDescription("Seconds of forced human form after being reverted by sunrise.", new AcceptableValueRange<float>(0f, 300f)));
const string senses = "Fenrir - Superhuman Senses";
SensesRadius = config.Bind(senses, "Detection Radius", 100f,
new ConfigDescription("Meters within which nearby creatures glow green while you are in any form. The light itself follows the Aswid's Marker Light settings.", new AcceptableValueRange<float>(10f, 300f)));
const string buffs = "Fenrir - Form Buffs";
BindNote(config, buffs, "Note: these values need a relog to take effect.");
FullFormSpeedBonus = config.Bind(buffs, "Full Form Speed Bonus", 1.0f,

View file

@ -164,6 +164,10 @@ namespace RacesOfValheim {
}
}
// The hunter's senses, shared with the Aswid: every form has them, the human does not.
if (isTransformed) HunterSenses.Tick(FenrirConfig.SensesRadius.Value);
else HunterSenses.Clear();
if (!RaceInput.Allowed) return;
int state = BossProgressionManager.GetCurrentProgressionState();
@ -412,6 +416,7 @@ namespace RacesOfValheim {
private IEnumerator RevertToHumanRoutine()
{
isTransformingSequence = true;
HunterSenses.Clear();
if (currentTransformation != null)
{

View file

@ -0,0 +1,92 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace RacesOfValheim
{
/// <summary>
/// The hunter's senses the Aswid and the Fenrir share: every untamed creature within a radius
/// gets a green light, seen only by the local player. The Aswid has it as a passive from Moder,
/// the Fenrir in any of its four forms.
///
/// The lights are local GameObjects parented to the creature, so nothing goes on the network.
/// The light's range and strength are the Aswid's settings; each race brings its own radius.
/// </summary>
public static class HunterSenses
{
private static readonly Dictionary<Character, GameObject> lights = new Dictionary<Character, GameObject>();
private static float timer;
/// <summary>
/// Called every frame while the senses are on. Sweeps once per refresh interval;
/// onSensed runs for each creature in range (the Aswid marks them with its status effect).
/// </summary>
public static void Tick(float radius, Action<Character> onSensed = null)
{
Player player = Player.m_localPlayer;
if (player == null) return;
timer -= Time.deltaTime;
if (timer > 0f) return;
timer = AswidConfig.SensesRefreshInterval.Value;
Vector3 myPos = player.transform.position;
HashSet<Character> inRange = new HashSet<Character>();
foreach (Character c in Character.GetAllCharacters())
{
if (c == null || c == player || c.IsDead() || c.IsTamed()) continue;
if (Vector3.Distance(c.transform.position, myPos) > radius) continue;
try
{
inRange.Add(c);
onSensed?.Invoke(c);
if (!lights.ContainsKey(c))
{
GameObject lightObj = new GameObject("AswidSensesLight");
lightObj.transform.SetParent(c.transform);
lightObj.transform.position = c.GetCenterPoint();
Light pLight = lightObj.AddComponent<Light>();
pLight.type = LightType.Point;
pLight.color = Color.green;
pLight.range = AswidConfig.SensesLightRange.Value;
pLight.intensity = AswidConfig.SensesLightIntensity.Value;
pLight.shadows = LightShadows.None;
lights[c] = lightObj;
}
}
catch (Exception ex)
{
Jotunn.Logger.LogError($"[Senses] Error processing mob {c.name}: {ex}");
}
}
List<Character> keysToRemove = new List<Character>();
foreach (var kvp in lights)
{
if (kvp.Key == null || kvp.Key.IsDead() || !inRange.Contains(kvp.Key))
{
if (kvp.Value != null) UnityEngine.Object.Destroy(kvp.Value);
keysToRemove.Add(kvp.Key);
}
}
foreach (var k in keysToRemove) lights.Remove(k);
}
/// <summary>Puts every light out, for when the senses end (a form reverts, a tier is lost).</summary>
public static void Clear()
{
if (lights.Count == 0) return;
foreach (var kvp in lights)
{
if (kvp.Value != null) UnityEngine.Object.Destroy(kvp.Value);
}
lights.Clear();
timer = 0f;
}
}
}

View file

@ -586,7 +586,10 @@ namespace RacesOfValheim
sb.AppendLine(ModText.Get("rov_compendium_fenrir_cursed_claws_s_wolf_s", (RaceClawsConfig.DurationSeconds.Value).ToString("0"), (SvermClaws.GetDamagePercent(state) * 100f).ToString("0")));
if (state >= 3)
{
sb.AppendLine(ModText.Get("rov_compendium_fenrir_wolf_form_g_key_night"));
sb.AppendLine(ModText.Get("rov_compendium_fenrir_senses_in_form", Mathf.RoundToInt(FenrirConfig.SensesRadius.Value)));
}
if (state >= 4)
{

View file

@ -93,6 +93,7 @@
"rov_compendium_fenrir_fenring_form_h_key_night": "[Moder Unlock] Fenring Form ('H' Key, night only): Stand as a true Fenring - heavy claws and a leaping strike, and the strongest of the four shapes so far.\n",
"rov_compendium_fenrir_fenring_form_now_answers_by": "[The Queen Unlock] Fenring Form now answers by day as well as night.\n",
"rov_compendium_fenrir_g_now_calls_ulv_form": "[Moder Unlock] 'G' now calls Ulv Form instead of Wolf, and answers by day as well as night.\n",
"rov_compendium_fenrir_senses_in_form": "In any form you sense every untamed creature within $1m, marking it with a telltale glow, as the Aswid do.\n",
"rov_compendium_fenrir_sunrise_breaks_any_night_bound": "Sunrise breaks any night-bound form early and leaves the beast too tired to change shape again for a short while after.\n",
"rov_compendium_fenrir_title": "Fenrir Secrets",
"rov_compendium_fenrir_ulv_form_h_key_night": "[Bonemass Unlock] Ulv Form ('H' Key, night only): A heavier wolf shape - stronger bite attacks, still bound to the dark.\n",

View file

@ -93,6 +93,7 @@
"rov_compendium_fenrir_fenring_form_h_key_night": "[Sblocco Moder] Forma di Fenring (tasto 'H', solo di notte): ergiti come un vero Fenring, con artigli pesanti e un attacco in salto, la più forte delle quattro forme finora.\n",
"rov_compendium_fenrir_fenring_form_now_answers_by": "[Sblocco Regina] La forma di Fenring ora risponde di giorno come di notte.\n",
"rov_compendium_fenrir_g_now_calls_ulv_form": "[Sblocco Moder] 'G' ora richiama la forma di Ulv invece del Lupo, e risponde di giorno come di notte.\n",
"rov_compendium_fenrir_senses_in_form": "In qualsiasi forma percepisci ogni creatura non addomesticata entro $1m, e la segni con un bagliore rivelatore, come fanno gli Aswid.\n",
"rov_compendium_fenrir_sunrise_breaks_any_night_bound": "L'alba spezza in anticipo ogni forma legata alla notte, e lascia la bestia troppo stanca per cambiare di nuovo forma per un po'.\n",
"rov_compendium_fenrir_title": "Segreti dei Fenrir",
"rov_compendium_fenrir_ulv_form_h_key_night": "[Sblocco Massa d'ossa] Forma di Ulv (tasto 'H', solo di notte): una forma di lupo più pesante, con morsi più forti, ancora legata al buio.\n",

View file

@ -93,6 +93,7 @@
"rov_compendium_fenrir_fenring_form_h_key_night": "[Награда: Матерь] Облик фенринга (клавиша «H», только ночью): Станьте истинным Фенрингом — тяжелые когти, сокрушительный удар в прыжке и мощнейшая из четырех форм на данный момент.\n",
"rov_compendium_fenrir_fenring_form_now_answers_by": "[Награда: Королева] Облик фенринга теперь доступен как днем, так и ночью.\n",
"rov_compendium_fenrir_g_now_calls_ulv_form": "[Награда: Матерь] Клавиша «G» теперь призывает облик Ульва вместо Волка и доступна и днем, и ночью.\n",
"rov_compendium_fenrir_senses_in_form": "В любой форме вы чувствуете любое неприрученное существо в радиусе $1 м, подсвечивая его характерным свечением, как Асвиды.\n",
"rov_compendium_fenrir_sunrise_breaks_any_night_bound": "Восход солнца прерывает любую ночную форму раньше срока и оставляет зверя истощенным, не позволяя перевоплощаться еще некоторое время.\n",
"rov_compendium_fenrir_title": "Тайны Фенрира",
"rov_compendium_fenrir_ulv_form_h_key_night": "[Награда: Масса костей] Облик ульва (клавиша «H», только ночью): Более тяжелая волчья форма — смертоносные укусы, по-прежнему скованные тьмой.\n",