class BCDice::GameSystem::EarthDawn4

Constants

HELP_MESSAGE

ダイスボットの使い方

ID

ゲームシステムの識別子

NAME

ゲームシステム名

SORT_KEY

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

Public Class Methods

new(command) click to toggle source
Calls superclass method BCDice::GameSystem::EarthDawn::new
# File lib/bcdice/game_system/EarthDawn4.rb, line 29
def initialize(command)
  super(command)

  @sort_add_dice = true
  @calcText = ''
end

Public Instance Methods

addStepToResult(result, step) click to toggle source
# File lib/bcdice/game_system/EarthDawn4.rb, line 210
def addStepToResult(result, step)
  result.size.times do |i|
    result[i] += step[i]
  end

  return result
end
ed_step(str) click to toggle source

アースドーンステップ表

# File lib/bcdice/game_system/EarthDawn4.rb, line 41
def ed_step(str)
  output = getStepResult(str)

  return output
end
eval_game_system_specific_command(command) click to toggle source
# File lib/bcdice/game_system/EarthDawn4.rb, line 36
def eval_game_system_specific_command(command)
  return ed_step(command)
end
getBaseStepTable() click to toggle source
# File lib/bcdice/game_system/EarthDawn4.rb, line 145
def getBaseStepTable
  stepTable =
    [
      #      dice
      #      D20  D12  D10  D8  D6  D4  mod
      [1, [0, 0, 0, 0, 0, 1, -2]],
      [2,  [0,   0,   0,  0,  0,  1, -1]],
      [3,  [0,   0,   0,  0,  0,  1,   0]],
      [4,  [0,   0,   0,  0,  1,  0,   0]],
      [5,  [0,   0,   0,  1,  0,  0,   0]],
      [6,  [0,   0,   1,  0,  0,  0,   0]],
      [7,  [0,   1,   0,  0,  0,  0,   0]],
    ]

  return stepTable
end
getModifyText(modify) click to toggle source
# File lib/bcdice/game_system/EarthDawn4.rb, line 136
def getModifyText(modify)
  string = ""
  return string if  modify == 0

  string += "+" if  modify > 0
  string += modify.to_s
  return string
end
getStepInfo(step) click to toggle source
# File lib/bcdice/game_system/EarthDawn4.rb, line 162
def getStepInfo(step)
  baseStepTable = getBaseStepTable
  baseMaxStep = baseStepTable.last.first

  if step <= baseMaxStep
    return get_table_by_number(step, baseStepTable)
  end

  #              dice
  #                D20  D12  D10  D8  D6  D4  mod
  overBounusStep = [1, 0, 0, 0, 0, 0, 0]
  overStep = step - baseMaxStep - 1

  stepRythm =
    [
      # dice
      # D20  D12  D10  D8  D6  D4  mod
      [0, 0, 0, 0, 2, 0, 0],
      [0,   0,   0,  1,  1,  0,   0],
      [0,   0,   0,  2,  0,  0,   0],
      [0,   0,   1,  1,  0,  0,   0],
      [0,   0,   2,  0,  0,  0,   0],
      [0,   1,   1,  0,  0,  0,   0],
      [0,   2,   0,  0,  0,  0,   0],
      [0,   1,   0,  0,  2,  0,   0],
      [0,   1,   0,  1,  1,  0,   0],
      [0,   1,   0,  2,  0,  0,   0],
      [0,   1,   1,  1,  0,  0,   0],
    ]

  # [  1,   0,   0,  0,  2,  0,   0],

  result = [0, 0, 0, 0, 0, 0, 0]

  loopCount = (overStep / stepRythm.size)

  loopCount.times do
    addStepToResult(result, overBounusStep)
  end

  index = (overStep % stepRythm.size)
  restStepInfo = stepRythm[index]

  addStepToResult(result, restStepInfo)

  return result
