Class: BCDice::DiceTable::D66Table
- Inherits:
-
Object
- Object
- BCDice::DiceTable::D66Table
- Defined in:
- lib/bcdice/dice_table/d66_table.rb
Overview
D66を振って出目を昇順/降順にして表を参照する
Direct Known Subclasses
D66LeftRangeTable, GameSystem::BeginningIdol::D66WithAbnormality, GameSystem::BeginningIdol::WorkWithChanceTable
Class Method Summary collapse
Instance Method Summary collapse
- #choice(key) ⇒ Object
-
#initialize(name, sort_type, items) ⇒ D66Table
constructor
A new instance of D66Table.
-
#roll(randomizer) ⇒ String
表を振る.
Constructor Details
#initialize(name, sort_type, items) ⇒ D66Table
Returns a new instance of D66Table.
20 21 22 23 24 |
# 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 |
Class Method Details
.from_i18n(key, locale) ⇒ D66Table
10 11 12 13 14 15 |
# 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 |
Instance Method Details
#choice(key) ⇒ Object
45 46 47 |
# File 'lib/bcdice/dice_table/d66_table.rb', line 45 def choice(key) RollResult.new(@name, key, @items[key]) end |
#roll(randomizer) ⇒ String
表を振る
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/bcdice/dice_table/d66_table.rb', line 29 def roll(randomizer) dice = randomizer.(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) RollResult.new(@name, key, chosen) end |