Merge branch 'fix-skeleton-resurrect-summon-toggle': Auto-Resurrect on the real deathblow, Summon on Kill toggle

This commit is contained in:
kanym 2026-10-24 15:50:51 +02:00
commit 9308ce062c
10 changed files with 162 additions and 35 deletions

View file

@ -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 },

View file

@ -1,4 +1,5 @@
using BepInEx.Configuration;
using UnityEngine;
namespace RacesOfValheim
{
@ -39,9 +40,13 @@ namespace RacesOfValheim
// ─── Resurrection (tier 6+) ────────────────────────────────────────────
public static ConfigEntry<float> ResurrectionCooldown;
// ─── Keybinds ──────────────────────────────────────────────────────────
public static ConfigEntry<KeyboardShortcut> SummonToggleKey;
// ─── Visuals ───────────────────────────────────────────────────────────
public static ConfigEntry<bool> HeadFireVFXEnabled;
public static ConfigEntry<bool> BodyModelEnabled;
public static ConfigEntry<bool> RaiseDeadIcon;
public static void Bind(ConfigFile config)
{
@ -65,6 +70,11 @@ namespace RacesOfValheim
FireAuraTickInterval = config.Bind(aura, "Tick Interval", 1f,
new ConfigDescription("Seconds between aura damage ticks.", new AcceptableValueRange<float>(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 Raise the Dead 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<float>(0f, 3600f)));
@ -74,6 +84,8 @@ namespace RacesOfValheim
new ConfigDescription("Whether the burning-skull effect (worn from tier 5+) renders at all. A client-side preference: disabling it stops you from seeing it on yourself and on every other skeleton you look at, but does not change what other players see."));
BodyModelEnabled = config.Bind(visuals, "Body Model Enabled", true,
new ConfigDescription("Whether Skeleton players wear the skeleton body. Turn it off if you use a player model mod (EnhancedValheimVRM and the like): Skeletons then keep the vanilla viking body, so the replacement model shows without bones clipping through it. Abilities are unchanged. Client-side, like the option above: it applies to every Skeleton you see, yourself included, and changes nothing for other players."));
RaiseDeadIcon = config.Bind(visuals, "Raise the Dead Icon", true,
new ConfigDescription("Shows the Raise the Dead status icon while your Summon on Kill is on."));
}
}
}

View file

@ -597,6 +597,58 @@ namespace RacesOfValheim
}
}
/// <summary>
/// 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.
/// </summary>
[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<GameObject>("fx_summon_skeleton_spawn") ??
PrefabManager.Cache.GetPrefab<GameObject>("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<GameObject>("fx_summon_skeleton_spawn") ??
PrefabManager.Cache.GetPrefab<GameObject>("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());

View file

@ -48,6 +48,74 @@ 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<StatusEffect>();
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<ItemDrop>("StaffSkeleton")?.m_itemData.GetIcon()
?? PrefabManager.Cache.GetPrefab<ItemDrop>("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";
/// <summary>Whether this character wants a skeleton raised from each kill. Per character, saved with it.</summary>
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";
}
}
/// <summary>
/// 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.
/// </summary>
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"));
}
}
bool on = rules.SummonOnKill && SummonOnKillEnabled;
SetRaiseDeadIcon(player, on && SkeletonConfig.RaiseDeadIcon.Value);
}
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 +340,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 +388,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<VisEquipment>();
if (currentVis != null)

View file

@ -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": "Thy dead shall rise again.",
"rov_msg_skeleton_summon_off": "Raising... nevermore.",
"rov_msg_skeleton_summon_locked": "Summon on Kill awakens once The Queen falls."
}

View file

@ -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."
}

View file

@ -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": "I tuoi morti risorgeranno ancora.",
"rov_msg_skeleton_summon_off": "Risorgere... mai più.",
"rov_msg_skeleton_summon_locked": "Evoca all'uccisione si risveglia quando cade la Regina."
}

View file

@ -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."
}

View file

@ -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": "Призыв при убийстве пробудится, когда падёт Королева."
}

View file

@ -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": "Каждое убийство поднимает скелета, который сражается за тебя. Нажми клавишу призыва при убийстве, чтобы выключить."
}