From fc5d6b8abcda6f30b91ce6ae228455260386731f Mon Sep 17 00:00:00 2001 From: kanym Date: Thu, 29 Oct 2026 19:33:21 +0100 Subject: [PATCH] feat: Fenrir forms sense nearby creatures like the Aswid Every Fenrir form (Wolf, Ulv, Fenring, Cultist) now lights each untamed creature within 100 m with the Aswid's green glow; the human does not. The glow moved out of AswidRace into a shared HunterSenses, which the Aswid now calls too, unchanged. New setting Fenrir - Superhuman Senses / Detection Radius; the light follows the Aswid's Marker Light settings. Compendium line in English, Italian and Russian. Asked for by a friend of MrBiffty. --- JotunnModStub/Aswid/AswidRace.cs | 73 +-------------- JotunnModStub/Fenrir/FenrirConfig.cs | 5 + JotunnModStub/Fenrir/FenrirRace.cs | 5 + JotunnModStub/HunterSenses.cs | 92 +++++++++++++++++++ JotunnModStub/RaceCompendium.cs | 3 + .../Translations/English/compendium.json | 1 + .../Translations/Italian/compendium.json | 1 + .../Translations/Russian/compendium.json | 1 + 8 files changed, 111 insertions(+), 70 deletions(-) create mode 100644 JotunnModStub/HunterSenses.cs diff --git a/JotunnModStub/Aswid/AswidRace.cs b/JotunnModStub/Aswid/AswidRace.cs index 24ae745..556d8d5 100644 --- a/JotunnModStub/Aswid/AswidRace.cs +++ b/JotunnModStub/Aswid/AswidRace.cs @@ -329,9 +329,6 @@ namespace RacesOfValheim } private float m_tintCheckTimer = 0f; - private float sensesCheckTimer = 0f; - - private Dictionary activeSensesLight = new Dictionary(); 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 allChars = Character.GetAllCharacters(); - Vector3 myPos = Player.m_localPlayer.transform.position; - - int markHash = "SE_AswidSensesMark".GetStableHashCode(); - HashSet inRangeChars = new HashSet(); - - 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(); - 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 keysToRemove = new List(); - 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); - } + int markHash = "SE_AswidSensesMark".GetStableHashCode(); + 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() diff --git a/JotunnModStub/Fenrir/FenrirConfig.cs b/JotunnModStub/Fenrir/FenrirConfig.cs index 5644b29..4b8c4fa 100644 --- a/JotunnModStub/Fenrir/FenrirConfig.cs +++ b/JotunnModStub/Fenrir/FenrirConfig.cs @@ -38,6 +38,7 @@ namespace RacesOfValheim public static ConfigEntry SpeedBonusPerState; public static ConfigEntry JumpBonusPerState; public static ConfigEntry SunSicknessDuration; + public static ConfigEntry SensesRadius; // ─── Form buffs (applied while transformed) ─────────────────────────── public static ConfigEntry 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(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(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, diff --git a/JotunnModStub/Fenrir/FenrirRace.cs b/JotunnModStub/Fenrir/FenrirRace.cs index 963737b..f23e140 100644 --- a/JotunnModStub/Fenrir/FenrirRace.cs +++ b/JotunnModStub/Fenrir/FenrirRace.cs @@ -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) { diff --git a/JotunnModStub/HunterSenses.cs b/JotunnModStub/HunterSenses.cs new file mode 100644 index 0000000..2346435 --- /dev/null +++ b/JotunnModStub/HunterSenses.cs @@ -0,0 +1,92 @@ +using System; +using System.Collections.Generic; +using UnityEngine; + +namespace RacesOfValheim +{ + /// + /// 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. + /// + public static class HunterSenses + { + private static readonly Dictionary lights = new Dictionary(); + private static float timer; + + /// + /// 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). + /// + public static void Tick(float radius, Action 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 inRange = new HashSet(); + + 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(); + 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 keysToRemove = new List(); + 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); + } + + /// Puts every light out, for when the senses end (a form reverts, a tier is lost). + 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; + } + } +} diff --git a/JotunnModStub/RaceCompendium.cs b/JotunnModStub/RaceCompendium.cs index 1cbc5de..32b7569 100644 --- a/JotunnModStub/RaceCompendium.cs +++ b/JotunnModStub/RaceCompendium.cs @@ -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) { diff --git a/JotunnModStub/Translations/English/compendium.json b/JotunnModStub/Translations/English/compendium.json index d77d928..72ae977 100644 --- a/JotunnModStub/Translations/English/compendium.json +++ b/JotunnModStub/Translations/English/compendium.json @@ -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", diff --git a/JotunnModStub/Translations/Italian/compendium.json b/JotunnModStub/Translations/Italian/compendium.json index 2d648a8..c7baaa3 100644 --- a/JotunnModStub/Translations/Italian/compendium.json +++ b/JotunnModStub/Translations/Italian/compendium.json @@ -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", diff --git a/JotunnModStub/Translations/Russian/compendium.json b/JotunnModStub/Translations/Russian/compendium.json index f48cf86..795ddc2 100644 --- a/JotunnModStub/Translations/Russian/compendium.json +++ b/JotunnModStub/Translations/Russian/compendium.json @@ -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",