end
getStepResult(str) click to toggle source
# File lib/bcdice/game_system/EarthDawn4.rb, line 47
def getStepResult(str)
  stepText, calcText, stepTotal, targetNumber = getStepResultInfos(str)

  return nil if stepText.nil?

  if targetNumber == 0
    output = "#{stepText} > #{calcText} > #{stepTotal}"
    return output
  end

  # 結果判定
  successText = getSuccess(targetNumber, stepTotal)

  output = "#{stepText}>=#{targetNumber} > #{calcText} > #{stepTotal} > #{successText}"

  return output
end
getStepResultInfo(str) click to toggle source
# File lib/bcdice/game_system/EarthDawn4.rb, line 101
def getStepResultInfo(str)
  return nil unless /^(\d+)E(\d+)?(K)?(\+\d+$)?(\+(.*))?/i =~ str

  stepTotal = 0
  @isFailed = true

  step = Regexp.last_match(1).to_i # ステップ
  targetNumber = Regexp.last_match(2).to_i # 目標値
  return nil if targetNumber < 0

  hasKarmaDice = !Regexp.last_match(3).nil? # カルマダイスの有無
  diceModify = Regexp.last_match(4).to_i
  nextText = Regexp.last_match(6)

  stepInfo = getStepInfo(step)
  debug('stepInfo', stepInfo)

  @calcText = ""

  diceTypes = [20, 12, 10, 8, 6, 4]
  diceTypes.each do |type|
    stepTotal += rollStep(type, stepInfo.shift)
  end
  modify = stepInfo.shift

  stepTotal += rollStep(6, 1) if hasKarmaDice

  @calcText += (getModifyText(modify) + getModifyText(diceModify))
  stepTotal += (modify + diceModify)

  stepText = "ステップ#{step}"

  return stepText, @calcText, stepTotal, targetNumber, nextText
end
getStepResultInfos(str) click to toggle source
# File lib/bcdice/game_system/EarthDawn4.rb, line 65
def getStepResultInfos(str)
  steps = []
  calcs = []
  totals = []
  target = 0

  while  !str.nil? && !str.empty?

    debug("=====>!! str", str)

    step, calc, total, value, nextText = getStepResultInfo(str)
    debug("=====> step", step)

    return nil if step.nil?

    steps << step
    calcs << calc
    totals << total
    target = value unless value == 0

    debug("=====> nextText", nextText)
    break if nextText == str

    str = nextText
  end

  stepText = steps.join("+")
  calcText = calcs.join(")+(")
  stepTotal = totals.inject { |sum, i| sum + i }

  calcText = "(" + calcText + ")" if calcs.size > 1
  calcText += " > (#{totals.join('+')})" if totals.size > 1

  return stepText, calcText, stepTotal, target
end
getSuccess(targetNumber, stepTotal) click to toggle source
# File lib/bcdice/game_system/EarthDawn4.rb, line 218
def getSuccess(targetNumber, stepTotal)
  return '自動失敗' if @isFailed

  diff = stepTotal - targetNumber
  debug("diff", diff)

  if diff < 0
    return "失敗"
  end

  level = (diff / 5) + 1

  return "成功 レベル:#{level}"
end
rollStep(diceType, diceCount) click to toggle source
# File lib/bcdice/game_system/EarthDawn4.rb, line 233
def rollStep(diceType, diceCount)
  debug('rollStep diceType, diceCount, @calcText', diceType, diceCount, @calcText)

  stepTotal = 0
  return stepTotal unless diceCount > 0

  # diceぶんのステップ判定

  @calcText += "+" unless @calcText.empty?
  @calcText += "#{diceCount}d#{diceType}["
  debug('rollStep string', @calcText)

  diceCount.times do |i|
    dice_now = @randomizer.roll_once(diceType)

    if dice_now != 1
      @isFailed = false
    end

    dice_in = dice_now

    while dice_now == diceType
      dice_now = @randomizer.roll_once(diceType)

      dice_in += dice_now
    end

    stepTotal += dice_in

    @calcText += ',' if i != 0
    @calcText += dice_in.to_s
  end

  @calcText += "]"

  return stepTotal
end