Cut 0: collapse the three disagreeing stat evaluate bodies into one

ItemManager.Evaluate (unequipped), ConsumableItemEffect.Evaluate and
EquippedItem.Evaluate each hand-computed the same quality/durability/heat/
modifier arithmetic with small, undocumented disagreements (docs/stats-and-
power-cut.md Sec 0.2). Collapse the arithmetic into one function,
PerformanceStat.Evaluate(IStatContext), fed by three IStatContext
implementations: EquippedItem (the only one with heat, live durability and
modifiers), ConsumableItemEffect (progress substitutes for heat,
unconditionally, matching its prior behaviour exactly) and a new
UnequippedStatContext in ItemManager (no heat, no modifiers, by name).

No behaviour change beyond the two disagreements the cut map names as
defects. Each context's original NaN handling is preserved exactly
(unequipped throws with diagnostic detail; equipped/consumable fall back to
Min). Behavior.Evaluate(PerformanceStat) keeps its name and signature, so
the ~81 existing call sites are untouched.

Verified: dotnet test tests/Aetheria.Shared.Tests unchanged at 61/61 before
new tests are added; a real-catalog probe over GameData/Aetheria.cc found
the new unequipped path reproduces the old formula exactly across 3123
(item, quality, durability, stat) cases; Unity batchmode compiles with 0
error CS and the Cut 1/2/3 shield probes still pass; AetherDb census,
factions, dangling, station-fit, loadout 1 and hardpoint-fit are
byte-identical before and after.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-09-18 16:19:22 +02:00
commit e9b688de51
3 changed files with 84 additions and 29 deletions

View file

@ -572,6 +572,19 @@ public class HardpointData
private static Dictionary<HardpointType, float3> _tintColors;
}
// What a PerformanceStat reads to resolve one number: the lot it prices quality against, and the three
// per-context factors that used to be three separate Evaluate bodies. EquippedItem, ConsumableItemEffect and the
// unequipped case (ItemManager's own private context) are the three implementations; each supplies only the
// sources it has, and says so through what it returns rather than through a second, quietly different formula.
public interface IStatContext
{
Lot Lot { get; }
float HeatFactor(PerformanceStat stat);
float DurabilityFactor(PerformanceStat stat);
float ScaleModifier(PerformanceStat stat);
float ConstantModifier(PerformanceStat stat);
}
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class PerformanceStat
{
@ -619,6 +632,19 @@ public class PerformanceStat
return ConstantModifiers[entity];
}
// The one evaluation path. Quality is read from the context's Lot the same way for everyone; heat,
// durability and modifiers are whatever the context has, and a context with none of those returns the
// identity for that term (1 for a multiplied factor, 0 for an added one) instead of a bespoke formula.
// Callers keep their own NaN handling: an unequipped read throws with diagnostic detail, an equipped or
// consumable read falls back to Min. That disagreement is not named as a defect, so it is not touched here.
public float Evaluate(IStatContext context)
{
var quality = pow(context.Lot.QualityForRole(FromRole), QualityExponent);
var durability = context.DurabilityFactor(this);
var heat = context.HeatFactor(this);
return lerp(Min, Max, quality * durability * heat) * context.ScaleModifier(this) + context.ConstantModifier(this);
}
}
[CultDocument("aetheria.personalityattribute", "1"), Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)]