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.
This commit is contained in:
parent
7411680553
commit
53f6fb71a2
10 changed files with 158 additions and 35 deletions
|
|
@ -1,4 +1,5 @@
|
|||
using BepInEx.Configuration;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
|
|
@ -39,6 +40,9 @@ 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;
|
||||
|
|
@ -65,6 +69,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 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<float>(0f, 3600f)));
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -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<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"));
|
||||
}
|
||||
}
|
||||
|
||||
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<VisEquipment>();
|
||||
if (currentVis != null)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue