22 lines
889 B
TypeScript
22 lines
889 B
TypeScript
import type { GameConfig, Location, ShipModel } from "./schemas";
|
|
|
|
/**
|
|
* The deal's loan (decision 0.5.83): the price of every ship it hands over plus
|
|
* the lease of its bay, read from content so it follows any price change.
|
|
*/
|
|
export function dealLoanAmount(data: {
|
|
config: Pick<GameConfig, "deal">;
|
|
shipModels: readonly ShipModel[];
|
|
locations: readonly Location[];
|
|
}): number {
|
|
const { avatarShipModelId, veteranShipModelId, bayLocationId } = data.config.deal;
|
|
const price = (id: string) => {
|
|
const model = data.shipModels.find((m) => m.id === id);
|
|
if (!model) throw new Error(`Unknown deal ship model ${id}`);
|
|
return model.price;
|
|
};
|
|
const bay = data.locations.find((l) => l.id === bayLocationId);
|
|
if (!bay) throw new Error(`Unknown deal bay location ${bayLocationId}`);
|
|
return price(avatarShipModelId) + price(veteranShipModelId) + bay.bayLeasePrice;
|
|
}
|