| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
export const START_CREDITS = 800; |
| 7 |
export const CREDIT_CAP = 9000; |
| 8 |
export const KILL_REWARD = 200; |
| 9 |
export const PLANT_REWARD = 300; |
| 10 |
export const WIN_REWARD = 3000; |
| 11 |
|
| 12 |
export const LOSS_BONUS = [1900, 2400, 2900]; |
| 13 |
|
| 14 |
export const clampCredits = (credits: number): number => |
| 15 |
Math.max(0, Math.min(CREDIT_CAP, Math.floor(credits))); |
| 16 |
|
| 17 |
export const award = (credits: number, amount: number): number => clampCredits(credits + amount); |
| 18 |
|
| 19 |
|
| 20 |
export const lossBonus = (streak: number): number => |
| 21 |
LOSS_BONUS[Math.min(Math.max(streak, 1), LOSS_BONUS.length) - 1]!; |
| 22 |
|
| 23 |
|
| 24 |
export function roundReward(won: boolean, lossStreak: number, planted: boolean): number { |
| 25 |
if (won) return WIN_REWARD; |
| 26 |
|
| 27 |
return lossBonus(lossStreak) + (planted ? PLANT_REWARD : 0); |
| 28 |
} |
| 29 |
|
| 30 |
|
| 31 |
export function spend(credits: number, cost: number): { ok: boolean; credits: number } { |
| 32 |
if (!Number.isFinite(cost) || cost < 0 || cost > credits) return { ok: false, credits }; |
| 33 |
return { ok: true, credits: clampCredits(credits - cost) }; |
| 34 |
} |