class BCDice::GameSystem::Nechronica

Constants

HELP_MESSAGE

ダイスボットの使い方

ID

ゲームシステムの識別子

NAME

ゲームシステム名

SORT_KEY

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

TABLES

Public Class Methods

new(command) click to toggle source
Calls superclass method BCDice::Base::new
# File lib/bcdice/game_system/Nechronica.rb, line 32
def initialize(command)
  super(command)

  @sort_add_dice = true
  @sort_barabara_dice = true
  @default_target_number = 6 # 目標値が空欄の時の目標値
end

Private Class Methods

translate_tables(locale) click to toggle source
# File lib/bcdice/game_system/Nechronica.rb, line 131
def translate_tables(locale)
  {
    "NM" => DiceTable::Table.from_i18n("Nechronica.table.NM", locale),
    "NMN" => DiceTable::Table.from_i18n("Nechronica.table.NMN", locale),
    "NME" => DiceTable::Table.from_i18n("Nechronica.table.NME", locale),
  }
end

Public Instance Methods

eval_game_system_specific_command(command) click to toggle source
# File lib/bcdice/game_system/Nechronica.rb, line 40
def eval_game_system_specific_command(command)
  roll_tables(command, self.class::TABLES) || nechronica_check(command)
end
result_nd10(total, _dice_total, value_list, cmp_op, target) click to toggle source
# File lib/bcdice/game_system/Nechronica.rb, line 44
def result_nd10(total, _dice_total, value_list, cmp_op, target)
  # 後方互換を維持するため、1d10>=nを目標値nの1NCとして処理
  if value_list.count != 1 || cmp_op != :>= || target.nil? || target == "?"
    return nil
  end

  result_nechronica([total], target)
end

Private Instance Methods

get_hit_location(value) click to toggle source
# File lib/bcdice/game_system/Nechronica.rb, line 115
def get_hit_location(value)
  return nil if value <= 5

  table = translate("Nechronica.hit_location.table")
  text = table[(value - 6).clamp(0, 5)]

  if value > 10
    text + translate("Nechronica.hit_location.additional_damage", damage: value - 10)
  else
    text
  end
end
nechronica_check(command) click to toggle source
# File lib/bcdice/game_system/Nechronica.rb, line 85
def nechronica_check(command)
  command = r_backward_compatibility(command)
  # 歴史的経緯で10を受理する
  cmd = Command::Parser.new(/N[CA](10)?/, round_type: round_type)
                       .enable_prefix_number.parse(command)
  return nil unless cmd

  dice_count = [1, cmd.prefix_number.to_i].max
  modify_number = cmd.modify_number || 0

  dice = @randomizer.roll_barabara(dice_count, 10).sort
  dice_mod = dice.map { |i| i + modify_number }
  total = dice_mod.max

  na = get_hit_location(total) if cmd.command.start_with?("NA")

  result = result_nechronica(dice_mod, 6)

  sequence = [
    "(#{cmd})",
    "[#{dice.join(',')}]#{Format.modifier(modify_number)}",
    "#{total}[#{dice_mod.join(',')}]",
    result.text,
    na,
  ].compact

  result.text = sequence.join(" > ")
  return result
end
r_backward_compatibility(command) click to toggle source

Rコマンドの後方互換を維持する

# File lib/bcdice/game_system/Nechronica.rb, line 74
def r_backward_compatibility(command)
  m = command.match(/^(\d)?R10([+\-\d]+)?(\[(\d+)\])?$/)
  return command unless m

  if m[4] == "1"
    "#{m[1]}NA#{m[2]}"
  else
    "#{m[1]}NC#{m[2]}"
  end
end
result_nechronica(value_list, target) click to toggle source
# File lib/bcdice/game_system/Nechronica.rb, line 55
def result_nechronica(value_list, target)
  if value_list.max >= target
    if value_list.max >= 11
      Result.critical(translate("Nechronica.critical"))
    else
      Result.success(translate("success"))
    end
  elsif value_list.count { |i| i <= 1 } == 0
    Result.failure(translate("failure"))
  elsif value_list.size > 1
    break_all_parts = translate("Nechronica.break_all_parts")
    fumble = translate("Nechronica.fumble")
    Result.fumble("#{fumble} > #{break_all_parts}")
  else
    Result.fumble(translate("Nechronica.fumble"))
  end
end