server: game API modules — market, missions, players, inventory, leaderboard, cities, events

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>
This commit is contained in:
2026-06-09 23:41:44 +02:00
co-authored by Claude Sonnet 4.6
parent c792f67e2d
commit fb62a39dab
13 changed files with 875 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
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);
}