Class: BCDice::CommonCommand::AddDice::Randomizer
- Inherits:
-
Object
- Object
- BCDice::CommonCommand::AddDice::Randomizer
- Defined in:
- lib/bcdice/common_command/add_dice/randomizer.rb
Defined Under Namespace
Classes: RandResult
Instance Attribute Summary collapse
-
#rand_results ⇒ Object
readonly
Returns the value of attribute rand_results.
Instance Method Summary collapse
-
#initialize(rand_source, game_system) ⇒ Randomizer
constructor
A new instance of Randomizer.
-
#roll(times, sides) ⇒ Array<Integer>
ダイスを振る.
Constructor Details
#initialize(rand_source, game_system) ⇒ Randomizer
Returns a new instance of Randomizer.
13 14 15 16 17 |
# File 'lib/bcdice/common_command/add_dice/randomizer.rb', line 13 def initialize(rand_source, game_system) @rand_source = rand_source @game_system = game_system @rand_results = [] end |
Instance Attribute Details
#rand_results ⇒ Object (readonly)
Returns the value of attribute rand_results.
7 8 9 |
# File 'lib/bcdice/common_command/add_dice/randomizer.rb', line 7 def rand_results @rand_results end |
Instance Method Details
#roll(times, sides) ⇒ Array<Integer>
ダイスを振る
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/bcdice/common_command/add_dice/randomizer.rb', line 23 def roll(times, sides) dice_list = if sides == 66 Array.new(times) { @rand_source.roll_d66(@game_system.d66_sort_type) } elsif sides == 9 && @game_system.enabled_d9? Array.new(times) { @rand_source.roll_d9() } else @rand_source.(times, sides) end dice_list.sort! if @game_system.sort_add_dice? rand_results = dice_list.map { |value| RandResult.new(sides, value) } @rand_results.concat(rand_results) dice_list end |