feat(aswid): devour feeds less health and some stamina

Devoured creatures feed 10% less health, and a share of it becomes
stamina: 60% for Meadows and Black Forest prey, 10% past them. Foods made
by the half-health formula are capped per biome, so a Troll no longer
feeds 150. The foods are rebuilt from their base values whenever a
setting changes or the server's values arrive.
This commit is contained in:
kanym 2026-10-26 13:57:41 +01:00
commit 83cd49c753
6 changed files with 132 additions and 8 deletions

View file

@ -70,6 +70,12 @@ namespace RacesOfValheim
// ─── Devour ────────────────────────────────────────────────────────────
public static ConfigEntry<float> DevourCooldown;
// What a devoured creature feeds - see AswidRace.ApplyFoodBalance.
public static ConfigEntry<float> DevourHealthMultiplier;
public static ConfigEntry<float> DevourStaminaShare;
public static ConfigEntry<float> EarlyStaminaShare;
public static ConfigEntry<float> FoodCapBase;
public static ConfigEntry<float> FoodCapPerBiome;
// ─── Domination (tier 6+ ability, native Interact key) ───────────────────
public static ConfigEntry<float> EnslaveCooldown;
@ -189,6 +195,23 @@ namespace RacesOfValheim
const string devour = "Aswid - Devour";
DevourCooldown = config.Bind(devour, "Consume Cooldown", 5f,
new ConfigDescription("How long one body stays drunk-dry, in seconds. A single death is reported to the devour more than once - by two damage patches, by the aura's execute, by a thrall's kill - and this is the window that keeps those from feeding you twice off the same corpse. It is per body, not per player: killing a whole pack at once devours every one of them. One second is used as the floor, so no corpse feeds you twice even at 0.", new AcceptableValueRange<float>(0f, 60f)));
DevourHealthMultiplier = config.Bind(devour, "Health Multiplier", 0.9f,
new ConfigDescription("Scales the health every devoured creature feeds you. 1 is the old amount.", new AcceptableValueRange<float>(0f, 2f)));
DevourStaminaShare = config.Bind(devour, "Stamina Share", 0.10f,
new ConfigDescription("Fraction of that health turned into stamina instead, for creatures past the Black Forest. 0.1 = 10%.", new AcceptableValueRange<float>(0f, 1f)));
EarlyStaminaShare = config.Bind(devour, "Early Creature Stamina Share", 0.60f,
new ConfigDescription("The same, for Meadows and Black Forest creatures. Above 0.5 they feed more stamina than health. Set it equal to the one above to treat every creature alike.", new AcceptableValueRange<float>(0f, 1f)));
FoodCapBase = config.Bind(devour, "Food Health Cap Base", 15f,
new ConfigDescription("Creatures with no hand-set meal feed half their health. That is capped at this plus the per-biome value times the biome's number (Meadows 1 ... Deep North 8). With the defaults: Black Forest 45, Mountains 75, Plains 90.", new AcceptableValueRange<float>(0f, 150f)));
FoodCapPerBiome = config.Bind(devour, "Food Health Cap Per Biome", 15f,
new ConfigDescription("See the base cap above.", new AcceptableValueRange<float>(0f, 50f)));
// Jotunn's server sync assigns Value, which fires SettingChanged, so the server's
// numbers reach the foods the same way a local drag does.
foreach (var entry in new[] { DevourHealthMultiplier, DevourStaminaShare, EarlyStaminaShare, FoodCapBase, FoodCapPerBiome })
{
entry.SettingChanged += (_, __) => AswidRace.ApplyAllFoodBalance();
}
const string domination = "Aswid - Domination";
EnslaveCooldown = config.Bind(domination, "Enslave Cooldown", 900f,

View file

@ -191,6 +191,11 @@ namespace RacesOfValheim
if (c != null)
{
float foodHp = Mathf.Min(c.m_health / 2f, 150f);
// The formula alone only knows how big a creature is, not where it
// lives - a Black Forest troll came out at 150. Only these get the
// per-biome cap in ApplyFoodBalance; the hand-set values below are
// choices, not formula output, and keep theirs.
bool fromFormula = true;
// Capped at 50 minutes: a tough creature like the Barka would otherwise
// feed for over an hour.
float burnTime = Mathf.Min(c.m_health * 2f, 3000f);
@ -201,24 +206,38 @@ namespace RacesOfValheim
{
burnTime = 1200f; // 20 minutes
}
else if (mobName == "JotunWitch") { foodHp = 120f; burnTime = 3600f; } // 60 minutes
else if (mobName == "ElakingMole") { foodHp = 100f; burnTime = 1800f; } // 30 minutes
else if (mobName.StartsWith("Dverger") && mobName != "DvergerDeepNorth") { foodHp = 90f; burnTime = 1500f; } // 25 minutes
else if (mobName == "DvergerDeepNorth") { foodHp = 100f; burnTime = 1800f; } // 30 minutes
else if (mobName == "Greyling") { foodHp = 20f; burnTime = 1200f; }
else if (mobName == "Greydwarf") { foodHp = 25f; burnTime = 1200f; }
else if (mobName == "Greydwarf_Shaman") { foodHp = 30f; burnTime = 1200f; }
else if (mobName == "Greydwarf_Elite") { foodHp = 60f; burnTime = 1800f; }
else if (mobName == "JotunWitch") { foodHp = 120f; burnTime = 3600f; fromFormula = false; } // 60 minutes
else if (mobName == "ElakingMole") { foodHp = 100f; burnTime = 1800f; fromFormula = false; } // 30 minutes
else if (mobName.StartsWith("Dverger") && mobName != "DvergerDeepNorth") { foodHp = 90f; burnTime = 1500f; fromFormula = false; } // 25 minutes
else if (mobName == "DvergerDeepNorth") { foodHp = 100f; burnTime = 1800f; fromFormula = false; } // 30 minutes
else if (mobName == "Greyling") { foodHp = 20f; burnTime = 1200f; fromFormula = false; }
else if (mobName == "Greydwarf") { foodHp = 25f; burnTime = 1200f; fromFormula = false; }
else if (mobName == "Greydwarf_Shaman") { foodHp = 30f; burnTime = 1200f; fromFormula = false; }
else if (mobName == "Greydwarf_Elite") { foodHp = 60f; burnTime = 1800f; fromFormula = false; }
customItem.ItemDrop.m_itemData.m_shared.m_food = foodHp;
customItem.ItemDrop.m_itemData.m_shared.m_foodStamina = 0f;
customItem.ItemDrop.m_itemData.m_shared.m_foodEitr = 0f;
customItem.ItemDrop.m_itemData.m_shared.m_foodBurnTime = burnTime;
customItem.ItemDrop.m_itemData.m_shared.m_foodRegen = Mathf.Max(1f, foodHp / 15f);
if (fromFormula) formulaFoods.Add(foodName);
}
}
}
// What the item gives before any balance setting, kept so ApplyFoodBalance can be
// rerun from scratch whenever a setting changes or the server's values arrive.
var shared = customItem.ItemDrop.m_itemData.m_shared;
baseFoods[foodName] = new BaseFood
{
Mob = mobName,
Health = shared.m_food,
Stamina = shared.m_foodStamina,
Regen = shared.m_foodRegen,
Shared = shared
};
ApplyFoodBalance(foodName);
GameObject trophyPrefab = Jotunn.Managers.PrefabManager.Cache.GetPrefab<GameObject>(trophyName);
if (trophyPrefab != null)
{
@ -234,6 +253,81 @@ namespace RacesOfValheim
}
}
private class BaseFood
{
public string Mob;
public float Health;
public float Stamina;
public float Regen;
public ItemDrop.ItemData.SharedData Shared;
}
private static readonly Dictionary<string, BaseFood> baseFoods = new Dictionary<string, BaseFood>();
private static readonly HashSet<string> formulaFoods = new HashSet<string>();
/// <summary>
/// The biome each edible creature lives in, as a number from 1 (Meadows) to 8 (Deep North).
/// It decides two things: the cap on formula-made foods, and which creatures count as early
/// game (1 and 2) for the larger stamina share. A creature missing here counts as tier 8,
/// which means uncapped in practice and never early.
/// </summary>
private static readonly Dictionary<string, int> mobBiomeTier = new Dictionary<string, int>
{
{ "Boar", 1 }, { "Neck", 1 }, { "Deer", 1 }, { "Greyling", 1 },
{ "Greydwarf", 2 }, { "Greydwarf_Elite", 2 }, { "Greydwarf_Shaman", 2 }, { "Troll", 2 },
{ "Leech", 3 },
{ "Wolf", 4 }, { "Fenring", 4 }, { "Fenring_Cultist", 4 }, { "Ulv", 4 }, { "Hatchling", 4 },
{ "Lox", 5 }, { "Goblin", 5 }, { "GoblinArcher", 5 }, { "GoblinShaman", 5 }, { "GoblinBrute", 5 }, { "Deathsquito", 5 },
{ "Hare", 6 }, { "Seeker", 6 }, { "SeekerBrood", 6 }, { "SeekerBrute", 6 }, { "Gjall", 6 }, { "Tick", 6 },
{ "Dverger", 6 }, { "DvergerMage", 6 }, { "DvergerMageFire", 6 }, { "DvergerMageIce", 6 }, { "DvergerMageSupport", 6 },
{ "Asksvin", 7 }, { "Volture", 7 }, { "DvergerAshlands", 7 },
};
public const int EarlyBiomeTier = 2;
private static int GetBiomeTier(string mob) => mobBiomeTier.TryGetValue(mob, out int tier) ? tier : 8;
/// <summary>
/// Rewrites one devour food from its unbalanced base and the current settings. The Discord
/// reports said even weak kills fed too much health; Dissolution asked for about 10% less,
/// and for early creatures to feed stamina more than health. So: health is scaled first,
/// then a share of it moves over to stamina. Vanilla meals the food was cloned from keep
/// the stamina they already had, the share goes on top.
///
/// Writing the shared data is enough to reach every copy: eaten foods, the extra slot and
/// the tooltip all read the same SharedData through their ItemData.
/// </summary>
private static void ApplyFoodBalance(string foodName)
{
if (!baseFoods.TryGetValue(foodName, out BaseFood food) || food.Shared == null) return;
int tier = GetBiomeTier(food.Mob);
float health = food.Health;
if (formulaFoods.Contains(foodName))
{
health = Mathf.Min(health, AswidConfig.FoodCapBase.Value + AswidConfig.FoodCapPerBiome.Value * tier);
}
float healthMultiplier = AswidConfig.DevourHealthMultiplier.Value;
health *= healthMultiplier;
float share = tier <= EarlyBiomeTier ? AswidConfig.EarlyStaminaShare.Value : AswidConfig.DevourStaminaShare.Value;
float moved = health * share;
food.Shared.m_food = health - moved;
food.Shared.m_foodStamina = food.Stamina + moved;
// Regen follows the health the food ends up giving, cap included, so a troll capped
// to 40 health does not keep the 10 per tick its old 150 earned.
float healthRatio = food.Health > 0f ? food.Shared.m_food / food.Health : 0f;
food.Shared.m_foodRegen = Mathf.Max(1f, food.Regen * healthRatio);
}
/// <summary>Hooked to the balance settings, which also fire when the server's values arrive.</summary>
public static void ApplyAllFoodBalance()
{
foreach (string foodName in baseFoods.Keys) ApplyFoodBalance(foodName);
}
private float m_tintCheckTimer = 0f;
private float sensesCheckTimer = 0f;