Class: BCDice::GameSystem::BeginningIdol::ChainTable
- Inherits:
-
Object
- Object
- BCDice::GameSystem::BeginningIdol::ChainTable
- Defined in:
- lib/bcdice/game_system/beginning_idol/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.
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/bcdice/game_system/beginning_idol/chain_table.rb', line 10 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
表を振る
26 27 28 29 30 31 32 33 |
# File 'lib/bcdice/game_system/beginning_idol/chain_table.rb', line 26 def roll(randomizer) value = randomizer.roll_sum(@times, @sides) index = value - @times chosen = @items[index] body = chosen.map { |item| item.respond_to?(:roll) ? item.roll(randomizer) : item }.join("\n") return "#{@name}(#{value}) > #{body}" end |