class BCDice::GameSystem::SRS

Constants

DEFAULT_CRITICAL_VALUE

既定のクリティカル値

DEFAULT_FUMBLE_VALUE

既定のファンブル値

DEFAULT_HELP_MESSAGE

既定のダイスボット説明文

HELP_MESSAGE
HELP_MESSAGE_1
HELP_MESSAGE_2
HELP_MESSAGE_3
ID

ゲームシステムの識別子

NAME

ゲームシステム名

SORT_KEY

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

SRSRollNode

成功判定コマンドのノード

SRS_ROLL_DEFAULT_THRESHOLDS

既定の閾値指定表記

SRS_ROLL_WITHOUT_TARGET_VALUE_RE

目標値なし成功判定の正規表現

SRS_ROLL_WITH_TARGET_VALUE_RE

目標値あり成功判定の正規表現

Public Class Methods

aliases_re_for_srs_roll_with_target_value() click to toggle source

目標値あり成功判定のエイリアスコマンドの正規表現を返す @return [nil]

# File lib/bcdice/game_system/SRS.rb, line 158
def aliases_re_for_srs_roll_with_target_value
  nil
end
aliases_re_for_srs_roll_without_target_value() click to toggle source

目標値なし成功判定のエイリアスコマンドの正規表現を返す @return [nil]

# File lib/bcdice/game_system/SRS.rb, line 164
def aliases_re_for_srs_roll_without_target_value
  nil
end
help_message() click to toggle source

ダイスボットの説明文を返す @return [String] 既定のダイスボット説明文

# File lib/bcdice/game_system/SRS.rb, line 152
def help_message
  DEFAULT_HELP_MESSAGE
end
inherited(subclass) click to toggle source

クラスが継承されたときに行う処理 @return [void]

# File lib/bcdice/game_system/SRS.rb, line 144
def inherited(subclass)
  subclass
    .extend(ClassMethods)
    .clear_aliases_for_srs_roll
end
new(command) click to toggle source

ダイスボットを初期化する

Calls superclass method BCDice::Base::new
# File lib/bcdice/game_system/SRS.rb, line 173
def initialize(command)
  super(command)

  # 式、出目ともに送信する

  # バラバラロール(Bコマンド)でソートする
  @sort_add_dice = true
  # D66ダイスあり(出目をソートしない)
  @d66_sort_type = D66SortType::NO_SORT
end

Public Instance Methods

eval_game_system_specific_command(command) click to toggle source

固有のダイスロールコマンドを実行する @param [String] command 入力されたコマンド @return [Result, nil] ダイスロールコマンドの実行結果

# File lib/bcdice/game_system/SRS.rb, line 223
def eval_game_system_specific_command(command)
  alias_replaced_with_2d6 = replace_alias_for_srs_roll_with_2d6(command)

  if (node = parse(alias_replaced_with_2d6))
    return execute_srs_roll(node)
  end

  return nil
end
help_message() click to toggle source

ダイスボットの説明文を返す @return [String]

# File lib/bcdice/game_system/SRS.rb, line 186
def help_message
  self.class.help_message
end

Private Instance Methods

compare_result(srs_roll, sum, modified_sum) click to toggle source

ダイスロール結果を目標値、クリティカル値、ファンブル値と比較する @param [SRSRollNode] srs_roll 成功判定ノード @param [Integer] sum 出目の合計 @param [Integer] modified_sum 修正後の値 @return [Result] 比較結果

# File lib/bcdice/game_system/SRS.rb, line 328
def compare_result(srs_roll, sum, modified_sum)
  if sum >= srs_roll.critical_value
    Result.critical("自動成功")
  elsif sum <= srs_roll.fumble_value
    Result.fumble("自動失敗")
  elsif srs_roll.target_value.nil?
    Result.new
  elsif modified_sum >= srs_roll.target_value
    Result.success("成功")
  else
    Result.failure("失敗")
  end
end
eval_modifier(modifier_str) click to toggle source

修正値を評価する @param [String, nil] modifier_str 修正値部分の文字列 @return [Integer] 修正値

# File lib/bcdice/game_system/SRS.rb, line 269
def eval_modifier(modifier_str)
  return 0 unless modifier_str

  return ArithmeticEvaluator.eval(modifier_str, round_type: @round_type)
end
execute_srs_roll(srs_roll) click to toggle source

成功判定を実行する @param [SRSRollNode] srs_roll 成功判定ノード @return [Result] 成功判定結果

# File lib/bcdice/game_system/SRS.rb, line 301
def execute_srs_roll(srs_roll)
  dice_list = @randomizer.roll_barabara(2, 6)
  dice_list.sort! if @sort_add_dice

  sum = dice_list.sum()
  dice_str = dice_list.join(",")

  modified_sum = sum + srs_roll.modifier

  result = compare_result(srs_roll, sum, modified_sum)

  parts = [
    "(#{srs_roll})",
    "#{sum}[#{dice_str}]#{Format.modifier(srs_roll.modifier)}",
    modified_sum,
    result.text
  ]

  result.text = parts.compact.join(' > ')
  result
end
parse(command) click to toggle source

構文解析する @param [String] command コマンド文字列 @return [SRSRollNode, nil]

# File lib/bcdice/game_system/SRS.rb, line 255
def parse(command)
  case command
  when SRS_ROLL_WITH_TARGET_VALUE_RE
    return parse_srs_roll_with_target_value(Regexp.last_match)
  when SRS_ROLL_WITHOUT_TARGET_VALUE_RE
    return parse_srs_roll_without_target_value(Regexp.last_match)
  else
    return nil
  end
end
parse_srs_roll_with_target_value(m) click to toggle source

目標値あり成功判定の正規表現マッチ情報からノードを作る @param [MatchData] m 正規表現のマッチ情報 @return [SRSRollNode]

# File lib/bcdice/game_system/SRS.rb, line 278
def parse_srs_roll_with_target_value(m)
  modifier = eval_modifier(m[1])
  target_value = m[2].to_i
  critical_value = m[3]&.to_i || DEFAULT_CRITICAL_VALUE
  fumble_value = m[4]&.to_i || DEFAULT_FUMBLE_VALUE

  return SRSRollNode.new(modifier, critical_value, fumble_value, target_value)
end
parse_srs_roll_without_target_value(m) click to toggle source

目標値なし成功判定の正規表現マッチ情報からノードを作る @param [MatchData] m 正規表現のマッチ情報 @return [SRSRollNode]

# File lib/bcdice/game_system/SRS.rb, line 290
def parse_srs_roll_without_target_value(m)
  modifier = eval_modifier(m[1])
  critical_value = m[2]&.to_i || DEFAULT_CRITICAL_VALUE
  fumble_value = m[3]&.to_i || DEFAULT_FUMBLE_VALUE

  return SRSRollNode.new(modifier, critical_value, fumble_value, nil)
end
replace_alias_for_srs_roll_with_2d6(input) click to toggle source

成功判定のエイリアスコマンドを2D6に置換する @param [String] input 入力文字列 @return [String]

# File lib/bcdice/game_system/SRS.rb, line 238
def replace_alias_for_srs_roll_with_2d6(input)
  case input
  when self.class.aliases_re_for_srs_roll_with_target_value
    return "2D6#{Regexp.last_match(1)}"
  when self.class.aliases_re_for_srs_roll_without_target_value
    modifier = Regexp.last_match(1)
    thresholds = Regexp.last_match(2) || SRS_ROLL_DEFAULT_THRESHOLDS

    return "2D6#{modifier}#{thresholds}"
  else
    return input
  end
end