fix(skeleton): Summon on Kill was completely dead - fix the whole chain

Queen/Fader-tier Skeletons were supposed to raise a tamed ally from every
kill, but nothing ever spawned. Several independent bugs stacked up:

- Kill attribution failed whenever the death blow was a poison DOT tick
  (SE_Poison builds its own attacker-less HitData every second, and
  Character.ApplyDamage overwrites m_lastHit on every one of those ticks).
  Since PoisonAttacks bakes bonus poison onto every Skeleton hit from
  Bonemass on, this was the common case, not an edge case. Character_Damage_Patch
  now tracks recent player hits per ZDOID as a fallback (RecentSkeletonHits),
  the same pattern Aswid's own life-drain-kill check already uses.
- SummonPrefabName pointed at "Skeleton_friendly", which isn't a real
  prefab (confirmed against the live ZNetScene registry). Reuses the
  Bound Bone Pile's own SkeletonThrall_Melee instead - tamed, loot-stripped,
  forced-melee, and already proven to work.
- The rise VFX names ("vfx_skeleton_spawn", "vfx_bloodmagic_aoe") were
  guesses that never existed either; fx_summon_skeleton_spawn is the real
  one. Same fix applied to the pre-existing Auto-Resurrect effect, which
  had the identical wrong names.
- The actual "climbing out of the ground" motion is a separate Animator
  bool ("wakeup") set via ZSyncAnimation - the exact call vanilla's own
  CreatureSpawner makes. Without it the model was simply active from
  frame one, VFX playing around a skeleton that was already standing.
- Vanilla skeletons carry no Tameable component, which spammed "is tamed
  but missing tameable or monster AI script!" every time a raised one
  landed a hit. Same fix Fenrir already uses for the Ulv and Fenring:
  copy one in from the vanilla Wolf, done once at prefab registration so
  it also quietly fixes the Bound Bone Pile's own thralls.
- Added RaisedThrall.SetExpiry(), a station-independent hard lifespan -
  these skeletons are never bound to a pile, so the existing anchor/wither
  pair had nothing to key off. Summoned skeletons now wither 2 minutes
  after being raised.

Also adds a permanent `listprefabs <substring>` debug console command -
queries the live ZNetScene registry directly, which is how the wrong
prefab/VFX names above were actually confirmed rather than guessed.
This commit is contained in:
kanym 2026-08-29 16:01:23 +02:00
commit 8c24ae3340
5 changed files with 232 additions and 12 deletions

View file

