Class: BCDice::CommonCommand::UpperDice::Node::Dice

Inherits:
Object
  • Object
show all
Defined in:
lib/bcdice/common_command/upper_dice/node.rb

Instance Method Summary collapse

Constructor Details

#initialize(roll_times, sides) ⇒ Dice

Returns a new instance of Dice.

Parameters:

  • roll_times (Integer)
  • sides (Integer)


137
138
139
140
# File 'lib/bcdice/common_command/upper_dice/node.rb', line 137

def initialize(roll_times, sides)
  @roll_times = roll_times
  @sides = sides
end

Instance Method Details

#roll(randomizer, reroll_threshold, sort) ⇒ Array<Hash>

Parameters:

Returns:

  • (Array<Hash>)


146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/bcdice/common_command/upper_dice/node.rb', line 146

def roll(randomizer, reroll_threshold, sort)
  ret = Array.new(@roll_times) do
    list = roll_ones(randomizer, reroll_threshold)
    {sum: list.sum(), list: list}
  end

  if sort
    ret = ret.sort_by { |e| e[:sum] }
  end

  return ret
end

#to_sString

Returns:

  • (String)


160
161
162
# File 'lib/bcdice/common_command/upper_dice/node.rb', line 160

def to_s
  "#{@roll_times}U#{@sides}"
end