class BCDice::GameSystem::RecordOfSteam

Constants

HELP_MESSAGE

ダイスボットの使い方

ID

ゲームシステムの識別子

NAME

ゲームシステム名

SORT_KEY

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

Public Instance Methods

eval_game_system_specific_command(command) click to toggle source

サンプルのダイスコマンドは「nSt@c」で n=ダイス個数, t=目標値, c=クリティカル値。@cのみ省略可

# File lib/bcdice/game_system/RecordOfSteam.rb, line 28
def eval_game_system_specific_command(command)
  unless /(\d+)[sS](\d+)(@(\d+))?/i =~ command
    return "1"
  end

  # $x の結果は正規表現マッチングすると新しい値に書き換わってしまうので、
  # マッチングした直後に変数に格納してしまうのが大事なポイント!
  diceCount = Regexp.last_match(1).to_i
  targetNumber = Regexp.last_match(2).to_i
  criticalValue = Regexp.last_match(4)
  criticalValue ||= 1
  criticalValue = criticalValue.to_i

  if diceCount >= 150
    return "(多分)無限個なので振れません! ヤメテクダサイ、(プロセスが)死んでしまいますっ"
  end

  if criticalValue >= 3
    return "(多分)無限個なので振れません! ヤメテクダサイ、(プロセスが)死んでしまいますっ"
  end

  specialValue = criticalValue

  rollResult, successCount, roundCount, specialCount, fumbleCount = getDiceRollResult(diceCount, targetNumber, criticalValue, specialValue)

  output = "(#{command}) > #{rollResult}"

  roundCountText = getRoundCountText(roundCount)
  successText = getSuccessText(successCount)
  specialText = getSpecialText(specialCount)
  fumbleText = getFumbleText(fumbleCount)

  result = "#{output}#{roundCountText}#{specialText}#{successText}#{fumbleText}"

  return result
end
getDiceRollResult(diceCount, targetNumber, criticalValue, specialValue) click to toggle source
# File lib/bcdice/game_system/RecordOfSteam.rb, line 65
def getDiceRollResult(diceCount, targetNumber, criticalValue, specialValue)
  successCount = 0
  roundCount = 0
  rollResult = ""
  specialCount = 0
  specialFlag = false
  fumbleCount = 0
  fumbleFlag = false

  while diceCount > 0
    diceList = @randomizer.roll_barabara(diceCount, 6)
    diceListText = diceList.join(",")

    rollResult += "," if rollResult != ""
    rollResult += diceListText

    if diceList.uniq.length == 1 && roundCount == 0
      if diceList.uniq.first <= specialValue
        specialFlag = true
      elsif diceList.uniq.first == 6
        fumbleFlag = true
      end
    end
    debug("diceList", diceList)

    if specialFlag
      specialCount = 1
      successCount = diceCount * 3

      return rollResult, successCount, roundCount, specialCount, fumbleCount
    elsif fumbleFlag
      fumbleCount = 1

      return rollResult, successCount, roundCount, specialCount, fumbleCount
    end

    diceCount = 0

    diceList.map do |diceValue|
      debug("diceValue", diceValue)
      debug("criticalValue", criticalValue)
      debug("specialValue", specialValue)

      if diceValue <= criticalValue
        diceCount += 2
        roundCount += 1
      end

      successCount += 1 if diceValue <= targetNumber
    end
  end

  return rollResult, successCount, roundCount, specialCount, fumbleCount
end
getFumbleText(fumbleCount) click to toggle source
# File lib/bcdice/game_system/RecordOfSteam.rb, line 142
def getFumbleText(fumbleCount)
  if fumbleCount == 1
    return " > ファンブル"
  end
end
getRoundCountText(roundCount) click to toggle source
# File lib/bcdice/game_system/RecordOfSteam.rb, line 120
def getRoundCountText(roundCount)
  if  roundCount <= 0
    return ""
  end

  return " > #{roundCount}回転"
end
getSpecialText(specialCount) click to toggle source
# File lib/bcdice/game_system/RecordOfSteam.rb, line 136
def getSpecialText(specialCount)
  if specialCount == 1
    return " > スペシャル"
  end
end
getSuccessText(successCount) click to toggle source
# File lib/bcdice/game_system/RecordOfSteam.rb, line 128
def getSuccessText(successCount)
  if successCount > 0
    return " > 成功数#{successCount}"
  end

  return " > 失敗"
end