@ -583,6 +583,18 @@ namespace RacesOfValheim
{
private static float lastStunTime = 0f;
// SummonOnKill needs to know "did the local Skeleton player damage this creature
// recently", not just "who threw the exact hit that zeroed its health" - a poison
// DOT tick (SE_Poison.UpdateStatusEffect) builds its own HitData every second with no
// attacker set at all, and Character.ApplyDamage overwrites m_lastHit on every one of
// those ticks. Since PoisonAttacks bakes bonus poison onto every Skeleton hit from
// Bonemass on, a large share of kills finish on an attacker-less poison tick rather
// than the swing itself - Character_OnDeath_Patch falls back to this map when that
// happens. Keyed by ZDOID rather than Character, since the character can already be
// gone by the time OnDeath's Prefix runs.
public static readonly System.Collections.Generic.Dictionary<ZDOID, float> RecentSkeletonHits =
new System.Collections.Generic.Dictionary<ZDOID, float>();
public static bool Prefix(Character __instance, HitData hit)
{
if (Player.m_localPlayer == null) return true;
@ -601,9 +613,10 @@ namespace RacesOfValheim
Player.m_localPlayer.Heal(Player.m_localPlayer.GetMaxHealth(), true);
Player.m_localPlayer.GetSEMan().AddStatusEffect("SE_SkeletonResurrectCooldown".GetStableHashCode(), true);
// Spawn VFX
GameObject vfx = PrefabManager.Cache.GetPrefab<GameObject>("vfx_skeleton_spawn") ??
PrefabManager.Cache.GetPrefab<GameObject>("vfx_bloodmagic_aoe");
// 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);
@ -619,6 +632,8 @@ namespace RacesOfValheim
Character attacker = hit.GetAttacker();
if (attacker != null && attacker == Player.m_localPlayer && SkeletonRace.IsSkeleton())
{
RecentSkeletonHits[__instance.GetZDOID()] = Time.time;
// Auto Stun
if (rules.AutoStunFirstHit && Time.time - lastStunTime > SkeletonConfig.AutoStunCooldown.Value)
{
@ -653,12 +668,49 @@ namespace RacesOfValheim
{
public static System.Collections.Generic.List<Character> activeMinions = new System.Collections.Generic.List<Character>();
// How long a recent Skeleton hit still counts toward a kill once the actual death
// blow turns out to be an attacker-less poison tick. Poison's own TTL (SE_Poison,
// vanilla) can run well past 10s on a heavy stack, so this errs generous - the only
// cost of a false positive here is one extra friendly skeleton, not anything unsafe.
private const float KillAttributionWindow = 20f;
// How long a SummonOnKill skeleton lasts before it withers on its own. These are never
// bound to a pile, so RaisedThrall's normal anchor/wither pair has nothing to key off -
// this is the hard, station-independent cap added for exactly that case (see
// RaisedThrall.SetExpiry).
private const float SummonLifetimeSeconds = 120f;
public static void Prefix(Character __instance)
{
if (Player.m_localPlayer == null || !SkeletonRace.IsSkeleton()) return;
HitData lastHit = HarmonyLib.Traverse.Create(__instance).Field("m_lastHit").GetValue<HitData>();
if (lastHit != null && lastHit.GetAttacker() == Player.m_localPlayer)
bool killedByPlayer = lastHit != null && lastHit.GetAttacker() == Player.m_localPlayer;
ZDOID zdoid = __instance.GetZDOID();
if (!killedByPlayer &&
Character_Damage_Patch.RecentSkeletonHits.TryGetValue(zdoid, out float hitTime) &&
Time.time - hitTime <= KillAttributionWindow)
{
// The death blow was very likely an attacker-less poison DOT tick - see the
// comment on RecentSkeletonHits. Credit the kill anyway.
killedByPlayer = true;
}
// The map only needs to remember live targets; drop this one and anything else
// that's aged out, so it can't grow across a long play session.
Character_Damage_Patch.RecentSkeletonHits.Remove(zdoid);
if (Character_Damage_Patch.RecentSkeletonHits.Count > 0)
{
var stale = new System.Collections.Generic.List<ZDOID>();
foreach (var kv in Character_Damage_Patch.RecentSkeletonHits)
{
if (Time.time - kv.Value > KillAttributionWindow) stale.Add(kv.Key);
}
foreach (var key in stale) Character_Damage_Patch.RecentSkeletonHits.Remove(key);
}
if (killedByPlayer)
{
int state = BossProgressionManager.GetCurrentProgressionState();
var rules = SkeletonProgression.GetRules(state);
@ -671,24 +723,85 @@ namespace RacesOfValheim
if (activeMinions.Count < rules.MaxSummons)
{
GameObject minionPrefab = PrefabManager.Cache.GetPrefab<GameObject>(rules.SummonPrefab);
if (minionPrefab != null)
if (minionPrefab == null)
{
Jotunn.Logger.LogWarning($"[Skeleton] SummonOnKill: no '{rules.SummonPrefab}' prefab in the cache; nothing raised from {__instance.m_name}.");
}
else
{
GameObject minion = UnityEngine.Object.Instantiate(minionPrefab, __instance.transform.position, Quaternion.identity);
Character minionChar = minion.GetComponent<Character>();
if (minionChar != null)
if (minionChar == null)
{
// Make it friendly
Jotunn.Logger.LogWarning($"[Skeleton] SummonOnKill: '{rules.SummonPrefab}' has no Character component; destroying the spawned instance.");
UnityEngine.Object.Destroy(minion);
}
else
{
// Confirmed against the live ZNetScene registry via
// 'listprefabs' - "vfx_skeleton_spawn" and "vfx_bloodmagic_aoe"
// (used below by Auto-Resurrect too) were both guesses that
// never actually existed. fx_summon_skeleton_spawn is the real
// vanilla effect for exactly this moment.
GameObject riseVfx = PrefabManager.Cache.GetPrefab<GameObject>("fx_summon_skeleton_spawn") ??
PrefabManager.Cache.GetPrefab<GameObject>("fx_summon_skeleton");
if (riseVfx != null)
{
UnityEngine.Object.Instantiate(riseVfx, minion.transform.position, Quaternion.identity);
}
else
{
Jotunn.Logger.LogWarning("[Skeleton] SummonOnKill: neither 'fx_summon_skeleton_spawn' nor 'fx_summon_skeleton' resolved to a prefab; no rise effect played.");
}
// The particles above are dressing; the actual "climbing out of
// the ground" motion is the creature's own Animator, played by
// setting this bool - the exact call vanilla's CreatureSpawner
// makes (see Spawner_Skeleton_rise) when m_wakeUpAnimation is
// set. Without it the model is simply active from frame one.
ZSyncAnimation zAnim = minion.GetComponent<ZSyncAnimation>();
if (zAnim != null)
{
zAnim.SetBool("wakeup", true);
}
else
{
Jotunn.Logger.LogWarning($"[Skeleton] SummonOnKill: '{rules.SummonPrefab}' has no ZSyncAnimation; cannot play the wakeup animation.");
}
// Make it friendly - same as RaisedThrall.Bind(), minus the
// station anchor, since this one wasn't raised at a pile.
minionChar.m_faction = Character.Faction.Players;
BaseAI ai = minion.GetComponent<BaseAI>();
if (ai != null)
if (ai == null)
{
Jotunn.Logger.LogWarning($"[Skeleton] SummonOnKill: '{rules.SummonPrefab}' has no BaseAI; it will stand where it spawned and never follow.");
}
else
{
MonsterAI monsterAI = minion.GetComponent<MonsterAI>();
if (monsterAI != null)
if (monsterAI == null)
{
Jotunn.Logger.LogWarning($"[Skeleton] SummonOnKill: '{rules.SummonPrefab}' has a BaseAI but no MonsterAI; cannot set a follow target.");
}
else
{
monsterAI.MakeTame();
monsterAI.SetFollowTarget(Player.m_localPlayer.gameObject);
}
}
RaisedThrall raised = minion.GetComponent<RaisedThrall>();
if (raised == null)
{
Jotunn.Logger.LogWarning($"[Skeleton] SummonOnKill: '{rules.SummonPrefab}' has no RaisedThrall; it will never wither on its own.");
}
else
{
raised.SetExpiry(SummonLifetimeSeconds);
}
activeMinions.Add(minionChar);
}
}