The mod's own items, build pieces and summoned creatures now carry $rov_item_, $rov_piece_ and $rov_creature_ tokens for their names and descriptions, and items.json holds the texts in English and Italian. Valheim localizes these fields wherever it shows them: tooltips, hover texts, messages, the build menu. Where a name doubles as an identifier, both sides use the same constant, so the comparisons still hold. The Aswid foods keep their prefix as a constant for the refinery's check and now name the creature with its vanilla token, so "Boar" translates too. The Furling crops get one whole description per crop instead of an English sentence with the metal dropped in. The Race Menu Ward's panel title is a mod UI Text, so it reads the translation directly. Saves are unaffected: items and eaten foods are stored by prefab name. The Sverm hive's goods stay for the merchant step. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
140 lines
7 KiB
C#
140 lines
7 KiB
C#
using Jotunn.Entities;
|
|
using Jotunn.Managers;
|
|
using UnityEngine;
|
|
|
|
namespace RacesOfValheim
|
|
{
|
|
/// <summary>
|
|
/// 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.
|
|
/// </summary>
|
|
internal static class DraughHumanMeat
|
|
{
|
|
/// <summary>The name the two consumers look it up by. Changing it breaks both.</summary>
|
|
public const string PrefabName = "HumanMeat";
|
|
|
|
private const string LookSource = "RawMeat";
|
|
private const string NourishmentSource = "BloodPudding";
|
|
|
|
/// <summary>
|
|
/// 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.
|
|
/// </summary>
|
|
private static readonly Color Tint = new Color(0.62f, 0.34f, 0.38f, 1f);
|
|
|
|
/// <summary>
|
|
/// Called from DraughRace.CreateModAssets, which is to say while vanilla prefabs are
|
|
/// available and before anything can ask for this item.
|
|
/// </summary>
|
|
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 = "$rov_item_draugh_humanmeat_name";
|
|
shared.m_description = "$rov_item_draugh_humanmeat_desc";
|
|
|
|
// 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<GameObject>(prefabName);
|
|
return prefab != null ? prefab.GetComponent<ItemDrop>() : null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 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.
|
|
/// </summary>
|
|
private static void Recolour(GameObject root)
|
|
{
|
|
foreach (Renderer renderer in root.GetComponentsInChildren<Renderer>(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;
|
|
}
|
|
}
|
|
}
|
|
}
|