diff --git a/JotunnModStub/RaceCompendium.cs b/JotunnModStub/RaceCompendium.cs index 4030117..92707d6 100644 --- a/JotunnModStub/RaceCompendium.cs +++ b/JotunnModStub/RaceCompendium.cs @@ -299,9 +299,77 @@ namespace RacesOfValheim knownTexts["Skadi Secrets"] = sb.ToString(); } + /// + /// This was a one-line placeholder that returned the same sentence at every tier, which is + /// why players reported that "Skeleton Secrets never populates after bosses" - it was never + /// written, rather than broken. It now unfolds tier by tier with the real numbers, the way + /// the Skadi entry above does. + /// private static void GenerateSkeletonText(Dictionary knownTexts, int state) { - knownTexts["Skeleton Secrets"] = "The secrets of the crypt will be revealed soon..."; + var rules = SkeletonProgression.GetRules(state); + float health = SkeletonProgression.GetMaxHealthBonus(state); + int lifesteal = Mathf.RoundToInt(rules.LifestealPercent * 100f); + + StringBuilder sb = new StringBuilder(); + sb.AppendLine("The Secrets of the Crypt\n"); + + // Says out loud which tier the race thinks it is on. A player who has killed a boss and + // seen nothing change can read this line back and know immediately whether the tier + // failed to advance or the unlock itself is broken. + sb.AppendLine(state <= BossProgressionManager.MinState + ? "You stand at the first of eight standings; no boss has yet fallen to your reckoning.\n" + : $"You stand at the {state} of eight standings, earned by the fall of {BossProgressionManager.GetBossNameForState(state)}.\n"); + + sb.AppendLine("[Base Passive] Undead Diet:"); + sb.AppendLine($"No hunger moves you and no meal can help you - mortal food is nothing to dry bones. In its place the dead grow strong as their betters fall: you carry +{health:0} Maximum Health at your present standing. Nor does effort tire you; you have no stamina to spend at all.\n"); + + sb.AppendLine("[Base Passive] Bones and Blades:"); + sb.AppendLine("Blades and points find little to cut in you and do half their work, but a hammer's weight finds everything, and hurts you the more for it.\n"); + + if (state >= 2) + { + sb.AppendLine("[Eikthyr Unlock] The Green Rot:"); + sb.AppendLine($"Poison has nothing left to poison - it cannot touch you at all - and your bones take on its sickly cast. Every blow you land returns {lifesteal}% of what it deals in physical harm to your own frame.\n"); + } + + if (state >= 3) + { + sb.AppendLine("[The Elder Unlock] The First Blow:"); + sb.AppendLine("The first strike out of the dark staggers whatever it lands upon. The dead may do this once every 5 seconds.\n"); + } + + if (state >= 4) + { + sb.AppendLine("[Bonemass Unlock] Rotten Touch:"); + sb.AppendLine("What you strike, you sicken - every blow carries 20 Poison damage of its own.\n"); + } + + if (state >= 5) + { + sb.AppendLine("[Moder Unlock] Charred Bones:"); + sb.AppendLine("Your frame blackens and burns, and the fire clings to you: everything near enough to feel it is scorched. Your wounds also close faster than bone has any right to.\n"); + } + + if (state >= 6) + { + sb.AppendLine("[Yagluth Unlock] Risen Again:"); + sb.AppendLine("A killing blow no longer ends you. You are made whole where you stand - and then the dark magic must gather itself for 5 minutes before it will do so again.\n"); + } + + if (state >= 7) + { + sb.AppendLine("[The Queen Unlock] The Crypt Answers:"); + sb.AppendLine($"Every enemy you put down rises to fight for you, up to {rules.MaxSummons} at your side at once.\n"); + } + + if (state >= 8) + { + sb.AppendLine("[Fader Unlock] A Host of Your Own:"); + sb.AppendLine($"{rules.MaxSummons} of the dead now follow you, and {lifesteal}% of the harm you deal comes back as your own strength.\n"); + } + + knownTexts["Skeleton Secrets"] = sb.ToString(); } private static void GenerateFurlingText(Dictionary knownTexts, int state, Player player) diff --git a/JotunnModStub/Skeleton/SkeletonPatches.cs b/JotunnModStub/Skeleton/SkeletonPatches.cs index 6f8c364..92a9c87 100644 --- a/JotunnModStub/Skeleton/SkeletonPatches.cs +++ b/JotunnModStub/Skeleton/SkeletonPatches.cs @@ -10,6 +10,35 @@ namespace RacesOfValheim private static Mesh skeletonMesh = null; private static Material[] skeletonMaterials = null; + /// + /// Makes the Skeleton's max health exactly what its progression promises. + /// + /// A Skeleton cannot eat, so SkeletonRace fakes three permanent foods whose values are + /// scaled to add up to the tier's bonus. That is a good way to keep food-based health + /// regeneration working - Valheim regenerates from the food list, so a Skeleton with no + /// food would never heal - but a bad way to land an exact number: the value the game reads + /// is Food.m_health, which UpdateFood recomputes every second as + /// Pow(remaining/burnTime, 0.3) * m_food, and anything that leaves those three foods + /// partly burnt, partly rebuilt or one short quietly costs health. A Bonemass-tier + /// Skeleton reported 95 max health where the table promises 25 + 140. + /// + /// So the foods stay, for regeneration, and the total they feed into is overwritten here. + /// GetTotalFoodValue has exactly one caller, Player.UpdateFood, which passes the result + /// straight to SetMaxHealth - so this is the single point where the number is decided, and + /// it now comes from the progression table rather than from three scaled sausages. + /// + [HarmonyPatch(typeof(Player), "GetTotalFoodValue")] + public static class Player_GetTotalFoodValue_SkeletonHealth_Patch + { + public static void Postfix(Player __instance, ref float hp) + { + if (__instance != Player.m_localPlayer || !SkeletonRace.IsSkeleton()) return; + + int state = BossProgressionManager.GetCurrentProgressionState(); + hp = __instance.m_baseHP + SkeletonProgression.GetMaxHealthBonus(state); + } + } + [HarmonyPatch(typeof(Player), "UseStamina")] public static class Player_UseStamina_Patch { diff --git a/JotunnModStub/Skeleton/SkeletonProgression.cs b/JotunnModStub/Skeleton/SkeletonProgression.cs index 082b18e..66d297b 100644 --- a/JotunnModStub/Skeleton/SkeletonProgression.cs +++ b/JotunnModStub/Skeleton/SkeletonProgression.cs @@ -34,6 +34,29 @@ namespace RacesOfValheim public UnityEngine.Vector3 ScaleMultiplier; } + public const string BaseModel = "Skeleton"; + public const string PoisonModel = "Skeleton_Poison"; + + // The published progression calls for a fire skeleton from Moder on, and the charred + // twitcher is the only burnt skeleton the game ships. It used to arrive at Fader; if that + // is preferred, move the model and its scale back to the state >= 8 block - nothing else + // in this file depends on where they sit. + public const string FireModel = "Charred_Twitcher"; + + // The charred rig is broader and shorter than a plain skeleton, so it needs squeezing to + // read as a player. Tied to the model, not to a tier. + public static readonly UnityEngine.Vector3 FireModelScale = new UnityEngine.Vector3(0.85f, 1.20f, 0.85f); + + public const string SummonPrefabName = "Skeleton_friendly"; + + /// + /// Every tier, exactly as the race's published progression describes it. The table had + /// drifted a long way from that description - poison immunity arrived two tiers late, + /// auto-stun four tiers late, and lifesteal jumped 20/30/40 instead of climbing in fives - + /// which is what players were reporting as "progression doesn't work". + /// + /// The blocks are cumulative: each one only states what its boss adds or replaces. + /// public static SkeletonRules GetRules(int state) { SkeletonRules rules = new SkeletonRules @@ -48,48 +71,50 @@ namespace RacesOfValheim SummonPrefab = "", AutoStunFirstHit = false, FireAura = false, - ModelPrefab = "Skeleton", + ModelPrefab = BaseModel, ScaleMultiplier = UnityEngine.Vector3.one }; - if (state >= 2) - { - rules.ModelPrefab = "Skeleton_Poison"; - rules.LifestealPercent = 0.20f; - } - if (state >= 3) - { - rules.EnhancedRegen = true; - } - if (state >= 4) + if (state >= 2) // Eikthyr { + rules.ModelPrefab = PoisonModel; rules.PoisonImmunity = true; + rules.LifestealPercent = 0.05f; + } + if (state >= 3) // The Elder + { + rules.LifestealPercent = 0.10f; + rules.AutoStunFirstHit = true; + } + if (state >= 4) // Bonemass + { + rules.LifestealPercent = 0.15f; rules.PoisonAttacks = true; } - if (state >= 5) + if (state >= 5) // Moder { + rules.LifestealPercent = 0.20f; + rules.ModelPrefab = FireModel; + rules.ScaleMultiplier = FireModelScale; + rules.FireAura = true; + rules.EnhancedRegen = true; + } + if (state >= 6) // Yagluth + { + rules.LifestealPercent = 0.25f; rules.AutoResurrect = true; } - if (state >= 6) + if (state >= 7) // The Queen { - rules.ModelPrefab = "Skeleton_Poison"; rules.LifestealPercent = 0.30f; rules.SummonOnKill = true; - rules.MaxSummons = 2; - rules.SummonPrefab = "Skeleton_friendly"; - rules.ScaleMultiplier = UnityEngine.Vector3.one * 1.1f; + rules.MaxSummons = 3; + rules.SummonPrefab = SummonPrefabName; } - if (state >= 7) + if (state >= 8) // Fader { - rules.AutoStunFirstHit = true; - rules.LifestealPercent = 0.40f; - } - if (state >= 8) - { - rules.ModelPrefab = "Charred_Twitcher"; - rules.SummonPrefab = "Charred_Twitcher"; - rules.FireAura = true; - rules.ScaleMultiplier = new UnityEngine.Vector3(0.85f, 1.20f, 0.85f); + rules.LifestealPercent = 0.35f; + rules.MaxSummons = 5; } return rules; diff --git a/JotunnModStub/Skeleton/SkeletonStatusEffects.cs b/JotunnModStub/Skeleton/SkeletonStatusEffects.cs index f3aea9a..398cd7b 100644 --- a/JotunnModStub/Skeleton/SkeletonStatusEffects.cs +++ b/JotunnModStub/Skeleton/SkeletonStatusEffects.cs @@ -5,29 +5,47 @@ namespace RacesOfValheim { public class SE_SkeletonStats : SE_Stats { + // The tier the current m_mods were built for. -1 means "never built". + private int m_appliedState = -1; + public override void Setup(Character character) { base.Setup(character); - - // Apply Damage Modifiers - int state = BossProgressionManager.GetCurrentProgressionState(); - SkeletonProgression.SkeletonRules rules = SkeletonProgression.GetRules(state); - - m_mods = new List(); - m_mods.Add(new HitData.DamageModPair { m_type = HitData.DamageType.Pierce, m_modifier = HitData.DamageModifier.Resistant }); - m_mods.Add(new HitData.DamageModPair { m_type = HitData.DamageType.Slash, m_modifier = HitData.DamageModifier.Resistant }); - m_mods.Add(new HitData.DamageModPair { m_type = HitData.DamageType.Blunt, m_modifier = HitData.DamageModifier.Weak }); - - if (rules.PoisonImmunity) - { - m_mods.Add(new HitData.DamageModPair { m_type = HitData.DamageType.Poison, m_modifier = HitData.DamageModifier.Immune }); - } + RebuildDamageMods(); } public override void UpdateStatusEffect(float dt) { base.UpdateStatusEffect(dt); - // Health is handled in SkeletonPatches.Player_GetMaxHealth_Patch + + // Setup runs once, when the effect is first applied - so the damage modifiers were + // frozen at whatever tier the player happened to be on then, usually tier 1 because the + // effect goes on at spawn before a boss is ever killed. Poison immunity therefore never + // arrived: killing the boss changed the rules, and nothing ever asked them again. + // Everything else the race does re-reads GetRules per hit, which is why only the + // modifiers looked broken. Re-check here instead; the state comparison makes it free. + RebuildDamageMods(); + } + + private void RebuildDamageMods() + { + int state = BossProgressionManager.GetCurrentProgressionState(); + if (state == m_appliedState) return; + m_appliedState = state; + + SkeletonProgression.SkeletonRules rules = SkeletonProgression.GetRules(state); + + m_mods = new List + { + new HitData.DamageModPair { m_type = HitData.DamageType.Pierce, m_modifier = HitData.DamageModifier.Resistant }, + new HitData.DamageModPair { m_type = HitData.DamageType.Slash, m_modifier = HitData.DamageModifier.Resistant }, + new HitData.DamageModPair { m_type = HitData.DamageType.Blunt, m_modifier = HitData.DamageModifier.Weak } + }; + + if (rules.PoisonImmunity) + { + m_mods.Add(new HitData.DamageModPair { m_type = HitData.DamageType.Poison, m_modifier = HitData.DamageModifier.Immune }); + } } }