class BCDice::GameSystem::SamsaraBallad

Constants

HELP_MESSAGE

ダイスボットの使い方

ID

ゲームシステムの識別子

NAME

ゲームシステム名

SORT_KEY

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

「ゲームシステム名の読みがなの設定方法」(docs/dicebot_sort_key.md)を参考にして 設定してください

Public Instance Methods

eval_game_system_specific_command(command) click to toggle source
# File lib/bcdice/game_system/SamsaraBallad.rb, line 38
def eval_game_system_specific_command(command)
  debug("eval_game_system_specific_command Begin")

  parser = Command::Parser.new('SBS', 'SB', round_type: round_type)
                          .enable_critical
                          .enable_fumble
                          .restrict_cmp_op_to(nil, :<=, :<)
  cmd = parser.parse(command)

  unless cmd
    return nil
  end

  if cmd.command == 'SB'
    places_text = nil
    total = @randomizer.roll_once(100)
  else
    a = @randomizer.roll_once(10)
    b = @randomizer.roll_once(10)
    places_text = "#{a},#{b}"
    places = [a, b].map { |n| n == 10 ? 0 : n }.sort

    total = places[0] * 10 + places[1]
    total = 100 if total == 0
  end

  result = compare(total, cmd)

  result_str =
    if result.failure?
      "失敗"
    elsif result.success?
      "成功"
    end

  additional_str =
    if result.fumble?
      "ファンブル"
    elsif result.critical?
      "クリティカル"
    end

  sequence = [
    "(D100#{cmd.cmp_op}#{cmd.target_number})",
    places_text,
    total.to_s,
    result_str,
    additional_str,
  ].compact

  result.text = sequence.join(" > ")

  return result
end

Private Instance Methods

compare(total, cmd) click to toggle source

@return [Result]

# File lib/bcdice/game_system/SamsaraBallad.rb, line 96
def compare(total, cmd)
  if [:<=, :<].include?(cmd.cmp_op)
    if !total.send(cmd.cmp_op, cmd.target_number)
      Result.failure(nil)
    elsif fumble_?(total, cmd.fumble)
      Result.new.tap do |r|
        r.success = true
        r.fumble = true
      end
    elsif critical_?(total, cmd.critical)
      Result.critical(nil)
    else
      Result.success(nil)
    end
  elsif fumble_?(total, cmd.fumble)
    # ファンブル優先
    Result.new.tap do |r|
      r.fumble = true
    end
  elsif critical_?(total, cmd.critical)
    Result.new.tap do |r|
      r.critical = true
    end
  else
    Result.new
  end
end
critical_?(total, critical) click to toggle source

@param total [Integer] @param critical [Integer, nil] @return [Boolean]

# File lib/bcdice/game_system/SamsaraBallad.rb, line 134
def critical_?(total, critical)
  critical && (total % 10 >= critical)
end
fumble_?(total, fumble) click to toggle source

@param total [Integer] @param fumble [Integer, nil] @return [Boolean]

# File lib/bcdice/game_system/SamsaraBallad.rb, line 127
def fumble_?(total, fumble)
  fumble && (total % 10 <= fumble)
end