diff --git a/JotunnModStub/Draugh/DraughConfig.cs b/JotunnModStub/Draugh/DraughConfig.cs index 8f3c8fe..8aa0a88 100644 --- a/JotunnModStub/Draugh/DraughConfig.cs +++ b/JotunnModStub/Draugh/DraughConfig.cs @@ -33,6 +33,7 @@ namespace RacesOfValheim // ─── Undead Fortitude (tier 4+: crit on staggered, death aura) ────────── public static ConfigEntry StaggerCritMultiplier; public static ConfigEntry DeathAuraRadius; + public static ConfigEntry HumanMeatNourishmentMultiplier; // ─── North Wind (tier 5+: AoE frost on parry, on the same cooldown) ────── public static ConfigEntry NorthWindCooldown; @@ -79,6 +80,10 @@ namespace RacesOfValheim new ConfigDescription("Multiplies physical damage dealt to staggered enemies, tier 4+.", new AcceptableValueRange(1f, 3f))); DeathAuraRadius = config.Bind(fortitude, "Death Aura Radius", 100f, new ConfigDescription("Meters within which an ally's death drops Human Meat for you, tier 4+.", new AcceptableValueRange(10f, 300f))); + // A multiplier rather than absolute numbers: Human Meat is built from Blood Pudding's own + // nourishment at start-up, and those are the game's values, not ours to hardcode. + HumanMeatNourishmentMultiplier = config.Bind(fortitude, "Human Meat Nourishment Multiplier", 1f, + new ConfigDescription("Scales Human Meat's health, stamina and eitr against the Blood Pudding it is built from. Read once at start-up.", new AcceptableValueRange(0.1f, 3f))); const string northWind = "Draugh - North Wind"; NorthWindCooldown = config.Bind(northWind, "Cooldown", 20f, diff --git a/JotunnModStub/Draugh/DraughHumanMeat.cs b/JotunnModStub/Draugh/DraughHumanMeat.cs new file mode 100644 index 0000000..6ba3293 --- /dev/null +++ b/JotunnModStub/Draugh/DraughHumanMeat.cs @@ -0,0 +1,140 @@ +using Jotunn.Entities; +using Jotunn.Managers; +using UnityEngine; + +namespace RacesOfValheim +{ + /// + /// Human Meat, the Bonemass-tier reward: an ally who dies near a Draugh leaves a piece of + /// themselves behind, and only a Draugh can stomach it. + /// + /// THIS ITEM DID NOT EXIST. Two places in the mod already used it - the drop in + /// DraughProgressionPatches.Draugh_DeathAura_Patch and the "fatal to the living" block in + /// DraughFoodPatches - and both looked it up by the name "HumanMeat", which nothing registered. + /// So the drop never happened and the block never fired: a perk the README has promised since + /// 1.4 with no item behind it. The two consumers are unchanged; what was missing was the + /// producer. + /// + /// BUILT FROM TWO VANILLA ITEMS, one for the look and one for the numbers: + /// + /// RawMeat gives the clone its model and icon, because that is what a piece of somebody looks + /// like, and because the Draugh's whole food identity is raw flesh. + /// + /// BloodPudding gives the nourishment, copied field by field at start-up rather than written + /// down here. Blood Pudding is a real cooked food in the game's own progression, so its + /// numbers are balanced against the rest of it, and reading them means this item follows any + /// change the game makes to them. DraughConfig.HumanMeatNourishmentMultiplier scales them. + /// Its stamina is folded into health rather than copied across - see the note further down. + /// + /// RawMeat is a Material in vanilla - raw meat is not edible - so m_itemType is forced to + /// Consumable. That is the one assumption in here worth knowing about: the alternative, which + /// DraughRace.CreateModAssets uses for its EdibleUncooked_ items, is to clone the COOKED item and + /// dress it as the raw one, which gets consumability for free but keeps the cooked model. If the + /// game ever refuses to eat this, that is the fallback, and the log line below prints exactly + /// what was produced so it can be told apart from a missing prefab. + /// + internal static class DraughHumanMeat + { + /// The name the two consumers look it up by. Changing it breaks both. + public const string PrefabName = "HumanMeat"; + + private const string LookSource = "RawMeat"; + private const string NourishmentSource = "BloodPudding"; + + /// + /// Darkens the meat and pulls it towards blood, so a stack of Human Meat is not mistaken for + /// the deer meat it is built from. Multiplied into the material's own colour, so it darkens + /// whatever the texture already is rather than replacing it. + /// + private static readonly Color Tint = new Color(0.62f, 0.34f, 0.38f, 1f); + + /// + /// Called from DraughRace.CreateModAssets, which is to say while vanilla prefabs are + /// available and before anything can ask for this item. + /// + public static void Register() + { + ItemDrop look = FindItem(LookSource); + ItemDrop nourishment = FindItem(NourishmentSource); + + if (look == null || nourishment == null) + { + // Nothing is registered rather than a half-built item: the two consumers both check + // for null, so no meat is a quiet no-op, while a nameless inedible one is not. + Jotunn.Logger.LogWarning( + $"[Draugh] Human Meat not registered: '{LookSource}' " + + $"{(look == null ? "missing" : "ok")}, '{NourishmentSource}' " + + $"{(nourishment == null ? "missing" : "ok")}."); + return; + } + + CustomItem item = new CustomItem(PrefabName, LookSource); + ItemDrop.ItemData.SharedData shared = item.ItemDrop.m_itemData.m_shared; + ItemDrop.ItemData.SharedData source = nourishment.m_itemData.m_shared; + + shared.m_name = "Human Meat"; + shared.m_description = "A piece of somebody. The living gag on it; you do not."; + + // Raw meat is a Material in vanilla, so none of the food fields below would be read + // without this. + shared.m_itemType = ItemDrop.ItemData.ItemType.Consumable; + + // BLOOD PUDDING'S STAMINA GOES ONTO HEALTH, AND STAMINA IS LEFT AT ZERO. A Draugh does + // not use stamina, so nourishment spent there is nourishment thrown away - the food + // slot would look full while giving the race half of what it cost. Adding the two + // together keeps the item worth the same as the pudding it is balanced against, which + // is the point of reading the pudding at all. + float scale = DraughConfig.HumanMeatNourishmentMultiplier.Value; + shared.m_food = (source.m_food + source.m_foodStamina) * scale; + shared.m_foodStamina = 0f; + shared.m_foodEitr = source.m_foodEitr * scale; + shared.m_foodRegen = source.m_foodRegen; + shared.m_foodBurnTime = source.m_foodBurnTime; + shared.m_maxStackSize = source.m_maxStackSize; + shared.m_consumeStatusEffect = source.m_consumeStatusEffect; + + Recolour(item.ItemDrop.gameObject); + + ItemManager.Instance.AddItem(item); + + Jotunn.Logger.LogInfo( + $"[Draugh] Human Meat registered from '{LookSource}' + '{NourishmentSource}': " + + $"type={shared.m_itemType} food={shared.m_food:F0} stamina={shared.m_foodStamina:F0} " + + $"eitr={shared.m_foodEitr:F0} regen={shared.m_foodRegen:F0} " + + $"burn={shared.m_foodBurnTime:F0}s stack={shared.m_maxStackSize}."); + } + + private static ItemDrop FindItem(string prefabName) + { + GameObject prefab = PrefabManager.Cache.GetPrefab(prefabName); + return prefab != null ? prefab.GetComponent() : null; + } + + /// + /// Tints the clone's own materials, on copies. + /// + /// The clone's renderers still point at the vanilla RawMeat materials, which are shared with + /// every piece of raw meat in the world - writing a colour into one of those would tint the + /// lot. Each renderer gets its own copy instead, which this prefab then owns. + /// + private static void Recolour(GameObject root) + { + foreach (Renderer renderer in root.GetComponentsInChildren(true)) + { + Material[] materials = renderer.sharedMaterials; + if (materials == null) continue; + + for (int i = 0; i < materials.Length; i++) + { + if (materials[i] == null) continue; + + Material copy = new Material(materials[i]); + if (copy.HasProperty("_Color")) copy.color = copy.color * Tint; + materials[i] = copy; + } + + renderer.sharedMaterials = materials; + } + } + } +} diff --git a/JotunnModStub/Draugh/DraughRace.cs b/JotunnModStub/Draugh/DraughRace.cs index a9f130f..9362f5c 100644 --- a/JotunnModStub/Draugh/DraughRace.cs +++ b/JotunnModStub/Draugh/DraughRace.cs @@ -23,6 +23,10 @@ namespace RacesOfValheim // Draugr is ever set up as a bench. DraughSpawner.Register(); + // The Bonemass-tier drop. Registered here for the same reason as the pile: two places in + // the mod already look it up by name, and until now nothing created it. + DraughHumanMeat.Register(); + // Generate EdibleUncooked prefabs for Draugh raw food logic foreach (var mapping in DraughFoodPatches.rawToCookedMapping) { diff --git a/README.md b/README.md index 010b03d..d3141fa 100644 --- a/README.md +++ b/README.md @@ -147,7 +147,7 @@ Three races grow a pair of their own, refused by the holster key and never dragg - **Base:** Born Dead, Buried Alive. -20% Slash/Pierce/Blunt; +50% Fire/Spirit taken. Poison resistant. Eats only raw flesh, eyes, entrails, blood. Swamp undead ignore you. - **Eikthyr:** Immune to Wet, swim faster, regen when wet/swimming. - **Elder:** Toxic Trace – attacks poison over time. -- **Bonemass:** Flesh and the Power It Holds – humanoids drop Human Meat food. Corpse Run permanently active. +- **Bonemass:** Flesh and the Power It Holds – a player who dies inside your death aura leaves Human Meat behind, yourself included. Only a Draugh can eat it. Corpse Run permanently active. - **Moder:** Parrying unleashes freezing nova (20s CD). - **Yagluth:** Zombie Ritual – fatal damage = ghost state, immune to damage, Eitr drains, die if Eitr hits 0. Raw food gives Eitr. - **Queen:** Swarm of Terror – being hit summons 2 Seeker Broods to fight for you.