Project

rpg_lib

0.0
No commit activity in last 3 years
No release in over 3 years
Library of tools for automating role-playing game tasks.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.14
~> 12.0
~> 3.5
~> 0.47
~> 0.13

Runtime

~> 1.6
 Project Readme

RpgLib

RpgLib is a Ruby gem that performs tasks that tabletop role-playing game nerds need to automate things.

At the moment, the API contains 3 entries: roll_die, roll, and choose.

roll_die

roll_die(sides) generates a random number between 1 and sides.

# generate a d6 roll
roll_die(6)

# generate a d100 roll
roll_die(100)

# generate a d9 roll - doesn't have to be standard polyhedrals
roll_die(9)

roll

roll(dice) evaluates the passed dice expression. dice can be any mathematical expression using whole numbers, operators +, -, *, and /, and dice expressions of the form [X]dY (where X is the optional number of times to roll, and Y is the side-count of the die).

roll('d100')
roll('3d6')
roll('2d10*100 + 3d6*10')

choose

choose(options) selects a random entry from the passed array.

choose(['red', 'green', 'blue', 'white'])
choose([:standard_treasure, :alternative_treasure])
choose([:one, 2, 'three'])

Installation

$> gem install rpg_lib

Use

For simple use:

require 'rpg_lib'
include RpgLib::Api

puts roll('3d6')

Exclude the include statement to use the internal classes directly, or to import into another namespace.

Development

$> rake spec
$> rake rubocop

If you make changes to the Treetop grammar, run:

$> rake treetop

and check in the new lib/rpg_list/parser/dice_expression_parser.rb.