Class: BCDice::GameSystem::Yggdrasill::ChainTable

Inherits:
DiceTable::Table show all
Defined in:
lib/bcdice/game_system/Yggdrasill.rb

Instance Method Summary collapse

Methods inherited from DiceTable::Table

#choice, from_i18n

Constructor Details

#initialize(name, type, items, additonal_table:, additonal_index:) ⇒ ChainTable

Returns a new instance of ChainTable.



331
332
333
334
335
336
# File 'lib/bcdice/game_system/Yggdrasill.rb', line 331

def initialize(name, type, items, additonal_table:, additonal_index:)
  super(name, type, items)

  @additonal_table = additonal_table
  @index = additonal_index
end

Instance Method Details

#roll(randomizer) ⇒ Object



338
339
340
341
342
343
344
345
346
# File 'lib/bcdice/game_system/Yggdrasill.rb', line 338

def roll(randomizer)
  value = randomizer.roll_sum(@times, @sides)
  chosen = choice(value)

  return chosen unless @index.include?(value)

  body = "#{chosen.body}#{@additonal_table.roll(randomizer)}"
  DiceTable::RollResult.new(chosen.table_name, chosen.value, body)
end