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

@ -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;