Class: BCDice::GameSystem::BeginningIdol::ItemTable
- Inherits:
-
Object
- Object
- BCDice::GameSystem::BeginningIdol::ItemTable
- Defined in:
- lib/bcdice/game_system/beginning_idol/item_table.rb
Instance Method Summary collapse
-
#initialize(locale) ⇒ ItemTable
constructor
A new instance of ItemTable.
- #roll(randomizer, roll_counts = 1) ⇒ Object
- #roll_command(randomizer, command) ⇒ Object
Constructor Details
#initialize(locale) ⇒ ItemTable
Returns a new instance of ItemTable.
7 8 9 |
# File 'lib/bcdice/game_system/beginning_idol/item_table.rb', line 7 def initialize(locale) @locale = locale end |
Instance Method Details
#roll(randomizer, roll_counts = 1) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/bcdice/game_system/beginning_idol/item_table.rb', line 23 def roll(randomizer, roll_counts = 1) if roll_counts == 0 return nil end table = I18n.t("BeginningIdol.item_table", locale: @locale) dice_list = randomizer.(roll_counts, 6).sort grouped = dice_list.group_by(&:itself) item_list = grouped.map do |dice, list| item = table[:items][dice - 1] if grouped.size != 1 item = format(table[:emph], item: item) end if dice_list.size == grouped.size item else format(table[:counting], item: item, count: list.size) end end return "#{table[:name]} > [#{dice_list.join(',')}] > #{item_list.join(table[:sep])}" end |
#roll_command(randomizer, command) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/bcdice/game_system/beginning_idol/item_table.rb', line 11 def roll_command(randomizer, command) m = /^IT(\d+)?$/.match(command) unless m return nil end roll_counts = m[1]&.to_i || 1 return roll(randomizer, roll_counts) end |