Class: BCDice::GameSystem::Warhammer4::CriticalTable

Inherits:
Object
  • Object
show all
Defined in:
lib/bcdice/game_system/Warhammer4.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, items) ⇒ CriticalTable

Returns a new instance of CriticalTable.



130
131
132
133
# File 'lib/bcdice/game_system/Warhammer4.rb', line 130

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

Instance Method Details

#roll(randomizer, under_ganken_bonus) ⇒ Object



135
136
137
138
139
140
141
142
143
144
# File 'lib/bcdice/game_system/Warhammer4.rb', line 135

def roll(randomizer, under_ganken_bonus)
  dice = randomizer.roll_once(100)
  if under_ganken_bonus
    dice = (dice - 20).clamp(1, 100)
  end

  chosen = @items.find { |key, _| key >= dice }[1]

  "#{@name}(#{dice}) > #{chosen}"
end