class BCDice::CommonCommand::UpperDice::Node::Dice
Public Class Methods
new(roll_times, sides)
click to toggle source
@param roll_times [Integer] @param sides [Integer]
# File lib/bcdice/common_command/upper_dice/node.rb, line 137 def initialize(roll_times, sides) @roll_times = roll_times @sides = sides end
Public Instance Methods
roll(randomizer, reroll_threshold, sort)
click to toggle source
@param randomizer [BCDice::Randomizer] @param reroll_threshold [Integer] @param sort [Boolean] @return [Array<Hash>]
# 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_s()
click to toggle source
@return [String]
# File lib/bcdice/common_command/upper_dice/node.rb, line 160 def to_s "#{@roll_times}U#{@sides}" end
Private Instance Methods
roll_ones(randomizer, reroll_threshold)
click to toggle source
# File lib/bcdice/common_command/upper_dice/node.rb, line 166 def roll_ones(randomizer, reroll_threshold) dice_list = [] loop do value = randomizer.roll_once(@sides) dice_list.push(value) break if value < reroll_threshold end return dice_list end