Make loadout availability a port and move the charge into Materialize (Cut 10 fix)

Materialize takes isAvailable as a Predicate<FactionProductData>; the restore
menu passes LoadoutGenerator.IsAvailable for the docked station, so generation
and loadouts still share one availability rule. Candidate products are ordered
by record key, so "first available product" no longer depends on dictionary
order. Materialize charges Price through ref credits only when it returns a
ship; RestoreLoadout no longer subtracts on its own.

Tests: a slot that resolves but does not fit builds nothing, charges nothing and
is listed; Price is the sum of design prices and is charged on success; the
first available product in key order builds a slot, a later one is used when
the first is unavailable, and none available fails the slot.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-09-14 22:27:03 +02:00
commit 5e5c304e37
4 changed files with 88 additions and 18 deletions

View file

@ -187,7 +187,7 @@ public class InventoryPanel : MonoBehaviour, IPointerClickHandler
loadouts.Select<Loadout, (string text, Action action, bool enabled)>(loadout =>
{
var price = Loadouts.Price(GameManager.ItemManager, loadout);
return ($"{loadout.Name} - {price:n0}", () => RestoreLoadout(loadout, price), price < GameManager.Credits);
return ($"{loadout.Name} - {price:n0}", () => RestoreLoadout(loadout), price < GameManager.Credits);
}));
}
@ -198,12 +198,14 @@ public class InventoryPanel : MonoBehaviour, IPointerClickHandler
// Builds the loadout against the current galaxy at the docked station. On failure nothing changes: no ship, no
// charge, and a dialog lists every slot that could not be built here.
private void RestoreLoadout(Loadout loadout, int price)
private void RestoreLoadout(Loadout loadout)
{
var station = GameManager.DockedEntity;
var failures = new List<string>();
var ship = Loadouts.Materialize(GameManager.ItemManager, ActionGameManager.CurrentGalaxy, GameManager.Zone.GalaxyZone,
station.Faction, GameManager.Zone, loadout, failures);
var availability = new LoadoutGenerator(ref GameManager.ItemManager.Random, GameManager.ItemManager,
ActionGameManager.CurrentGalaxy, GameManager.Zone.GalaxyZone, station.Faction, 0);
var ship = Loadouts.Materialize(GameManager.ItemManager, GameManager.Zone, loadout, availability.IsAvailable,
ref GameManager.Credits, failures);
if (ship == null)
{
Dialog.Clear();
@ -214,7 +216,6 @@ public class InventoryPanel : MonoBehaviour, IPointerClickHandler
return;
}
GameManager.Credits -= price;
ship.SetParent(station);
ship.IsPlayerShip = true;
GameManager.DockingBay.DockedShip = ship;