class BCDice::GameSystem::Warhammer4

Constants

CRITICAL_TABLES
HELP_MESSAGE

ダイスボットの使い方

HIT_PARTS_TABLE
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/Warhammer4.rb, line 37
def initialize(command)
  super(command)

  @round_type = RoundType::CEIL
end

Public Instance Methods

eval_game_system_specific_command(command) click to toggle source
# File lib/bcdice/game_system/Warhammer4.rb, line 43
def eval_game_system_specific_command(command)
  roll_critical_table(command) || roll_attack(command) || roll_tables(command, TABLES)
end
result_1d100(total, _dice_total, cmp_op, target) click to toggle source
# File lib/bcdice/game_system/Warhammer4.rb, line 47
def result_1d100(total, _dice_total, cmp_op, target)
  return Result.nothing if target == '?'
  return nil unless cmp_op == :<=

  t10 = total / 10
  d10 = target / 10
  sl = d10 - t10

  if total <= 5 && sl < 1
    # 自動成功時のSLは最低でも1
    sl = 1
  elsif total >= 96 && sl > -1
    # 自動失敗時のSLは最大でも-1
    sl = -1
  end

  result =
    if total <= 5
      Result.success("自動成功")
    elsif total >= 96
      Result.failure("自動失敗")
    elsif total <= target
      Result.success("成功")
    else
      Result.failure("失敗")
    end

  sl_text = format("(SL%+d)", sl)
  result.text += "#{sl_text} > #{result_detail(sl, total, target)}"

  return result
end

Private Instance Methods

additional_result(total, target_number) click to toggle source
# File lib/bcdice/game_system/Warhammer4.rb, line 265
def additional_result(total, target_number)
  tens, ones = split_d100(total)
  if (total > target_number) || (total > 95) # 自動失敗時のファンブル処理も
    if ones == tens
      "ファンブル"
    else
      # 一の位と十の位を入れ替えて参照する
      "(#{HIT_PARTS_TABLE.fetch(merge_d100(ones, tens)).content})"
    end
  elsif ones == tens
    "クリティカル"
  else
    # 一の位と十の位を入れ替えて参照する
    HIT_PARTS_TABLE.fetch(merge_d100(ones, tens)).content
  end
end
merge_d100(tens, ones) click to toggle source
# File lib/bcdice/game_system/Warhammer4.rb, line 290
def merge_d100(tens, ones)
  if tens == 0 && ones == 0
    100
  else
    tens * 10 + ones
  end
end
result_detail(sl, total, target) click to toggle source
# File lib/bcdice/game_system/Warhammer4.rb, line 82
def result_detail(sl, total, target)
  if sl == 0
    if total <= 5
      '小成功'
    elsif total >= 96
      '小失敗'
    elsif total <= target
      '小成功'
    else
      '小失敗'
    end
  elsif sl >= 6
    '超大成功'
  elsif sl >= 4
    '大成功'
  elsif sl >= 2
    '成功'
  elsif sl > 0
    '小成功'
  elsif sl >= -1
    '小失敗'
  elsif sl >= -3
    '失敗'
  elsif sl >= -5
    '大失敗'
  else # sl <= -6
    '超大失敗'
  end
end
roll_attack(command) click to toggle source

命中判定

# File lib/bcdice/game_system/Warhammer4.rb, line 247
def roll_attack(command)
  m = /^WH(\d+)$/.match(command)
  return nil unless m

  target_number = m[1].to_i
  total = @randomizer.roll_once(100)
  result = result_1d100(total, total, :<=, target_number)&.text

  sequence = [
    "(#{command})",
    total,
    result,
    additional_result(total, target_number),
  ].compact

  return sequence.join(" > ")
end
roll_critical_table(command) click to toggle source

クリティカル表

# File lib/bcdice/game_system/Warhammer4.rb, line 113
def roll_critical_table(command)
  m = /^WHCT([HABTL])(U)?$/.match(command)
  return nil unless m

  part = m[1]
  part = "B" if part == "T"

  under_ganken_bonus = !m[2].nil?

  CRITICAL_TABLES[part].roll(@randomizer, under_ganken_bonus)
end
split_d100(dice) click to toggle source
# File lib/bcdice/game_system/Warhammer4.rb, line 282
def split_d100(dice)
  if dice == 100
    return 0, 0
  else
    return dice / 10, dice % 10
  end
end