Files
gioco-mobile/server/src/modules/market/pricing.ts
T

30 lines
1.1 KiB
TypeScript
Raw Normal View History

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);
}