Add routes and services for all game domains: market buy/sell with dynamic pricing, mission generation and completion, player stats and travel, inventory queries, leaderboard, city list, and world events. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
30 lines
1.1 KiB
TypeScript
30 lines
1.1 KiB
TypeScript
import { balance } from '../../config/gameBalance.js';
|
|
import { clamp } from '../../shared/validators.js';
|
|
|
|
/**
|
|
* Formula del mercato dinamico (blueprint §9):
|
|
* rawPrice = basePrice * economyModifier * demand / max(supply, minSupplyDivisor) * eventModifier
|
|
* con rawPrice limitato a [basePrice*minPriceFactor, basePrice*maxPriceFactor].
|
|
*/
|
|
export function computePrices(
|
|
basePrice: number,
|
|
economyModifier: number,
|
|
demand: number,
|
|
supply: number,
|
|
eventModifier: number,
|
|
): { buyPrice: number; sellPrice: number } {
|
|
const m = balance.market;
|
|
const raw =
|
|
basePrice * economyModifier * (demand / Math.max(supply, m.minSupplyDivisor)) * eventModifier;
|
|
const clamped = clamp(raw, basePrice * m.minPriceFactor, basePrice * m.maxPriceFactor);
|
|
return {
|
|
buyPrice: Math.round(clamped * m.buyMargin),
|
|
sellPrice: Math.round(clamped * m.sellMargin),
|
|
};
|
|
}
|
|
|
|
/** Mantiene demand/supply nei limiti consentiti. */
|
|
export function clampDemandSupply(value: number): number {
|
|
return clamp(value, balance.market.minDemandSupply, balance.market.maxDemandSupply);
|
|
}
|