Skip to content

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.

Terminal window
bun add @randsum/games
import { roll } from '@randsum/games/root-rpg'
// Roll with a stat bonus
const { result, total } = roll(2)
// result: 'Strong Hit' | 'Weak Hit' | 'Miss'
import { roll } from '@randsum/games/root-rpg'
const { result } = roll(0)
switch (result) {
case 'Strong Hit':
// 10+ total: complete success
break
case 'Weak Hit':
// 7-9 total: partial success with cost
break
case 'Miss':
// 6- total: failure
break
}
import { roll } from '@randsum/games/root-rpg'
roll(2) // Strong stat
roll(0) // No bonus
roll(-1) // Penalty

Input:

ParameterTypeDescription
bonusnumberStat modifier (-20 to +20)

Returns: GameRollResult with:

PropertyTypeDescription
resultRootRpgRollResult'Strong Hit' | 'Weak Hit' | 'Miss'
totalnumberSum of 2d6 + bonus
rollsRollRecord[]Raw dice data from the core roller
OutcomeTotalDescription
Strong Hit10+Complete success — you achieve your goal
Weak Hit7-9Partial success — you do it, but with a cost or complication
Miss6-Failure — things go badly

Game roll() can throw two types of errors:

  • ValidationError (from @randsum/roller) — numeric input out of range or not finite (e.g., bonus: 999 when max is 20)
  • SchemaError (from @randsum/games/root-rpg) — game-specific issues like unmatched outcome tables
import { roll, SchemaError } from '@randsum/games/root-rpg'
import { ValidationError } from '@randsum/roller'
try {
roll(999)
} catch (error) {
if (error instanceof ValidationError) {
// Out-of-range bonus (must be -20 to 20)
console.log(error.code) // 'VALIDATION_ERROR'
} else if (error instanceof SchemaError) {
// Game-specific error
console.log(error.code) // 'NO_TABLE_MATCH'
}
}
import type { RootRpgRollResult, GameRollResult, RollRecord } from '@randsum/games/root-rpg'
import { SchemaError } from '@randsum/games/root-rpg'

This game is powered by a .randsum.json spec that defines the 2d6+bonus resolution and outcome tiers. The TypeScript code is generated from this spec at build time. See Schema Overview for how game specs work.