class BCDice::DiceTable::D66Table

D66を振って出目を昇順/降順にして表を参照する

Public Class Methods

from_i18n(key, locale) click to toggle source

@param key [String] @param locale [Symbol] @return [D66Table]

# File lib/bcdice/dice_table/d66_table.rb, line 10
def self.from_i18n(key, locale)
  table = I18n.t(key, locale: locale)
  sort_type = D66SortType.const_get(table[:d66_sort_type])

  new(table[:name], sort_type, table[:items])
end
new(name, sort_type, items) click to toggle source

@param [String] name 表の名前 @param [Symbol] sort_type 出目入れ替えの方式 BCDice::D66SortType @param [Hash] items 表の項目 Key は数値

# File lib/bcdice/dice_table/d66_table.rb, line 20
def initialize(name, sort_type, items)
  @name = name
  @sort_type = sort_type
  @items = items.freeze
end

Public Instance Methods

roll(randomizer) click to toggle source

表を振る @param randomizer [#roll_barabara] ランダマイザ @return [String] 結果

# File lib/bcdice/dice_table/d66_table.rb, line 29
def roll(randomizer)
  dice = randomizer.roll_barabara(2, 6)

  case @sort_type
  when D66SortType::ASC
    dice.sort!
  when D66SortType::DESC
    dice.sort!.reverse!
  end

  key = dice[0] * 10 + dice[1]
  chosen = @items[key]
  chosen = chosen.roll(randomizer) if chosen.respond_to?(:roll)
  return RollResult.new(@name, key, chosen)
end