Root RPG
The @randsum/games/root-rpg subpath provides mechanics for Root RPG, a tabletop roleplaying game set in the world of the Root board game. It uses a 2d6 + bonus system with success thresholds similar to Powered by the Apocalypse games.
Official SiteRoot RPG by Magpie Games
Installation
Section titled “Installation”bun add @randsum/gamesnpm install @randsum/gamesimport { roll } from '@randsum/games/root-rpg'
// Roll with a stat bonusconst { result, total } = roll({ bonus: 2 })// result: 'strong_hit' | 'weak_hit' | 'miss'import { roll } from '@randsum/games/root-rpg'
const { result } = roll({ bonus: 0 })
switch (result) {case 'strong_hit': // 10+ total: complete success breakcase 'weak_hit': // 7-9 total: partial success with cost breakcase 'miss': // 6- total: failure break}import { roll } from '@randsum/games/root-rpg'
roll({ bonus: 2 }) // Strong statroll({ bonus: 0 }) // No bonusroll({ bonus: -1 }) // Penalty
// Advantage and disadvantage roll 3d6 and keep the best or worst tworoll({ bonus: 1, rollingWith: 'Advantage' })roll({ bonus: 1, rollingWith: 'Disadvantage' })roll(input: { bonus: number, rollingWith?: 'Advantage' | 'Disadvantage' })
Section titled “roll(input: { bonus: number, rollingWith?: 'Advantage' | 'Disadvantage' })”Input:
| Property | Type | Description |
|---|---|---|
bonus |
number |
Stat modifier, an integer from -3 to +5 |
rollingWith |
'Advantage' | 'Disadvantage' | undefined |
Roll 3d6, keep the 2 highest or lowest |
Returns: GameRollResult with:
| Property | Type | Description |
|---|---|---|
result |
RootRpgRollResult |
'strong_hit' | 'weak_hit' | 'miss' |
total |
number |
Sum of the kept dice + bonus |
rolls |
RollRecord[] |
Raw dice data from the core roller |
Outcomes
Section titled “Outcomes”| Outcome | Total | Description |
|---|---|---|
strong_hit |
10+ | Complete success: you achieve your goal |
weak_hit |
7-9 | Partial success: you do it, but with a cost or complication |
miss |
6- | Failure: things go badly |
Error handling
Section titled “Error handling”Game roll() can throw two types of errors:
ValidationError(from@randsum/roller): numeric input out of range, not an integer, or not finite (e.g.,bonus: 9when the maximum is 5)SchemaError(from@randsum/games/root-rpg): game-specific issues like an invalidrollingWithvalue
import { roll, SchemaError } from '@randsum/games/root-rpg'import { ValidationError } from '@randsum/roller'
try {roll({ bonus: 9 })} catch (error) {if (error instanceof ValidationError) { // Out-of-range bonus (must be -3 to 5) console.log(error.code) // 'VALIDATION_ERROR'} else if (error instanceof SchemaError) { // e.g., invalid rollingWith enum value console.log(error.code) // 'INVALID_INPUT_TYPE'}}import type { RootRpgRollResult, GameRollResult, RollRecord } from '@randsum/games/root-rpg'import { SchemaError } from '@randsum/games/root-rpg'Schema
Section titled “Schema”This game is powered by a .randsum.json spec that defines the 2d6+bonus resolution, advantage and disadvantage, and outcome tiers. The TypeScript code is generated from this spec at build time. See Schema Overview for how game specs work.