From 73dd96be003246cf2ec364ad312c34f284148fe7 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 7 Oct 2026 02:08:37 +0200 Subject: [PATCH] StationServices: a repair share is never below the sell value it adds, rounded in the sell price's own function Selling floors price * fraction * condition in doubles while repair ceilinged a separate expression, so the two disagreed by one credit for some prices (GetPrice 360 at durability 7 of 20). SellValue is now the one sell rounding, and RepairShare charges at least SellValue(whole) - SellValue(worn), so repair-never-profits holds exactly. Co-Authored-By: Claude Opus 5.5 --- Assets/Scripts/ServerShared/StationServices.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Assets/Scripts/ServerShared/StationServices.cs b/Assets/Scripts/ServerShared/StationServices.cs index ef1e791d8..a6cb4bfb5 100644 --- a/Assets/Scripts/ServerShared/StationServices.cs +++ b/Assets/Scripts/ServerShared/StationServices.cs @@ -31,7 +31,7 @@ public static class StationServices switch (item) { case CraftedItemInstance crafted: - return (int) Math.Floor(items.GetPrice(crafted) * fraction * Condition(items, crafted)); + return SellValue(items.GetPrice(crafted), fraction, Condition(items, crafted)); case SimpleCommodity commodity: return (int) Math.Floor((long) items.GetData(commodity).Price * commodity.Quantity * fraction); default: @@ -121,10 +121,20 @@ public static class StationServices return Math.Max(0, Math.Min(1, gear.Durability / (double) design.Durability)); } + // The sell value of a price at a condition, rounded down. The one place the sell rounding lives: RepairShare + // prices the sell value a repair adds from the same function, so the two cannot round apart. + private static int SellValue(int price, double fraction, double condition) => + (int) Math.Floor(price * fraction * condition); + + // The share of the repair charge for one piece of gear: its wear at the repair fraction, rounded up, and never + // less than the sell value the repair adds, so mending before selling never nets credits. private static long RepairShare(ItemManager items, EquippableItem gear, double fraction) { - var worn = 1 - Condition(items, gear); - return (long) Math.Ceiling(worn * items.GetPrice(gear) * fraction); + var price = items.GetPrice(gear); + var condition = Condition(items, gear); + var sellFraction = (double) items.GameplaySettings.SellFraction; + var added = SellValue(price, sellFraction, 1) - SellValue(price, sellFraction, condition); + return Math.Max(added, (long) Math.Ceiling((1 - condition) * price * fraction)); } }