Files
h-school/src/HSchool.Simulation/PersonInsulation.cs
T
Leonid PershinandCursor 53c4ae0f92 Sum warmth insulation from worn items and refresh goldens for the new trait pool.
HeatLoving and ColdLoving shift later trait rolls; worn clothes now feed PersonInsulation instead of reflection.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-20 04:00:53 +03:00

49 lines
1.4 KiB
C#

using HSchool.Content;
using HSchool.People;
namespace HSchool.Simulation;
/// <summary>
/// Worn insulation in °C-equivalent points, summed from apparel currently on the body.
/// Tests that need a bare frost set <see cref="Naked"/> on the entity explicitly.
/// </summary>
public readonly record struct PersonInsulation(float Value)
{
public static PersonInsulation Naked { get; } = new(0f);
public static PersonInsulation FromWorn(DefCatalog catalog, params string[] defNames)
{
ArgumentNullException.ThrowIfNull(catalog);
var sum = 0f;
foreach (var name in defNames)
{
if (catalog.Things.TryGetValue(name, out var thing) && thing.Layers.Count > 0)
{
sum += thing.Insulation;
}
}
return new PersonInsulation(sum);
}
public static PersonInsulation FromPerson(Person person, DefCatalog? catalog)
{
ArgumentNullException.ThrowIfNull(person);
if (catalog is null)
{
return Naked;
}
var worn = new List<string>();
foreach (var item in person.Items)
{
if (item.Location.Equals(ItemLocations.Worn, StringComparison.Ordinal))
{
worn.Add(item.Def);
}
}
return worn.Count == 0 ? Naked : FromWorn(catalog, [.. worn]);
}
}