Class: BCDice::DiceTable::D66RangeTable

Inherits:
Object
  • Object
show all
Defined in:
lib/bcdice/dice_table/d66_range_table.rb

Overview

項目をRangeを用いて参照するD66表

Instance Method Summary collapse

Constructor Details

#initialize(name, items) ⇒ D66RangeTable

Returns a new instance of D66RangeTable.

Parameters:

  • name (String)

    表の名前

  • items (Array<(Range, String)>)

    表の項目の配列



9
10
11
12
# File 'lib/bcdice/dice_table/d66_range_table.rb', line 9

def initialize(name, items)
  @name = name
  @items = items.freeze
end

Instance Method Details

#roll(randomizer) ⇒ String

表を振る

Parameters:

  • randomizer (#roll_once)

    ランダマイザ

Returns:

  • (String)

    結果



17
18
19
20
21
22
23
24
25
# File 'lib/bcdice/dice_table/d66_range_table.rb', line 17

def roll(randomizer)
  dice1 = randomizer.roll_once(6)
  dice2 = randomizer.roll_once(6)

  key = dice1 * 10 + dice2

  chosen = @items.find { |row| row[0].include?(key) }
  return RollResult.new(@name, key, chosen[1])
end