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:
parent
e042579e17
commit
8c24ae3340
5 changed files with 232 additions and 12 deletions
|
|
@ -75,6 +75,7 @@ namespace RacesOfValheim
|
|||
CommandManager.Instance.AddConsoleCommand(new DumpElderCommand());
|
||||
CommandManager.Instance.AddConsoleCommand(new FenrirPackSpawnCommand());
|
||||
CommandManager.Instance.AddConsoleCommand(new DumpPotionsCommand());
|
||||
CommandManager.Instance.AddConsoleCommand(new ListPrefabsCommand());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -1302,4 +1303,51 @@ namespace RacesOfValheim
|
|||
Console.instance.Print($"[DEBUG] Progression state reset to natural world state: {state}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ground truth for "does this prefab actually exist", the same problem that made
|
||||
/// SummonOnKill's rise VFX ("vfx_skeleton_spawn", "vfx_bloodmagic_aoe") a guess instead of a
|
||||
/// fact. ZNetScene.GetPrefabNames() is the live registry the running game actually built, so
|
||||
/// this beats grepping asset bundles offline - those are compressed and unsearchable as plain
|
||||
/// text, which is exactly why that VFX name had to be confirmed in-game instead.
|
||||
/// </summary>
|
||||
public class ListPrefabsCommand : ConsoleCommand
|
||||
{
|
||||
public override string Name => "listprefabs";
|
||||
public override string Help => "[DEBUG] Logs every ZNetScene prefab name containing the given substring (case-insensitive)";
|
||||
|
||||
public override void Run(string[] args)
|
||||
{
|
||||
if (args.Length == 0)
|
||||
{
|
||||
Console.instance.Print("Usage: listprefabs <substring>");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ZNetScene.instance == null)
|
||||
{
|
||||
Console.instance.Print("ZNetScene is not ready yet.");
|
||||
return;
|
||||
}
|
||||
|
||||
string filter = args[0];
|
||||
System.Collections.Generic.List<string> matches = new System.Collections.Generic.List<string>();
|
||||
foreach (string prefabName in ZNetScene.instance.GetPrefabNames())
|
||||
{
|
||||
if (prefabName.IndexOf(filter, System.StringComparison.OrdinalIgnoreCase) >= 0)
|
||||
{
|
||||
matches.Add(prefabName);
|
||||
}
|
||||
}
|
||||
matches.Sort();
|
||||
|
||||
Console.instance.Print($"[DEBUG] {matches.Count} prefab(s) containing '{filter}':");
|
||||
Jotunn.Logger.LogInfo($"[DEBUG] listprefabs '{filter}': {matches.Count} match(es)");
|
||||
foreach (string name in matches)
|
||||
{
|
||||
Console.instance.Print(" " + name);
|
||||
Jotunn.Logger.LogInfo(" " + name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,12 @@ namespace RacesOfValheim
|
|||
public const string KeyAnchor = "RoV_draughAnchor";
|
||||
public const string KeyOrphanAt = "RoV_draughOrphanAt";
|
||||
|
||||
// A hard, station-independent lifespan - unlike the wither above, which only starts once
|
||||
// an anchor's station is gone. Nothing sets this by default; a thrall raised at a real
|
||||
// pile never expires on its own. SummonOnKill uses it because its skeletons are never
|
||||
// bound to a pile in the first place, so the anchor/wither pair has nothing to key off.
|
||||
public const string KeyExpiresAt = "RoV_thrallExpiresAt";
|
||||
|
||||
// ─── Set on the prefab at registration ───────────────────────────────
|
||||
|
||||
/// <summary>Groups thralls for follower caps and for a station's per-kind roster.</summary>
|
||||
|
|
@ -151,6 +157,10 @@ namespace RacesOfValheim
|
|||
if (m_nview == null || !m_nview.IsValid() || !m_nview.IsOwner()) return;
|
||||
if (m_character == null || m_character.IsDead()) return;
|
||||
|
||||
// A hard cap, checked before anything anchor-based - it has to fire regardless of
|
||||
// where this thrall is standing or whether it is following, unlike the wither below.
|
||||
if (TickExpiry()) return;
|
||||
|
||||
// Checked before anything else, and NOT skipped while following: a thrall out with its
|
||||
// master still has to wither if the station behind it has fallen.
|
||||
if (TickWither()) return;
|
||||
|
|
@ -161,6 +171,25 @@ namespace RacesOfValheim
|
|||
GoHome();
|
||||
}
|
||||
|
||||
/// <summary>Sets a hard lifespan from now, independent of any station anchor. Overwrites
|
||||
/// any expiry already set.</summary>
|
||||
public void SetExpiry(float seconds)
|
||||
{
|
||||
if (m_nview == null || !m_nview.IsValid() || ZNet.instance == null) return;
|
||||
m_nview.GetZDO().Set(KeyExpiresAt, (ZNet.instance.GetTime() + TimeSpan.FromSeconds(seconds)).Ticks);
|
||||
}
|
||||
|
||||
/// <summary>True once it has killed this one for running out the clock set by SetExpiry.
|
||||
/// A no-op for any thrall that never had one set (the ZDO key stays at its default 0).</summary>
|
||||
private bool TickExpiry()
|
||||
{
|
||||
long expiresAt = m_nview.GetZDO().GetLong(KeyExpiresAt, 0L);
|
||||
if (expiresAt == 0L || ZNet.instance.GetTime() < new DateTime(expiresAt)) return false;
|
||||
|
||||
Kill();
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>Starts the clock when the station is gone, and stops the thrall when it runs out.
|
||||
/// Returns true once it has killed this one, so the caller stops bothering with it.</summary>
|
||||
private bool TickWither()
|
||||
|
|
|
|||
|
|
@ -252,6 +252,31 @@ namespace RacesOfValheim
|
|||
if (drops != null) Object.DestroyImmediate(drops);
|
||||
}
|
||||
|
||||
// Vanilla skeletons carry no Tameable at all. Without one, Character.RaiseSkill logs
|
||||
// "is tamed but missing tameable or monster AI script!" every time this thrall lands a
|
||||
// hit - harmless (it only gates the vanilla creature-leveling system, which none of
|
||||
// this mod's thralls use), but it was never actually silenced until it showed up in
|
||||
// testing. Same fix Fenrir already uses for the Ulv and the Fenring: copy a real one
|
||||
// in from the vanilla Wolf.
|
||||
if (prefab.GetComponent<Tameable>() == null)
|
||||
{
|
||||
GameObject wolf = PrefabManager.Cache.GetPrefab<GameObject>("Wolf");
|
||||
Tameable sourceTame = wolf != null ? wolf.GetComponent<Tameable>() : null;
|
||||
if (sourceTame != null)
|
||||
{
|
||||
Tameable copy = prefab.AddComponent<Tameable>();
|
||||
foreach (System.Reflection.FieldInfo field in typeof(Tameable).GetFields(
|
||||
System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance))
|
||||
{
|
||||
field.SetValue(copy, field.GetValue(sourceTame));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Jotunn.Logger.LogWarning($"[Skeleton] {prefabName}: could not borrow a Tameable from the vanilla Wolf.");
|
||||
}
|
||||
}
|
||||
|
||||
RaisedThrall thrall = prefab.AddComponent<RaisedThrall>();
|
||||
thrall.m_kind = kind;
|
||||
thrall.m_commandingRace = RaceId;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,7 +47,12 @@ namespace RacesOfValheim
|
|||
// shorter and wore a 0.85/1.20/0.85 squeeze to compensate. Tied to the model, not a tier.
|
||||
public static readonly UnityEngine.Vector3 FireModelScale = UnityEngine.Vector3.one;
|
||||
|
||||
public const string SummonPrefabName = "Skeleton_friendly";
|
||||
// Reuses the Bound Bone Pile's own melee thrall (SkeletonBonePile.ThrallMeleeName) rather
|
||||
// than a standalone prefab, so a Queen/Fader kill raises the same tamed, loot-stripped,
|
||||
// forced-melee skeleton the pile does - not a separate, unproven asset. "Skeleton_friendly"
|
||||
// was tried first and never resolved to a real prefab; see the mod's own log for the
|
||||
// "no prefab in the cache" warning that caught it.
|
||||
public const string SummonPrefabName = SkeletonBonePile.ThrallMeleeName;
|
||||
|
||||
// Fader's dead stand taller than everyone else's. Applied to the player's root transform,
|
||||
// which is how this race has always sized itself - so it carries the collider, the camera
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue