Class: BCDice::DiceTable::ChainTable
- Inherits:
-
Object
- Object
- BCDice::DiceTable::ChainTable
- Defined in:
- lib/bcdice/dice_table/chain_table.rb
Instance Method Summary collapse
-
#initialize(name, type, items) ⇒ ChainTable
constructor
A new instance of ChainTable.
-
#roll(randomizer) ⇒ String
表を振る.
Constructor Details
#initialize(name, type, items) ⇒ ChainTable
Returns a new instance of ChainTable.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/bcdice/dice_table/chain_table.rb', line 9 def initialize(name, type, items) @name = name @items = items.freeze m = /(\d+)D(\d+)/i.match(type) unless m raise ArgumentError, "Unexpected table type: #{type}" end @times = m[1].to_i @sides = m[2].to_i end |
Instance Method Details
#roll(randomizer) ⇒ String
表を振る
25 26 27 28 29 30 31 32 |
# File 'lib/bcdice/dice_table/chain_table.rb', line 25 def roll(randomizer) value = randomizer.roll_sum(@times, @sides) index = value - @times chosen = @items[index] chosen = chosen.roll(randomizer) if chosen.respond_to?(:roll) return RollResult.new(@name, value, chosen) end |