class BCDice::GameSystem::Ryutama

Constants

HELP_MESSAGE

ダイスボットの使い方

ID

ゲームシステムの識別子

NAME

ゲームシステム名

SORT_KEY

ゲームシステム名の読みがな

Public Class Methods

new(command) click to toggle source
Calls superclass method BCDice::Base::new
# File lib/bcdice/game_system/Ryutama.rb, line 26
def initialize(command)
  super(command)
  @validDiceTypes = [20, 12, 10, 8, 6, 4, 2]
end

Public Instance Methods

eval_game_system_specific_command(command) click to toggle source
# File lib/bcdice/game_system/Ryutama.rb, line 31
def eval_game_system_specific_command(command)
  debug('eval_game_system_specific_command begin')

  unless command =~ /^R(\d+)(,(\d+))?([+\-\d]+)?(>=(\d+))?/
    debug('unmatched!')
    return ''
  end
  debug('matched')

  dice1 = Regexp.last_match(1).to_i
  dice2 = Regexp.last_match(3).to_i
  modifyString = Regexp.last_match(4)
  difficulty = Regexp.last_match(6)

  dice1, dice2 = getDiceType(dice1, dice2)
  if dice1 == 0
    return ''
  end

  modifyString ||= ''
  modify = ArithmeticEvaluator.eval(modifyString)
  difficulty = getDiffculty(difficulty)

  value1 = getRollValue(dice1)
  value2 = getRollValue(dice2)
  total = value1 + value2 + modify

  result = getResultText(value1, value2, dice1, dice2, difficulty, total)
  unless result.empty?
    result = " > #{result}"
  end

  value1Text = "#{value1}(#{dice1})"
  value2Text = (value2 == 0 ? "" : "+#{value2}(#{dice2})")
  modifyText = getModifyString(modify)

  baseText = getBaseText(dice1, dice2, modify, difficulty)
  output = "(#{baseText}) > #{value1Text}#{value2Text}#{modifyText} > #{total}#{result}"
  return output
end
getBaseText(dice1, dice2, modify, difficulty) click to toggle source
# File lib/bcdice/game_system/Ryutama.rb, line 172
def getBaseText(dice1, dice2, modify, difficulty)
  baseText = "R#{dice1}"

  if dice2 != 0
    baseText += ",#{dice2}"
  end

  baseText += getModifyString(modify)

  unless difficulty.nil?
    baseText += ">=#{difficulty}"
  end

  return baseText
end
getDiceType(dice1, dice2) click to toggle source
# File lib/bcdice/game_system/Ryutama.rb, line 72
def getDiceType(dice1, dice2)
  debug('getDiceType begin')

  if dice2 != 0
    if isValidDiceOne(dice1)
      return dice1, dice2
    else
      return 0, 0
    end
  end

  if isValidDice(dice1, dice2)
    return dice1, dice2
  end

  diceBase = dice1

  dice1 = diceBase / 10
  dice2 = diceBase % 10

  if isValidDice(dice1, dice2)
    return dice1, dice2
  end

  dice1 = diceBase / 100
  dice2 = diceBase % 100

  if isValidDice(dice1, dice2)
    return dice1, dice2
  end

  if isValidDiceOne(diceBase)
    return diceBase, 0
  end

  return 0, 0
end
getDiffculty(difficulty) click to toggle source
# File lib/bcdice/game_system/Ryutama.rb, line 119
def getDiffculty(difficulty)
  unless difficulty.nil?
    difficulty = difficulty.to_i
  end

  return difficulty
end
getModifyString(modify) click to toggle source
# File lib/bcdice/game_system/Ryutama.rb, line 188
def getModifyString(modify)
  if modify > 0
    return "+" + modify.to_s
  elsif modify < 0
    return modify.to_s
  end

  return ''
end
getResultText(value1, value2, dice1, dice2, difficulty, total) click to toggle source
# File lib/bcdice/game_system/Ryutama.rb, line 134
def getResultText(value1, value2, dice1, dice2, difficulty, total)
  if isFamble(value1, value2)
    return "1ゾロ【1ゾロポイント+1】"
  end

  if isCritical(value1, value2, dice1, dice2)
    return "クリティカル成功"
  end

  if difficulty.nil?
    return ''
  end

  if  total >= difficulty
    return "成功"
  end

  return "失敗"
end
getRollValue(dice) click to toggle source
# File lib/bcdice/game_system/Ryutama.rb, line 127
def getRollValue(dice)
  return 0 if dice == 0

  value = @randomizer.roll_once(dice)
  return value
end
isCritical(value1, value2, dice1, dice2) click to toggle source
# File lib/bcdice/game_system/Ryutama.rb, line 158
def isCritical(value1, value2, dice1, dice2)
  return false if value2 == 0

  if (value1 == 6) && (value2 == 6)
    return true
  end

  if (value1 == dice1) && (value2 == dice2)
    return true
  end

  return false
end
isFamble(value1, value2) click to toggle source
# File lib/bcdice/game_system/Ryutama.rb, line 154
def isFamble(value1, value2)
  return ((value1 == 1) && (value2 == 1))
end
isValidDice(dice1, dice2) click to toggle source
# File lib/bcdice/game_system/Ryutama.rb, line 110
def isValidDice(dice1, dice2)
  return (isValidDiceOne(dice1) &&
           isValidDiceOne(dice2))
end
isValidDiceOne(dice) click to toggle source
# File lib/bcdice/game_system/Ryutama.rb, line 115
def isValidDiceOne(dice)
  @validDiceTypes.include?(dice)
end