class BCDice::CommonCommand::D66Dice
Constants
- PREFIX_PATTERN
Public Class Methods
eval(command, game_system, randomizer)
click to toggle source
@param command [String] @param game_system [BCDice::Base] @param randomizer [Randomizer] @return [Result, nil]
# File lib/bcdice/common_command/d66_dice.rb, line 13 def eval(command, game_system, randomizer) cmd = parse(command, game_system) cmd&.eval(randomizer) end
new(secret:, sort_type:, suffix:)
click to toggle source
@param secret [Boolean] @param sort_type [Symbol] @param suffix [String, nil]
# File lib/bcdice/common_command/d66_dice.rb, line 48 def initialize(secret:, sort_type:, suffix:) @secret = secret @sort_type = sort_type @suffix = suffix end
Private Class Methods
parse(command, game_system)
click to toggle source
# File lib/bcdice/common_command/d66_dice.rb, line 20 def parse(command, game_system) command = command.split(" ", 2).first m = /^(S)?D66([ANSD])?$/i.match(command) return nil unless m new( secret: !m[1].nil?, sort_type: sort_type_from_suffix(m[2]) || game_system.d66_sort_type, suffix: m[2] ) end
sort_type_from_suffix(suffix)
click to toggle source
# File lib/bcdice/common_command/d66_dice.rb, line 33 def sort_type_from_suffix(suffix) case suffix when "A", "S" D66SortType::ASC when "D" D66SortType::DESC when "N" D66SortType::NO_SORT end end
Public Instance Methods
eval(randomizer)
click to toggle source
@param randomizer [Randomizer] @return [Result]
# File lib/bcdice/common_command/d66_dice.rb, line 56 def eval(randomizer) value = roll(randomizer) Result.new.tap do |r| r.secret = @secret r.text = "(D66#{@suffix}) > #{value}" end end
Private Instance Methods
roll(randomizer)
click to toggle source
# File lib/bcdice/common_command/d66_dice.rb, line 67 def roll(randomizer) dice_list = Array.new(2) { randomizer.roll_once(6) } case @sort_type when D66SortType::ASC dice_list.sort! when D66SortType::DESC dice_list.sort!.reverse! end return dice_list[0] * 10 + dice_list[1] end