Project

rpg-tools

0.0
No commit activity in last 3 years
No release in over 3 years
RPG Tools is a compilation of helpful tools when developing a Role Playing Game (RPG). For now the gem has three classes: Die, Throw and CheckRoll.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 3.0.0
 Project Readme

RPG Tools

RPG Tools is a compilation of helpful tools when developing a Role Playing Game (RPG). For now the gem has three classes:

Die: Models the use of a simple die (ie. D6, D10, D20, etc.)
Throw: Takes an array of Die to be rolled and the offset to be added (ie. 2D6, 3D4+5, 2D10,3D20+2, etc.)
CheckRoll: Using a Throw and a threshold models a check roll with one or several chances and some other settings (ie. 2D6 to get greater or equal to 10, 3D10 to get les than 15, etc.)

These tools try to be flexible, general and powerful. Most of Die representation in other gems do the job of a Throw (a pack of Dice with a offset) or just return the result of ten rolls as single Fixum giving no information of each of the single ten rolls (which may be important if you want to have detailed info or want to give feedback to the user). With RPG Tools each object acts as it should: a Die acts as a Die, with no more functionality than a normal Die. Also each roll has all the information needed just if you want it. By default rolling a Throw just returns the total amount, but if you ask for a detailed roll you will get the total amount and the result of each die of the Throw.

Installation

Add to your Gemfile:


  gem 'rpg-tools'

Then run:

  bundle update

Using RPG Tools. API

Using Tools::Die

Creating a new Die:


  die = Tools::Die.new #Creates a new Die with 20 sides (D20) by default
  die = Tools::Die.new 6 #Creates a new Die with 6 sides (D6)
  die = Tools::Die.new 100 #Creates a new Die with 100 sides (D100)

Rolling a Die:


  die = Tools::Die.new
  #Rolling the die once 
  die.roll # => 8
  #Rolling the die five times
  die.roll 5 # => [1, 20, 16, 11, 11]

More methods of Die:


  #Converting Die into string
  die1 = Tools::Die.new 20
  die2 = Tools::Die.new 6
  die3 = Tools::Die.new 100
  die1.to_s # => "D20"
  die2.to_s # => "D6"
  die3.to_s # => "D100"


  #Comparing Dice
  die1 = Tools::Die.new 20
  die2 = Tools::Die.new 6
  die3 = Tools::Die.new 20
  die1.eql? die1 # => true
  die1.eql? die2 # => false
  die1.eql? die3 # => true

Using Tools::Throw

Creating a new Throw:


  dice = [Tools::Die.new(6),Tools::Die.new(6),Tools::Die.new(20),Tools::Die.new(100),Tools::Die.new(100),Tools::Die.new(100)]
  offset = 3
  throw = Tools::Throw.new dice,offset #Creates a new throw with 2D6, 1D20, 3D100 and +3

Rolling a Throw:


  dice = [Tools::Die.new(6),Tools::Die.new(6),Tools::Die.new(20)]
  offset = 2
  throw = Tools::Throw.new dice,offset #Creates a new throw with 2D6, 1D20 and +2
  #Rolling the throw once (simple)
  throw.roll # => 10
  #Rolling the throw once (detailed)
  throw.roll 1,true # => [25, [6, 6, 11]]
  #Rolling the throw five times (simple)
  throw.roll 5 # => [23, 22, 18, 18, 16]
  #Rolling the throw five times (detailed)
  throw.roll 5, true # => [[26, [1, 4, 19]], [28, [6, 3, 17]], [13, [1, 4, 6]], [23, [5, 6, 10]], [11, [3, 5, 1]]]

More methods of Throw:


  #Converting Throw into string
  dice = [Tools::Die.new(6),Tools::Die.new(6),Tools::Die.new(20),Tools::Die.new(100),Tools::Die.new(100),Tools::Die.new(100)]
  offset = 3
  throw = Tools::Throw.new dice,offset #Creates a new throw with 2D6, 1D20, 3D100 and +3
  throw.to_s # => "2D6,1D20,3D100+3"

Using Tools::CheckRoll

Creating a new CheckRoll:


  dice = [Tools::Die.new(6),Tools::Die.new(6)]
  offset = 2
  throw = Tools::Throw.new dice,offset #Creates a new throw with 2D6+2
  threshold = 9
  check_roll = Tools::CheckRoll.new throw, threshold #Creates a CheckRoll with 2D6+2 throw and a threshold of 9

Rolling a CheckRoll:


  dice = [Tools::Die.new(6),Tools::Die.new(6)]
  offset = 2
  throw = Tools::Throw.new dice,offset #Creates a new throw with 2D6+2
  threshold = 9
  check_roll = Tools::CheckRoll.new throw, threshold #Creates a CheckRoll with 2D6+2 throw and a threshold of 9
  #Roll the CheckRoll
  check_roll.roll # => [false, 6]
  #CheckRoll results
  check_roll.is_successful? # => false
  check_roll.result # => [false, 6]
  check_roll.detailed_result # => [false, [6, [3, 1]]]
  #Reroll the CheckRoll
  check_roll.reroll # => [true, 12]
  #CheckRoll results
  check_roll.is_successful? # => true 
  check_roll.result # => [true, 12]
  check_roll.detailed_result # => [true, [12, [6, 4]]]

Using greater_than_threshold and greater_to_threshold attributes:


  dice = [Tools::Die.new(6),Tools::Die.new(6)]
  offset = 2
  throw = Tools::Throw.new dice,offset #Creates a new throw with 2D6+2
  threshold = 9
  #Creating a "greater and equal to" check
  check_roll1 = Tools::CheckRoll.new throw, threshold #1,true,true (by default)
  check_roll1.to_s # => "2D6+2 must be greater or equal to 9."
  #Creating a "greater than" check
  check_roll2 = Tools::CheckRoll.new throw, threshold, 1, true, false
  check_roll2.to_s # => "2D6+2 must be greater than 9." 
  #Creating a "less than" check
  check_roll3 = Tools::CheckRoll.new throw, threshold, 1, false, false
  check_roll3.to_s # => "2D6+2 must be less than 9."
  #Creating a "less and equal to" check
  check_roll4 = Tools::CheckRoll.new throw, threshold, 1, false, true
  check_roll4.to_s # => "2D6+2 must be less or equal to 9."

More methods of CheckRoll:


  #Converting CheckRoll into string
  dice = [Tools::Die.new(6),Tools::Die.new(6)]
  offset = 2
  throw = Tools::Throw.new dice,offset #Creates a new throw with 2D6+2
  threshold = 9
  check_roll = Tools::CheckRoll.new throw, threshold #Creates a CheckRoll with 2D6+2 throw and a threshold of 9
  check_roll.to_s # => "2D6+2 must be greater or equal to 9."

License

Copyright © 2011 Eduardo Casanova Cuesta

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.