From 174bdaded13dbac621a16314091a337f1f7d88d0 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 18 Oct 2026 07:09:31 +0200 Subject: [PATCH] Every reader of an item's quality reads Lot.EffectiveQuality Price, tier, equipped thermal and durability exponents, wear and the unequipped durability exponent now read the one effective quality; no reader keeps a path to the assembly alone. Tests pin each reader against a lot whose part sits below its assembly. Unverified until the Yggdrasil run. Co-Authored-By: Claude Sonnet 5.5 --- Assets/Scripts/ServerShared/Entity.cs | 7 +- Assets/Scripts/ServerShared/ItemData.cs | 2 +- Assets/Scripts/ServerShared/ItemManager.cs | 10 +-- .../HeatResponseTests.cs | 24 ++++++- tests/Aetheria.Shared.Tests/LoadoutTests.cs | 64 +++++++++++++++---- 5 files changed, 86 insertions(+), 21 deletions(-) diff --git a/Assets/Scripts/ServerShared/Entity.cs b/Assets/Scripts/ServerShared/Entity.cs index 034e211bb..4a2b25402 100644 --- a/Assets/Scripts/ServerShared/Entity.cs +++ b/Assets/Scripts/ServerShared/Entity.cs @@ -2189,16 +2189,17 @@ public class EquippedItem : IStatContext Hardpoint = hardpoint; EquippableItem = item; Lot = ItemManager.GetLot(item); + var quality = Lot.EffectiveQuality(); Position = position; Conductivity = Data.Conductivity; ThermalExponent = lerp( ItemManager.GameplaySettings.ThermalQualityMin, ItemManager.GameplaySettings.ThermalQualityMax, - pow(Lot.Quality, ItemManager.GameplaySettings.ThermalQualityExponent)); + pow(quality, ItemManager.GameplaySettings.ThermalQualityExponent)); DurabilityExponent = lerp( ItemManager.GameplaySettings.DurabilityQualityMin, ItemManager.GameplaySettings.DurabilityQualityMax, - pow(Lot.Quality, ItemManager.GameplaySettings.DurabilityQualityExponent)); + pow(quality, ItemManager.GameplaySettings.DurabilityQualityExponent)); var hullData = itemManager.GetData(entity.Hull); InsetShape = hullData.Shape.Inset(Data.Shape, position, item.Rotation); if (Entity.Temperature != null) oldTemperature = Temperature; @@ -2369,7 +2370,7 @@ public class EquippedItem : IStatContext Entity.Resolver.InvalidateSource(this, StatSource.Durability); var performanceThreshold = Entity.Settings.ShutdownPerformance; Wear = (1 - pow(ThermalPerformance, - (1 - pow(Lot.Quality, ItemManager.GameplaySettings.QualityWearExponent)) * + (1 - pow(Lot.EffectiveQuality(), ItemManager.GameplaySettings.QualityWearExponent)) * ItemManager.GameplaySettings.ThermalWearExponent) + deltaTemp * ItemManager.GameplaySettings.DeltaTempWearExponent ) * Data.Durability / Data.ThermalResilience; diff --git a/Assets/Scripts/ServerShared/ItemData.cs b/Assets/Scripts/ServerShared/ItemData.cs index d7b2ee9b3..a9619c61e 100644 --- a/Assets/Scripts/ServerShared/ItemData.cs +++ b/Assets/Scripts/ServerShared/ItemData.cs @@ -688,7 +688,7 @@ public class StatTerm { [JsonProperty("source"), Key(0)] public StatSource Source; [JsonProperty("exponent"), Key(1)] public float Exponent; - // The design role whose part quality this term reads; unset reads the item's own workmanship quality. + // The design role whose part quality this term reads; unset reads the item's effective quality (Lot.EffectiveQuality). // Njordr states the same rule as a derivation over dimensions; this is that rule with one dimension. [Inspectable, JsonProperty("role"), Key(2)] public string Role; } diff --git a/Assets/Scripts/ServerShared/ItemManager.cs b/Assets/Scripts/ServerShared/ItemManager.cs index 73e2c9592..12d45d101 100644 --- a/Assets/Scripts/ServerShared/ItemManager.cs +++ b/Assets/Scripts/ServerShared/ItemManager.cs @@ -82,7 +82,7 @@ public class ItemManager return result; } - // The unequipped case: quality and durability read live off the item and its lot; heat and modifiers do not + // The unequipped case: quality (the lot's effective quality) and durability read live off the item and its lot; heat and modifiers do not // exist without an entity, so they resolve as the identity for their term rather than a bespoke formula. private sealed class UnequippedStatContext : IStatContext { @@ -99,7 +99,7 @@ public class ItemManager _durabilityExponent = lerp( items.GameplaySettings.DurabilityQualityMin, items.GameplaySettings.DurabilityQualityMax, - pow(Lot.Quality, items.GameplaySettings.DurabilityQualityExponent)); + pow(Lot.EffectiveQuality(), items.GameplaySettings.DurabilityQualityExponent)); } public float HeatFactor(float exponent) => 1f; @@ -111,10 +111,11 @@ public class ItemManager public float ConstantModifier(PerformanceStat stat) => 0f; } + // Price follows effective quality (price-follows-effective-quality), so a sleeper's over-specced parts do not show in it. public int GetPrice(CraftedItemInstance item) { var data = GetData(item); - return (int) (GameplaySettings.QualityPriceModifier.Evaluate(GetLot(item).Quality) * data.Price); + return (int) (GameplaySettings.QualityPriceModifier.Evaluate(GetLot(item).EffectiveQuality()) * data.Price); } // Builds one of a manufacturer's branded products (quality-is-assembly-over-supply-chain): the unit's own quality is its @@ -222,9 +223,10 @@ public class ItemManager public string Title(ItemInstance item) => (item is CraftedItemInstance crafted ? Brand(crafted).Product?.Name : null) ?? GetData(item).Name; + // The tier name and colour follow price, so they hide the same sleepers. public (RarityTier tier, int upgrades) GetTier(CraftedItemInstance item) { - var quality = GetLot(item).Quality; + var quality = GetLot(item).EffectiveQuality(); var tier = GameplaySettings.Tiers[0]; foreach (var t in GameplaySettings.Tiers) if (quality + .001f > t.Quality) diff --git a/tests/Aetheria.Shared.Tests/HeatResponseTests.cs b/tests/Aetheria.Shared.Tests/HeatResponseTests.cs index 9711f91c1..6f1f768ee 100644 --- a/tests/Aetheria.Shared.Tests/HeatResponseTests.cs +++ b/tests/Aetheria.Shared.Tests/HeatResponseTests.cs @@ -26,14 +26,14 @@ public sealed class HeatResponseTests : IDisposable // A hull plus one thermal gear design, equipped and settled at the given start temperature (two // UpdatePerformance calls so deltaTemp reads 0 before the test drives its own change). - private EquippedItem BuildEquippedAt(CultCache cache, ItemManager items, float startTemperature, out Ship ship) + private EquippedItem BuildEquippedAt(CultCache cache, ItemManager items, float startTemperature, out Ship ship, Lot gearLot = null) { var maker = cache.RefOf(cache.GetByName("Maker")); var hullData = cache.GetByName("Skiff"); var thermalData = cache.GetByName("Thermal"); var hullItem = (EquippableItem) items.CreateInstance(items.CreateLot(hullData, maker, .5f)); ship = new Ship(items, null, hullItem, new EntitySettings()); - var gearItem = (EquippableItem) items.CreateInstance(items.CreateLot(thermalData, maker, .5f)); + var gearItem = (EquippableItem) items.CreateInstance(gearLot != null ? items.Lots.Add(gearLot) : items.CreateLot(thermalData, maker, .5f)); Assert.True(ship.TryEquip(gearItem, HardpointCell)); var equipped = ship.Equipment.Single(e => e.Data is GearData); foreach (var cell in equipped.InsetShape.Coordinates) ship.Temperature[cell.x, cell.y] = startTemperature; @@ -249,6 +249,26 @@ public sealed class HeatResponseTests : IDisposable Assert.True(equipped.Wear > 0f); } + // Wear's quality term reads the lot's effective quality: a .9 lot whose one part is .1 wears as a roleless .1 lot, and not + // as a roleless .9 lot. + [Fact] + public void HeldOutsidePlateauWearReadsEffectiveQuality() + { + using var cache = OpenCatalogWithThermalGear(); + var items = new ItemManager(cache, new ProvenanceLedger(), Settings(), _ => { }); + var thermal = cache.RefOf(cache.GetByName("Thermal")); + Lot Gear(float assembly, params float[] parts) => new Lot + { + Design = thermal, Origin = new Attributed(), Quality = assembly, + Roles = parts.Select(p => new RoleFill { Role = "core", Quality = p }).ToList() + }; + float WearAt10(Lot lot) => BuildEquippedAt(cache, items, 10f, out _, lot).Wear; + + var sleeper = WearAt10(Gear(.9f, .1f)); + Assert.Equal(WearAt10(Gear(.1f)), sleeper, 5); + Assert.NotEqual(WearAt10(Gear(.9f)), sleeper, 5); + } + [Fact] public void AFastSwingAcrossThePlateauStillWears() { diff --git a/tests/Aetheria.Shared.Tests/LoadoutTests.cs b/tests/Aetheria.Shared.Tests/LoadoutTests.cs index 9fe71b898..528f5ad58 100644 --- a/tests/Aetheria.Shared.Tests/LoadoutTests.cs +++ b/tests/Aetheria.Shared.Tests/LoadoutTests.cs @@ -490,7 +490,8 @@ public sealed class LoadoutTests : IDisposable } // A Lamp lot with Quality .2 and one role fill (lens .15, under the assembly): a stat reading that role gets .15, one - // reading none gets the effective quality .15, and GetTier reads .2. + // reading none gets the effective quality .15, and GetTier reads .2. A lot of + // assembly .6 with a lens of .3 is Common, not Rare: the tier follows its effective quality. [Fact] public void StatsReadTheLot() { @@ -519,8 +520,16 @@ public sealed class LoadoutTests : IDisposable Quality = .6f, Roles = new List() }); + var cappedLot = items.Lots.Add(new Lot + { + Design = cache.RefOf(lamp), + Origin = new Attributed(), + Quality = .6f, + Roles = new List { new RoleFill { Role = "lens", Quality = .3f } } + }); var instance = (EquippableItem) items.CreateInstance(commonLot); var rareInstance = (EquippableItem) items.CreateInstance(rareLot); + var cappedInstance = (EquippableItem) items.CreateInstance(cappedLot); var withRole = new PerformanceStat { Min = 0, Max = 1, Terms = { new StatTerm { Source = StatSource.Quality, Exponent = 1, Role = "lens" } } }; var noRole = new PerformanceStat { Min = 0, Max = 1, Terms = { new StatTerm { Source = StatSource.Quality, Exponent = 1 } } }; @@ -528,6 +537,7 @@ public sealed class LoadoutTests : IDisposable Assert.Equal(.15f, items.Evaluate(noRole, instance), 3); Assert.Equal(.2f, items.GetTier(instance).tier.Quality, 3); Assert.Equal(.5f, items.GetTier(rareInstance).tier.Quality, 3); + Assert.Equal(.2f, items.GetTier(cappedInstance).tier.Quality, 3); // Minting a second instance from an existing lot must not re-roll the lot's quality. var secondInstance = (EquippableItem) items.CreateInstance(commonLot); @@ -553,9 +563,10 @@ public sealed class LoadoutTests : IDisposable Assert.Equal(.25f, items.Evaluate(squared, instance), 3); } - // F4: GetPrice reads the lot's quality through GameplaySettings.QualityPriceModifier. + // F4: GetPrice reads the lot's effective quality through GameplaySettings.QualityPriceModifier: a lot of assembly .8 whose + // one part is .2 prices exactly as a roleless .2 lot (price-follows-effective-quality). [Fact] - public void GetPriceReadsLotQuality() + public void GetPriceReadsEffectiveQuality() { using var cache = Open(); var settings = RunSaveTests.TestSettings(); @@ -564,16 +575,24 @@ public sealed class LoadoutTests : IDisposable var lamp = cache.GetByName("Lamp"); var lowLot = items.Lots.Add(new Lot { Design = cache.RefOf(lamp), Origin = new Attributed(), Quality = .2f, Roles = new List() }); var highLot = items.Lots.Add(new Lot { Design = cache.RefOf(lamp), Origin = new Attributed(), Quality = .8f, Roles = new List() }); + var sleeperLot = items.Lots.Add(new Lot + { + Design = cache.RefOf(lamp), Origin = new Attributed(), Quality = .8f, + Roles = new List { new RoleFill { Role = "lens", Quality = .2f } } + }); var low = (EquippableItem) items.CreateInstance(lowLot); var high = (EquippableItem) items.CreateInstance(highLot); + var sleeper = (EquippableItem) items.CreateInstance(sleeperLot); Assert.True(items.GetPrice(high) > items.GetPrice(low)); + Assert.Equal(items.GetPrice(low), items.GetPrice(sleeper)); + Assert.True(items.GetPrice(sleeper) < items.GetPrice(high)); } - // F4: the durability exponent path in ItemManager.Evaluate reads the lot's quality (GameplaySettings. + // F4: the durability exponent path in ItemManager.Evaluate reads the lot's effective quality (GameplaySettings. // DurabilityQuality{Min,Max,Exponent}), independently of the quality-for-role term (absent here -- the - // stat declares only a Durability term). + // stat declares only a Durability term): a .9 lot whose one part is .1 evaluates as a roleless .1 lot. [Fact] - public void EvaluateDurabilityExponentReadsLotQuality() + public void EvaluateDurabilityExponentReadsEffectiveQuality() { using var cache = AetheriaStores.Open(Catalog, catalogWritable: true); var durable = cache.Upsert(new GearData { Name = "Durable", Hardpoint = HardpointType.Sensors, Shape = new Shape(), Price = 10, Durability = 100 }); @@ -582,19 +601,29 @@ public sealed class LoadoutTests : IDisposable var items = new ItemManager(cache, new ProvenanceLedger(), RunSaveTests.TestSettings(), _ => { }); var lowLot = items.Lots.Add(new Lot { Design = new CultRecordRef(durable.Key), Origin = new Attributed(), Quality = .1f, Roles = new List() }); var highLot = items.Lots.Add(new Lot { Design = new CultRecordRef(durable.Key), Origin = new Attributed(), Quality = .9f, Roles = new List() }); + var sleeperLot = items.Lots.Add(new Lot + { + Design = new CultRecordRef(durable.Key), Origin = new Attributed(), Quality = .9f, + Roles = new List { new RoleFill { Role = "lens", Quality = .1f } } + }); var low = (EquippableItem) items.CreateInstance(lowLot); var high = (EquippableItem) items.CreateInstance(highLot); + var sleeper = (EquippableItem) items.CreateInstance(sleeperLot); low.Durability = items.GetData(low).Durability / 2; high.Durability = items.GetData(high).Durability / 2; + sleeper.Durability = items.GetData(sleeper).Durability / 2; var stat = new PerformanceStat { Min = 0, Max = 1, Terms = { new StatTerm { Source = StatSource.Durability, Exponent = 1 } } }; Assert.NotEqual(items.Evaluate(stat, low), items.Evaluate(stat, high)); + Assert.Equal(items.Evaluate(stat, low), items.Evaluate(stat, sleeper), 3); + Assert.NotEqual(items.Evaluate(stat, high), items.Evaluate(stat, sleeper), 3); } - // F4: EquippedItem's thermal exponent (Entity.cs's EquippedItem constructor) reads the lot's quality - // (GameplaySettings.ThermalQuality{Min,Max,Exponent}), through a real equip on a live entity. + // F4: EquippedItem's thermal and durability exponents (Entity.cs's EquippedItem constructor) read the lot's effective + // quality (GameplaySettings.{Thermal,Durability}Quality{Min,Max,Exponent}), through a real equip on a live entity: a .9 + // lot whose one part is .1 equips as a roleless .1 lot. [Fact] - public void EquippedItemThermalExponentReadsLotQuality() + public void EquippedItemExponentsReadEffectiveQuality() { using var cache = Open(); var items = new ItemManager(cache, new ProvenanceLedger(), RunSaveTests.TestSettings(), _ => { }); @@ -604,18 +633,31 @@ public sealed class LoadoutTests : IDisposable // TestSettings has one tier, so materializing through a Loadout always rolls the same quality; mint the // gear's lot directly at a chosen quality and equip it onto a bare ship instead. - Ship BuildWithGearQuality(float quality) + Ship BuildWithGear(Func mintGear) { var hullItem = (EquippableItem) items.CreateInstance(items.CreateLot(hullData, maker, .5f)); var ship = new Ship(items, null, hullItem, new EntitySettings()); - var gearItem = (EquippableItem) items.CreateInstance(items.CreateLot(lampData, maker, quality)); + var gearItem = (EquippableItem) items.CreateInstance(mintGear()); Assert.True(ship.TryEquip(gearItem, HardpointCell)); return ship; } + Ship BuildWithGearQuality(float quality) => BuildWithGear(() => items.CreateLot(lampData, maker, quality)); + // The gear is a lot added directly: assembly .9, one part at .1. + Ship BuildWithSleeperGear() => BuildWithGear(() => items.Lots.Add(new Lot + { + Design = cache.RefOf(lampData), Origin = new Attributed(), Quality = .9f, + Roles = new List { new RoleFill { Role = "lens", Quality = .1f } } + })); var lowEquipped = BuildWithGearQuality(.1f).Equipment.Single(e => e.Data is GearData); var highEquipped = BuildWithGearQuality(.9f).Equipment.Single(e => e.Data is GearData); + var sleeperEquipped = BuildWithSleeperGear().Equipment.Single(e => e.Data is GearData); Assert.NotEqual(lowEquipped.ThermalExponent, highEquipped.ThermalExponent); + Assert.NotEqual(lowEquipped.DurabilityExponent, highEquipped.DurabilityExponent); + Assert.Equal(lowEquipped.ThermalExponent, sleeperEquipped.ThermalExponent, 5); + Assert.Equal(lowEquipped.DurabilityExponent, sleeperEquipped.DurabilityExponent, 5); + Assert.NotEqual(highEquipped.ThermalExponent, sleeperEquipped.ThermalExponent, 5); + Assert.NotEqual(highEquipped.DurabilityExponent, sleeperEquipped.DurabilityExponent, 5); } // Cut 0 (docs/stats-and-power-cut.md): the collapsed evaluation path (PerformanceStat.Evaluate(IStatContext))