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 <noreply@anthropic.com>
This commit is contained in:
parent
68d80968e8
commit
73dd96be00
1 changed files with 13 additions and 3 deletions
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue