class BCDice::GameSystem::Cthulhu

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/Cthulhu.rb, line 53
def initialize(command)
  super(command)
  @special_percentage  = 20
  @critical_percentage = 1
  @fumble_percentage   = 1
end

Public Instance Methods

eval_game_system_specific_command(command) click to toggle source
# File lib/bcdice/game_system/Cthulhu.rb, line 60
def eval_game_system_specific_command(command)
  case command
  when /CCB/i
    # 5%
    @critical_percentage = 5
    @fumble_percentage   = 5
    return getCheckResult(command)
  when /CC/i
    # 1%
    @critical_percentage = 1
    @fumble_percentage   = 1
    return getCheckResult(command)
  when /RESB/i
    # 5%
    @critical_percentage = 5
    @fumble_percentage   = 5
    return getRegistResult(command)
  when /CBRB/i
    # 5%
    @critical_percentage = 5
    @fumble_percentage   = 5
    return getCombineRoll(command)
  when /RES/i
    # 1%
    @critical_percentage = 1
    @fumble_percentage   = 1
    return getRegistResult(command)
  when /CBR/i
    # 1%
    @critical_percentage = 1
    @fumble_percentage   = 1
    return getCombineRoll(command)
  end

  return nil
end

Private Instance Methods

compare(total, target, broken_number = 0) click to toggle source
# File lib/bcdice/game_system/Cthulhu.rb, line 171
def compare(total, target, broken_number = 0)
  result = CompareResult.new(@locale)
  target_special = (target * @special_percentage / 100).clamp(1, 100)

  if (total <= target) && (total < 100)
    result.success = true
    result.special = total <= target_special
    result.critical = total <= @critical_percentage
  else
    result.failure = true
    result.fumble = total >= (101 - @fumble_percentage)
  end

  if broken_number > 0 && total >= broken_number
    result.broken = true
    result.failure = true
    result.success = false
    result.special = false
    result.critical = false
  end

  return result
end
getCheckResult(command) click to toggle source
# File lib/bcdice/game_system/Cthulhu.rb, line 99
def getCheckResult(command)
  m = %r{^CCB?(\d+)?(?:<=([+-/*\d]+))?$}i.match(command)
  unless m
    return nil
  end

  broken_num = m[1].to_i
  diff = ArithmeticEvaluator.eval(m[2])

  if diff <= 0
    total = @randomizer.roll_once(100)
    return Result.new("(1D100) > #{total}")
  end

  expr = "(1D100<=#{diff})"
  if broken_num > 0
    expr += " #{translate('Cthulhu.broken_number')}[#{broken_num}]"
  end

  total = @randomizer.roll_once(100)
  compare_result = compare(total, diff, broken_num)

  compare_result.to_result.tap do |r|
    r.text = "#{expr} > #{total} > #{compare_result.text}"
  end
end
getCombineRoll(command) click to toggle source
# File lib/bcdice/game_system/Cthulhu.rb, line 221
def getCombineRoll(command)
  m = /^CBR(B)?\((\d+),(\d+)\)$/i.match(command)
  unless m
    return nil
  end

  diff_1 = m[2].to_i
  diff_2 = m[3].to_i

  total = @randomizer.roll_once(100)

  result_1 = compare(total, diff_1)
  result_2 = compare(total, diff_2)

  rank =
    if result_1.success && result_2.success
      translate("success")
    elsif result_1.success || result_2.success
      translate("Cthulhu.partial_success")
    else
      translate("failure")
    end

  Result.new.tap do |r|
    r.text = "(1d100<=#{diff_1},#{diff_2}) > #{total}[#{result_1.text},#{result_2.text}] > #{rank}"
    r.critical = result_1.critical || result_2.critical
    r.fumble = result_1.fumble || result_2.fumble
    r.condition = result_1.success || result_2.success
  end
end
getRegistResult(command) click to toggle source
# File lib/bcdice/game_system/Cthulhu.rb, line 195
def getRegistResult(command)
  m = /^RES(B)?([-\d]+)$/i.match(command)
  unless m
    return nil
  end

  value = m[2].to_i
  target = value * 5 + 50

  if target < 5
    return Result.failure("(1d100<=#{target}) > #{translate('Cthulhu.automatic_failure')}")
  end

  if target > 95
    return Result.success("(1d100<=#{target}) > #{translate('Cthulhu.automatic_success')}")
  end

  # 通常判定
  total_n = @randomizer.roll_once(100)
  compare_result = compare(total_n, target)

  compare_result.to_result.tap do |r|
    r.text = "(1d100<=#{target}) > #{total_n} > #{compare_result.text}"
  end
end