Class: BCDice::GameSystem::Yggdrasill::YggTable

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_type:, additonal_format:, additonal_index:, out_of_control: nil) ⇒ YggTable

Returns a new instance of YggTable.



297
298
299
300
301
302
303
304
305
306
307
308
309
310
# File 'lib/bcdice/game_system/Yggdrasill.rb', line 297

def initialize(name, type, items, additonal_type:, additonal_format:, additonal_index:, out_of_control: nil)
  super(name, type, items)

  m = /(\d+)D(\d+)/i.match(additonal_type)
  unless m
    raise ArgumentError, "Unexpected table type: #{additonal_type}"
  end

  @additonal_times = m[1].to_i
  @additonal_sides = m[2].to_i
  @format = additonal_format
  @index = additonal_index
  @out_of_control = out_of_control
end

Instance Method Details

#roll(randomizer) ⇒ Object



312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
# File 'lib/bcdice/game_system/Yggdrasill.rb', line 312

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

  return chosen unless @index.include?(value) || @out_of_control == value

  body =
    if @out_of_control == value
      "#{chosen.body}#{RA90.roll(randomizer)}"
    else
      list = randomizer.roll_barabara(@additonal_times, @additonal_sides)
      chosen.body + format(@format, total: list.sum(), list: list.join(","))
    end

  DiceTable::RollResult.new(chosen.table_name, chosen.value, body)
end