(rng: () => number)
| 41 | } |
| 42 | |
| 43 | function rollRarity(rng: () => number): Rarity { |
| 44 | const total = Object.values(RARITY_WEIGHTS).reduce((a, b) => a + b, 0) |
| 45 | let roll = rng() * total |
| 46 | for (const rarity of RARITIES) { |
| 47 | roll -= RARITY_WEIGHTS[rarity] |
| 48 | if (roll < 0) return rarity |
| 49 | } |
| 50 | return 'common' |
| 51 | } |
| 52 | |
| 53 | const RARITY_FLOOR: Record<Rarity, number> = { |
| 54 | common: 5, |