Class: BCDice::CommonCommand::AddDice::Randomizer

Inherits:
Object
  • Object
show all
Defined in:
lib/bcdice/common_command/add_dice/randomizer.rb

Defined Under Namespace

Classes: RandResult

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rand_source, game_system) ⇒ Randomizer

Returns a new instance of Randomizer.

Parameters:



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_resultsObject (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>

ダイスを振る

Parameters:

  • times (Integer)

    ダイス数

  • sides (Integer)

    面数

Returns:

  • (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.roll_barabara(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