/** Central Exchange (marketplace plaza) staff + letter copy. */ export const MARKET_ORDER_MAX_AGE_MS = 30 * 24 * 60 * 60 * 1000; export const CENTRAL_EXCHANGE_STAFF = Object.freeze([ "Bobby Pennies", "Ada Ledger", "Clive Quill", "Marge Tally", "Nigel Coinwright", "Pearl Balance", "Otto Vault", "Iris Counter" ]); export function pickExchangeClerk (random = Math.random) { const index = Math.floor(random() * CENTRAL_EXCHANGE_STAFF.length) % CENTRAL_EXCHANGE_STAFF.length; return CENTRAL_EXCHANGE_STAFF[index]; } export function exchangeSignature (clerkName) { return `Signed,\n${clerkName}\nCentral Exchange`; } export function soldLetterBody ({ itemName, quantity, unitPrice, clerkName }) { return [ `Good news — your sell order for ${quantity}× ${itemName} has been filled at ${unitPrice} coins each.`, "", "The proceeds have been deposited in your bank vault.", "", exchangeSignature(clerkName) ].join("\n"); } export function buyFilledLetterBody ({ itemName, quantity, unitPrice, clerkName }) { return [ `Your buy order for ${quantity}× ${itemName} has been filled at ${unitPrice} coins each.`, "", "The goods have been deposited in your bank vault.", "", exchangeSignature(clerkName) ].join("\n"); } export function orderExpiredLetterBody ({ side, itemName, quantity, escrowLabel, clerkName }) { const kind = side === "buy" ? "buy" : "sell"; return [ `Unfortunately your ${kind} order for ${quantity}× ${itemName} could not be filled within one month.`, "", `Your reserved ${escrowLabel} has been returned to your bank.`, "", exchangeSignature(clerkName) ].join("\n"); } export function orderCancelledLetterBody ({ side, itemName, quantity, escrowLabel, clerkName }) { const kind = side === "buy" ? "buy" : "sell"; return [ `Your ${kind} order for ${quantity}× ${itemName} was cancelled.`, "", `Your reserved ${escrowLabel} has been returned to your bank.`, "", exchangeSignature(clerkName) ].join("\n"); } /** Deterministic midpoint unit price for integer coins (half rounds away from zero via Math.round). */ export function midpointTradePrice (buyerMaximum, sellerMinimum) { const high = Math.max(0, Math.floor(Number(buyerMaximum) || 0)); const low = Math.max(0, Math.floor(Number(sellerMinimum) || 0)); return Math.max(0, Math.round((high + low) / 2)); }