From 53f6fb71a2dee8427da8f8e96accd2b765e34be3 Mon Sep 17 00:00:00 2001 From: kanym Date: Sat, 24 Oct 2026 15:28:04 +0200 Subject: [PATCH] fix(skeleton): Auto-Resurrect on the real deathblow; Summon on Kill toggle Auto-Resurrect was decided in the Character.Damage prefix on the raw hit: before armour, blocking and resistances, with poison and fire counted in full. With good armour it fired on almost any hit. Damage also runs on the attacker's owner, so on a dedicated server a mob owned by the server or another player skipped the check entirely. It now runs in an ApplyDamage prefix, on the victim's own client, against the damage that is about to land. The rising-from-the-ground immunity is checked there too. Summon on Kill gets a toggle key (G, Skeleton - Keybinds) and a gamepad radial entry. The choice is saved on the character, on by default. A "Raise the Dead" status icon with the Dead Raiser's picture shows while it is on. Texts in English, Italian and Russian. --- JotunnModStub/RaceRadial.cs | 3 + JotunnModStub/Skeleton/SkeletonConfig.cs | 9 ++ JotunnModStub/Skeleton/SkeletonPatches.cs | 84 ++++++++++++------- JotunnModStub/Skeleton/SkeletonRace.cs | 70 ++++++++++++++++ .../Translations/English/messages.json | 5 +- .../Translations/English/status_effects.json | 4 +- .../Translations/Italian/messages.json | 5 +- .../Translations/Italian/status_effects.json | 4 +- .../Translations/Russian/messages.json | 5 +- .../Translations/Russian/status_effects.json | 4 +- 10 files changed, 158 insertions(+), 35 deletions(-) diff --git a/JotunnModStub/RaceRadial.cs b/JotunnModStub/RaceRadial.cs index 3e4e0da..a3dfc6b 100644 --- a/JotunnModStub/RaceRadial.cs +++ b/JotunnModStub/RaceRadial.cs @@ -72,6 +72,9 @@ namespace RacesOfValheim new Entry { Race = "Sverm", Label = "Ravager Strain", Key = () => SvermConfigManagement.RavagerKey, Icon = "TrophySeekerBrute" }, + new Entry { Race = "Skeleton", Label = "Summon on Kill", Key = () => SkeletonConfig.SummonToggleKey, Icon = "StaffSkeleton", + Available = player => SkeletonProgression.GetRules(BossProgressionManager.GetCurrentProgressionState()).SummonOnKill }, + // Any race: shown to whoever RaceClawSet has claws for. new Entry { Race = null, Label = "Grow Claws", Key = () => RaceClawsConfig.ActivateKey, Icon = "TrophyWolf", Available = player => RaceClawSet.For(player) != null }, diff --git a/JotunnModStub/Skeleton/SkeletonConfig.cs b/JotunnModStub/Skeleton/SkeletonConfig.cs index c6b8ba6..c5a9abf 100644 --- a/JotunnModStub/Skeleton/SkeletonConfig.cs +++ b/JotunnModStub/Skeleton/SkeletonConfig.cs @@ -1,4 +1,5 @@ using BepInEx.Configuration; +using UnityEngine; namespace RacesOfValheim { @@ -39,6 +40,9 @@ namespace RacesOfValheim // ─── Resurrection (tier 6+) ──────────────────────────────────────────── public static ConfigEntry ResurrectionCooldown; + // ─── Keybinds ────────────────────────────────────────────────────────── + public static ConfigEntry SummonToggleKey; + // ─── Visuals ─────────────────────────────────────────────────────────── public static ConfigEntry HeadFireVFXEnabled; public static ConfigEntry BodyModelEnabled; @@ -65,6 +69,11 @@ namespace RacesOfValheim FireAuraTickInterval = config.Bind(aura, "Tick Interval", 1f, new ConfigDescription("Seconds between aura damage ticks.", new AcceptableValueRange(0.1f, 5f))); + // G is the first ability key of every race that has one; the Skeleton had none. + const string keybinds = "Skeleton - Keybinds"; + SummonToggleKey = config.Bind(keybinds, "Toggle Summon on Kill", new KeyboardShortcut(KeyCode.G), + "Turns raising a skeleton from each kill on and off (The Queen and later). The Dead Raiser icon shows while it is on."); + const string resurrection = "Skeleton - Resurrection"; ResurrectionCooldown = config.Bind(resurrection, "Cooldown", 300f, new ConfigDescription("Seconds between auto-resurrections, tier 6+.", new AcceptableValueRange(0f, 3600f))); diff --git a/JotunnModStub/Skeleton/SkeletonPatches.cs b/JotunnModStub/Skeleton/SkeletonPatches.cs index 461fa75..8bfab05 100644 --- a/JotunnModStub/Skeleton/SkeletonPatches.cs +++ b/JotunnModStub/Skeleton/SkeletonPatches.cs @@ -597,6 +597,58 @@ namespace RacesOfValheim } } + /// + /// Auto-Resurrect, decided on the hit that would actually kill. + /// + /// It used to be decided in the Character.Damage prefix below, on hit.GetTotalDamage(), + /// and that number is the raw hit: before armour, blocking and resistances, and with the + /// hit's poison and fire counted in full although vanilla splits those off and lands them + /// over time. Any hit whose raw size beat the current health raised the Skeleton, so with + /// good armour it fired on "just about any damage" (akira's report). Damage also runs on + /// whoever owns the attacker, so on a dedicated server a mob owned by the server or by + /// another player never reached this check at all, and a real deathblow went through. + /// + /// ApplyDamage is what RPC_Damage calls on the victim's owner, after armour, blocking and + /// resistances, with poison, fire and spirit already moved out into their status effects. + /// Those effects come back through here on each tick, so a lethal tick still counts. The + /// one scaling left inside ApplyDamage for a player is the damage-taken rate. + /// + [HarmonyPatch(typeof(Character), nameof(Character.ApplyDamage))] + public static class Skeleton_ApplyDamage_Patch + { + private static readonly int CooldownHash = "SE_SkeletonResurrectCooldown".GetStableHashCode(); + + public static bool Prefix(Character __instance, HitData hit) + { + Player player = Player.m_localPlayer; + if (player == null || __instance != player) return true; + + // Here as well as in the Damage prefix, which only sees hits thrown from this client. + if (SkeletonRise.IsRising(player)) return false; + + if (!SkeletonRace.IsSkeleton() || player.IsDead()) return true; + if (!SkeletonProgression.GetRules(BossProgressionManager.GetCurrentProgressionState()).AutoResurrect) return true; + + float damage = hit.GetTotalDamage() * Game.m_localDamgeTakenRate; + if (damage < player.GetHealth()) return true; + if (player.GetSEMan().HaveStatusEffect(CooldownHash)) return true; + + player.Heal(player.GetMaxHealth(), true); + player.GetSEMan().AddStatusEffect(CooldownHash, true); + + // Confirmed real via 'listprefabs'; see SummonOnKill below. + GameObject vfx = PrefabManager.Cache.GetPrefab("fx_summon_skeleton_spawn") ?? + PrefabManager.Cache.GetPrefab("fx_summon_skeleton"); + if (vfx != null) UnityEngine.Object.Instantiate(vfx, player.transform.position, Quaternion.identity); + + // The body climbs out of the ground the way a crypt skeleton does. + SkeletonRise.Begin(player); + + player.Message(MessageHud.MessageType.Center, ModText.Get("rov_msg_skeleton_have_been_resurrected_by_dark")); + return false; // the lethal hit never lands + } + } + [HarmonyPatch(typeof(Character), "Damage")] public static class Character_Damage_Patch { @@ -624,34 +676,8 @@ namespace RacesOfValheim // Half in the ground: nothing lands on a Skeleton while it climbs back out. if (__instance == Player.m_localPlayer && SkeletonRise.IsRising(Player.m_localPlayer)) return false; - // Auto-Resurrect check - if (__instance == Player.m_localPlayer && SkeletonRace.IsSkeleton() && rules.AutoResurrect) - { - if (hit.GetTotalDamage() >= __instance.GetHealth()) - { - if (!Player.m_localPlayer.GetSEMan().HaveStatusEffect("SE_SkeletonResurrectCooldown".GetStableHashCode())) - { - // Cancel death! - Player.m_localPlayer.Heal(Player.m_localPlayer.GetMaxHealth(), true); - Player.m_localPlayer.GetSEMan().AddStatusEffect("SE_SkeletonResurrectCooldown".GetStableHashCode(), true); - - // Spawn VFX - confirmed real via 'listprefabs'; see SummonOnKill below - // for how the previous two guesses here were caught and replaced. - GameObject vfx = PrefabManager.Cache.GetPrefab("fx_summon_skeleton_spawn") ?? - PrefabManager.Cache.GetPrefab("fx_summon_skeleton"); - if (vfx != null) - { - UnityEngine.Object.Instantiate(vfx, Player.m_localPlayer.transform.position, Quaternion.identity); - } - - // The body climbs out of the ground the way a crypt skeleton does. - SkeletonRise.Begin(Player.m_localPlayer); - - Player.m_localPlayer.Message(MessageHud.MessageType.Center, ModText.Get("rov_msg_skeleton_have_been_resurrected_by_dark")); - return false; // Skip applying this lethal damage - } - } - } + // The Auto-Resurrect check used to live here and is now in + // Skeleton_ApplyDamage_Patch below; see there for why. // Outgoing damage (Lifesteal, Poison, Stun) Character attacker = hit.GetAttacker(); @@ -740,7 +766,7 @@ namespace RacesOfValheim int state = BossProgressionManager.GetCurrentProgressionState(); var rules = SkeletonProgression.GetRules(state); - if (rules.SummonOnKill && !string.IsNullOrEmpty(rules.SummonPrefab)) + if (rules.SummonOnKill && SkeletonRace.SummonOnKillEnabled && !string.IsNullOrEmpty(rules.SummonPrefab)) { // Clean up dead minions activeMinions.RemoveAll(m => m == null || m.IsDead()); diff --git a/JotunnModStub/Skeleton/SkeletonRace.cs b/JotunnModStub/Skeleton/SkeletonRace.cs index 1895ed5..8a80c7e 100644 --- a/JotunnModStub/Skeleton/SkeletonRace.cs +++ b/JotunnModStub/Skeleton/SkeletonRace.cs @@ -48,6 +48,73 @@ namespace RacesOfValheim resurrectSE.name = "SE_SkeletonResurrectCooldown"; CustomStatusEffect customResurrectSE = new CustomStatusEffect(resurrectSE, fixReference: false); ItemManager.Instance.AddStatusEffect(customResurrectSE); + + // The "Summon on Kill is on" icon. The Dead Raiser's, since the Skeleton trophy is + // already Undead Fortitude's and this is the staff that raises skeletons in vanilla. + var raiseSE = ScriptableObject.CreateInstance(); + raiseSE.name = RaiseDeadEffectName; + raiseSE.m_name = "$rov_se_skeleton_raisedead_name"; + raiseSE.m_tooltip = "$rov_se_skeleton_raisedead_tooltip"; + raiseSE.m_icon = PrefabManager.Cache.GetPrefab("StaffSkeleton")?.m_itemData.GetIcon() + ?? PrefabManager.Cache.GetPrefab("TrophySkeleton")?.m_itemData.GetIcon(); + ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(raiseSE, fixReference: false)); + } + + // ─── Summon on Kill switch ────────────────────────────────────────── + + private const string RaiseDeadEffectName = "SE_SkeletonRaiseDead"; + private static readonly int RaiseDeadEffectHash = RaiseDeadEffectName.GetStableHashCode(); + + // Stored as "off" on the character, so a character that never pressed the key - every + // existing one - keeps the perk on. + private const string SummonOffKey = "RacesOfValheim_SkeletonSummonOff"; + + /// Whether this character wants a skeleton raised from each kill. Per character, saved with it. + public static bool SummonOnKillEnabled + { + get + { + Player player = Player.m_localPlayer; + return player == null || player.m_customData == null || !player.m_customData.ContainsKey(SummonOffKey); + } + set + { + Player player = Player.m_localPlayer; + if (player == null || player.m_customData == null) return; + if (value) player.m_customData.Remove(SummonOffKey); + else player.m_customData[SummonOffKey] = "1"; + } + } + + /// + /// The toggle key, and the icon that says the perk is on. The icon is put back whenever it + /// is missing, because status effects do not survive death or a relog. + /// + private static void TickSummonToggle(Player player, SkeletonProgression.SkeletonRules rules) + { + if (RaceInput.Allowed && SkeletonConfig.SummonToggleKey.Value.IsDownIgnoringHeldKeys()) + { + if (!rules.SummonOnKill) + { + player.Message(MessageHud.MessageType.Center, ModText.Get("rov_msg_skeleton_summon_locked")); + } + else + { + SummonOnKillEnabled = !SummonOnKillEnabled; + player.Message(MessageHud.MessageType.Center, + ModText.Get(SummonOnKillEnabled ? "rov_msg_skeleton_summon_on" : "rov_msg_skeleton_summon_off")); + } + } + + SetRaiseDeadIcon(player, rules.SummonOnKill && SummonOnKillEnabled); + } + + private static void SetRaiseDeadIcon(Player player, bool on) + { + SEMan seman = player.GetSEMan(); + bool has = seman.HaveStatusEffect(RaiseDeadEffectHash); + if (on && !has) seman.AddStatusEffect(RaiseDeadEffectHash, true); + else if (!on && has) seman.RemoveStatusEffect(RaiseDeadEffectHash, true); } public static bool IsSkeleton() @@ -272,6 +339,7 @@ namespace RacesOfValheim SkeletonVisuals.EnsureFireAura(Player.m_localPlayer, false, ref fireAuraVFX); headFlame.Apply(Player.m_localPlayer, false); RestoreJawBone(); + SetRaiseDeadIcon(Player.m_localPlayer, false); if (Player.m_localPlayer.transform.localScale != Vector3.one) { @@ -319,6 +387,8 @@ namespace RacesOfValheim int state = BossProgressionManager.GetCurrentProgressionState(); var rules = SkeletonProgression.GetRules(state); + TickSummonToggle(Player.m_localPlayer, rules); + // Continuously adjust equipment VisEquipment currentVis = Player.m_localPlayer.GetComponent(); if (currentVis != null) diff --git a/JotunnModStub/Translations/English/messages.json b/JotunnModStub/Translations/English/messages.json index 8f7c7fa..92fd052 100644 --- a/JotunnModStub/Translations/English/messages.json +++ b/JotunnModStub/Translations/English/messages.json @@ -202,5 +202,8 @@ "rov_msg_warvulture_vulture_settles_into_glide": "The vulture settles into a glide.", "rov_msg_warvulture_vulture_spirals_down": "The vulture spirals down.", "rov_msg_boneship_no_shore": "No shore in reach. They stay at the oars.", - "rov_msg_boneship_sunk": "The ship goes down, and $1 go with it." + "rov_msg_boneship_sunk": "The ship goes down, and $1 go with it.", + "rov_msg_skeleton_summon_on": "Summon on Kill: on. The dead will rise for you.", + "rov_msg_skeleton_summon_off": "Summon on Kill: off. The dead stay down.", + "rov_msg_skeleton_summon_locked": "Summon on Kill awakens once The Queen falls." } diff --git a/JotunnModStub/Translations/English/status_effects.json b/JotunnModStub/Translations/English/status_effects.json index ba0b959..dd86c98 100644 --- a/JotunnModStub/Translations/English/status_effects.json +++ b/JotunnModStub/Translations/English/status_effects.json @@ -58,5 +58,7 @@ "rov_se_trol_trueform_name": "True Form", "rov_se_trol_trueform_tooltip": "You have unleashed your inner troll!", "rov_se_trol_trueformcd_name": "True Form Cooldown", - "rov_se_trol_trueformcd_tooltip": "You are exhausted from your True Form." + "rov_se_trol_trueformcd_tooltip": "You are exhausted from your True Form.", + "rov_se_skeleton_raisedead_name": "Raise the Dead", + "rov_se_skeleton_raisedead_tooltip": "Each kill raises a skeleton to fight for you. Press the Summon on Kill key to turn it off." } diff --git a/JotunnModStub/Translations/Italian/messages.json b/JotunnModStub/Translations/Italian/messages.json index f0e20bb..1e1ee27 100644 --- a/JotunnModStub/Translations/Italian/messages.json +++ b/JotunnModStub/Translations/Italian/messages.json @@ -202,5 +202,8 @@ "rov_msg_warvulture_vulture_settles_into_glide": "L'avvoltoio si mette a planare.", "rov_msg_warvulture_vulture_spirals_down": "L'avvoltoio scende a spirale.", "rov_msg_boneship_no_shore": "Nessuna riva a portata. Restano ai remi.", - "rov_msg_boneship_sunk": "La nave affonda, e con lei $1." + "rov_msg_boneship_sunk": "La nave affonda, e con lei $1.", + "rov_msg_skeleton_summon_on": "Evoca all'uccisione: attiva. I morti si alzeranno per te.", + "rov_msg_skeleton_summon_off": "Evoca all'uccisione: disattiva. I morti restano a terra.", + "rov_msg_skeleton_summon_locked": "Evoca all'uccisione si risveglia quando cade la Regina." } diff --git a/JotunnModStub/Translations/Italian/status_effects.json b/JotunnModStub/Translations/Italian/status_effects.json index e4e391c..ed8a813 100644 --- a/JotunnModStub/Translations/Italian/status_effects.json +++ b/JotunnModStub/Translations/Italian/status_effects.json @@ -58,5 +58,7 @@ "rov_se_trol_trueform_name": "Vera forma", "rov_se_trol_trueform_tooltip": "Hai scatenato il troll che è in te!", "rov_se_trol_trueformcd_name": "Ricarica vera forma", - "rov_se_trol_trueformcd_tooltip": "Sei esausto dopo la tua vera forma." + "rov_se_trol_trueformcd_tooltip": "Sei esausto dopo la tua vera forma.", + "rov_se_skeleton_raisedead_name": "Risveglio dei morti", + "rov_se_skeleton_raisedead_tooltip": "Ogni uccisione fa risorgere uno scheletro che combatte per te. Premi il tasto di Evoca all'uccisione per disattivarlo." } diff --git a/JotunnModStub/Translations/Russian/messages.json b/JotunnModStub/Translations/Russian/messages.json index 3ef6918..128bd9a 100644 --- a/JotunnModStub/Translations/Russian/messages.json +++ b/JotunnModStub/Translations/Russian/messages.json @@ -202,5 +202,8 @@ "rov_msg_warvulture_vulture_settles_into_glide": "Стервятник переходит в планирующий полет.", "rov_msg_warvulture_vulture_spirals_down": "Стервятник кружит, спускаясь по спирали.", "rov_msg_boneship_no_shore": "Берега не видно. Они остаются на веслах.", - "rov_msg_boneship_sunk": "Корабль идет ко дну, и $1 вместе с ним." + "rov_msg_boneship_sunk": "Корабль идет ко дну, и $1 вместе с ним.", + "rov_msg_skeleton_summon_on": "Призыв при убийстве: включён. Мёртвые восстанут ради тебя.", + "rov_msg_skeleton_summon_off": "Призыв при убийстве: выключен. Мёртвые остаются лежать.", + "rov_msg_skeleton_summon_locked": "Призыв при убийстве пробудится, когда падёт Королева." } diff --git a/JotunnModStub/Translations/Russian/status_effects.json b/JotunnModStub/Translations/Russian/status_effects.json index f1f2d58..d38df6e 100644 --- a/JotunnModStub/Translations/Russian/status_effects.json +++ b/JotunnModStub/Translations/Russian/status_effects.json @@ -58,5 +58,7 @@ "rov_se_trol_trueform_name": "Истинный облик", "rov_se_trol_trueform_tooltip": "Вы выпустили своего внутреннего тролля на свободу!", "rov_se_trol_trueformcd_name": "Перезарядка истинного облика", - "rov_se_trol_trueformcd_tooltip": "Вы истощены после пребывания в Истинном облике." + "rov_se_trol_trueformcd_tooltip": "Вы истощены после пребывания в Истинном облике.", + "rov_se_skeleton_raisedead_name": "Восстание мёртвых", + "rov_se_skeleton_raisedead_tooltip": "Каждое убийство поднимает скелета, который сражается за тебя. Нажми клавишу призыва при убийстве, чтобы выключить." }