class BCDice::GameSystem::HatsuneMiku

Constants

HELP_MESSAGE

ダイスボットの使い方

ID

ゲームシステムの識別子

NAME

ゲームシステム名

SORT_KEY

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

TABLES

Public Class Methods

new(command) click to toggle source
Calls superclass method BCDice::Base::new
# File lib/bcdice/game_system/HatsuneMiku.rb, line 40
def initialize(command)
  super(command)

  @d66_sort_type = D66SortType::ASC
end

Public Instance Methods

check_success(total_n, dice_n, signOfInequality, diff, special_n) click to toggle source
# File lib/bcdice/game_system/HatsuneMiku.rb, line 128
def check_success(total_n, dice_n, signOfInequality, diff, special_n)
  return "ファンブル" if  dice_n == 1
  return "スペシャル" if  dice_n >= special_n

  cmp_op = Normalize.comparison_operator(signOfInequality)
  target_num = diff.to_i

  if total_n.send(cmp_op, target_num)
    "成功"
  else
    "失敗"
  end
end
eval_game_system_specific_command(command) click to toggle source
# File lib/bcdice/game_system/HatsuneMiku.rb, line 46
def eval_game_system_specific_command(command)
  text = judgeRoll(command)
  return text unless text.nil?

  return roll_tables(command, TABLES)
end
getChangedModifyText(text) click to toggle source
# File lib/bcdice/game_system/HatsuneMiku.rb, line 110
def getChangedModifyText(text)
  modifyText = ""
  values = text.split(/,/)

  values.each do |value|
    case value
    when "++"
      modifyText += "+2"
    when "+"
      modifyText += "+1"
    else
      modifyText += value
    end
  end

  return modifyText
end
judgeRoll(command) click to toggle source
# File lib/bcdice/game_system/HatsuneMiku.rb, line 53
def judgeRoll(command)
  return nil unless /^(R([A-DS]|\d+)([+\-\d,]*))(@(\d))?((>(=)?)([+\-\d]*))?(@(\d))?$/i =~ command

  skillRank = Regexp.last_match(2)
  modifyText = Regexp.last_match(3)
  signOfInequality = (Regexp.last_match(7).nil? ? ">=" : Regexp.last_match(7))
  targetText = (Regexp.last_match(9).nil? ? "4" : Regexp.last_match(9))

  specialNum = Regexp.last_match(5)
  specialNum ||= Regexp.last_match(11)
  specialNum ||= 6
  specialNum = specialNum.to_i
  specialText = (specialNum == 6 ? "" : "@#{specialNum}")

  modifyText = getChangedModifyText(modifyText)

  commandText = "R#{skillRank}#{modifyText}"

  rankDiceList = {"S" => 4, "A" => 3, "B" => 2, "C" => 1, "D" => 2}
  diceCount = rankDiceList[skillRank]
  diceCount = skillRank.to_i if skillRank =~ /^\d+$/

  modify = ArithmeticEvaluator.eval(modifyText)
  target = ArithmeticEvaluator.eval(targetText)

  diceList = @randomizer.roll_barabara(diceCount, 6).sort
  diceText = diceList.join(",")

  diceList = [diceList.min] if skillRank == "D"

  message = "(#{commandText}#{specialText}#{signOfInequality}#{targetText}) > [#{diceText}]#{modifyText} > "

  if diceList.length <= 1
    dice = diceList.first
    total = dice + modify
    result = check_success(total, dice, signOfInequality, target, specialNum)
    message += "#{total}:#{result}"
  else
    texts = []
    diceList.each_with_index do |pickup_dice, index|
      rests = diceList.clone
      rests.delete_at(index)
      dice = rests.max
      total = dice + modify
      result = check_success(total, dice, signOfInequality, target, specialNum)

      colorList = ["黒", "赤", "青", "緑", "白", "任意"]
      color = colorList[pickup_dice - 1]
      texts << " ネイロに#{pickup_dice}(#{color})を取得した場合 #{total}:#{result}"
    end
    texts.uniq!
    message += "\n" + texts.join("\n")
  end

  return message
end