/** * Credits. The whole economy is four numbers and a losing streak, and all of * it is pure: the match calls these and stores what comes back. */ export const START_CREDITS = 800; export const CREDIT_CAP = 9000; export const KILL_REWARD = 200; export const PLANT_REWARD = 300; export const WIN_REWARD = 3000; /** Rising with the streak, and capped at the third step. */ export const LOSS_BONUS = [1900, 2400, 2900]; export const clampCredits = (credits: number): number => Math.max(0, Math.min(CREDIT_CAP, Math.floor(credits))); export const award = (credits: number, amount: number): number => clampCredits(credits + amount); /** The loss bonus for a team that has now lost `streak` rounds in a row. */ export const lossBonus = (streak: number): number => LOSS_BONUS[Math.min(Math.max(streak, 1), LOSS_BONUS.length) - 1]!; /** What a round's end pays each member of a team. */ export function roundReward(won: boolean, lossStreak: number, planted: boolean): number { if (won) return WIN_REWARD; // A team that lost the round but got the spike down keeps a little more. return lossBonus(lossStreak) + (planted ? PLANT_REWARD : 0); } /** A purchase either happens at a price or is refused; never a debt. */ export function spend(credits: number, cost: number): { ok: boolean; credits: number } { if (!Number.isFinite(cost) || cost < 0 || cost > credits) return { ok: false, credits }; return { ok: true, credits: clampCredits(credits - cost) }; }