class BCDice::GameSystem::Yggdrasill

Constants

HELP_MESSAGE
ID
NAME
PSY_TABLE
RA110
RA50
RA70
RA90
SORT_KEY
TABLES

Public Instance Methods

eval_game_system_specific_command(command) click to toggle source
# File lib/bcdice/game_system/Yggdrasill.rb, line 60
def eval_game_system_specific_command(command)
  roll_tables(command, TABLES) ||
    roll_cf(command) ||
    roll_ra(command) ||
    roll_treat(command) ||
    roll_down(command) ||
    roll_cond(command) ||
    roll_guki(command) ||
    roll_cont(command) ||
    roll_allr(command) ||
    roll_pafe(command)
end

Private Instance Methods

count_critical(dice_list, lucky_state) click to toggle source
# File lib/bcdice/game_system/Yggdrasill.rb, line 133
def count_critical(dice_list, lucky_state)
  threshold =
    if lucky_state == "G"
      4
    elsif lucky_state
      5
    else
      6
    end

  dice_list.count { |x| x >= threshold }
end
count_fumble(dice_list, lucky_state) click to toggle source
# File lib/bcdice/game_system/Yggdrasill.rb, line 146
def count_fumble(dice_list, lucky_state)
  threshold =
    if lucky_state == "G"
      3
    elsif lucky_state
      2
    else
      1
    end

  dice_list.count { |x| x <= threshold }
end
roll_allr(command) click to toggle source
# File lib/bcdice/game_system/Yggdrasill.rb, line 268
def roll_allr(command)
  return nil unless command == 'ALLR'

  dice = @randomizer.roll_once(6)
  text =
    if dice == 1
      "発動失敗【技対象が敵味方含めた全員となる】"
    else
      "発動成功"
    end

  "オールレンジ判定 > #{dice} > #{text}"
end
roll_cf(command) click to toggle source
# File lib/bcdice/game_system/Yggdrasill.rb, line 75
def roll_cf(command)
  # マイナス補正にダイスロールを用いることはシステム上ありえないため、正規表現ではじく
  m = /^(H)?CF([LG])?(T)?((?:[+-]*\d+|\+?\d+D\d+)(?:[+-]+\d+|\++\d+D\d+)*)$/.match(command)
  return nil unless m

  hoge = !m[1].nil?
  lucky_state = m[2]
  treat_flg = !m[3].nil?

  expr = m[4]

  node = CommonCommand::AddDice::Parser.parse(expr)
  return nil unless node

  add_dice_randomizer = CommonCommand::AddDice::Randomizer.new(@randomizer, self)
  total = node.lhs.eval(self, add_dice_randomizer)
  rand_values = add_dice_randomizer.rand_results.map(&:value)

  n1 = count_fumble(rand_values, lucky_state)
  n_max = count_critical(rand_values, lucky_state)

  # ファンブルロール
  fa_list = @randomizer.roll_barabara(n1, 6)
  fa1 = fa_list.sum
  fa2 = fa_list.join(",")

  critical_rerolls = []
  rerolls = n_max
  while rerolls > 0
    list = @randomizer.roll_barabara(rerolls, 6)
    critical_rerolls.push(list)

    rerolls = list.count(6)
  end
  # crの達成値を合計する・cr出目を見易く
  cr1 = critical_rerolls.flatten.sum
  cr2 = critical_rerolls.map { |x| "[#{x.join(',')}]" }.join()

  # 修正値&一投目出目 -ファンブル +クリティカル
  total_n = total - fa1 + cr1
  total_n /= 2 if hoge == true
  # 最終達成値
  result = "計【 #{total_n} 】"

  text = "(#{command}) > #{result} : #{node.lhs.output}"
  # クリファン有無に応じて表示の追加
  text += " (fa:#{n1})-#{fa1}[#{fa2}]" if n1 > 0
  text += " (cr:#{n_max})+#{cr1}#{cr2} (cr:計#{critical_rerolls.flatten.size}回)" if cr1 > 0

  if treat_flg == true
    # TREAT追加処理
    heal = eval_game_system_specific_command("TREAT#{total_n}")
    text += "\n > #{heal}"
  end

  return text
end
roll_cond(command) click to toggle source
# File lib/bcdice/game_system/Yggdrasill.rb, line 236
def roll_cond(command)
  return nil unless command == 'COND'

  hp_list = @randomizer.roll_barabara(2, 6)
  hp_total = hp_list.sum
  hp_str = hp_list.join(",")

  pp_list = @randomizer.roll_barabara(2, 6)
  pp_total = pp_list.sum
  pp_str = pp_list.join(",")

  return "(#{command}) > HP#{hp_total}[#{hp_str}] 、 PP#{pp_total}[#{pp_str}]"
end
roll_cont(command) click to toggle source
# File lib/bcdice/game_system/Yggdrasill.rb, line 259
def roll_cont(command)
  return nil unless /CO(NT)?/.match?(command)

  dice = @randomizer.roll_once(6)
  text = dice <= 4 ? "1R追加" : "2R追加"

  "コンティニュー判定 > #{dice} > #{text}"
end
roll_down(command) click to toggle source
# File lib/bcdice/game_system/Yggdrasill.rb, line 220
def roll_down(command)
  return nil unless command == 'DOWN'

  dice = @randomizer.roll_once(6)

  result =
    if dice.even?
      "回避"
    else
      fell = @randomizer.roll_once(6)
      "気絶【#{fell}R行動不能】"
    end

  "気絶判定 > #{dice} > #{result}"
end
roll_guki(command) click to toggle source
# File lib/bcdice/game_system/Yggdrasill.rb, line 250
def roll_guki(command)
  return nil unless command == 'GUKI'

  dice = @randomizer.roll_once(6)
  result = dice.even? ? "成功" : "失敗"

  "(GUKI) > #{dice} > #{result}"
end
roll_pafe(command) click to toggle source
# File lib/bcdice/game_system/Yggdrasill.rb, line 282
def roll_pafe(command)
  return nil unless command == "PAFE"

  dice = @randomizer.roll_once(6)
  text =
    if dice == 1
      "発動失敗【通常命中・回避判定となり、発動時のアクション内の命中力&回避力が半減する】"
    else
      "発動成功"
    end

  "発動ロール > #{dice} > #{text}"
end
roll_ra(command) click to toggle source
# File lib/bcdice/game_system/Yggdrasill.rb, line 159
def roll_ra(command)
  m = /^RA(\d+)?$/.match(command)
  return nil unless m

  body =
    case m[1]&.to_i
    when 50
      RA50.roll(@randomizer)
    when 70
      RA70.roll(@randomizer)
    when 90
      RA90.roll(@randomizer)
    when 110, 120, 130, 140
      RA110.roll(@randomizer)
    when 150
      "> 因子崩壊【キャラロスト】"
    when nil
      "> このコマンドは数値を付けてください"
    else
      "> 指定の暴走率の暴走ロールはありません"
    end

  "(#{command}) #{body}"
end
roll_treat(command) click to toggle source
# File lib/bcdice/game_system/Yggdrasill.rb, line 184
def roll_treat(command)
  m = /^TREAT(-?\d+)?$/.match(command)
  return nil unless m

  unless m[1]
    return "AE【応急処置】 > このコマンドは数値を付けてください"
  end

  value = m[1]&.to_i

  recovery =
    if value <= 5
      0
    elsif value <= 7
      1
    elsif value <= 11
      dice = @randomizer.roll_once(6)
      total = dice / 2
      "#{total}(#{dice}[#{dice}]/2)"
    elsif value <= 14
      dice = @randomizer.roll_once(6)
      "#{dice}(#{dice}[#{dice}])"
    elsif value <= 17
      dice = @randomizer.roll_once(6)
      total = dice + 3
      "#{total}(#{dice}[#{dice}]+3)"
    else
      list = @randomizer.roll_barabara(2, 6)
      dice = list.sum()
      total = dice + 2
      "#{total}(#{dice}[#{list.join(',')}]+2)"
    end

  "AE【応急処置】 > HPが#{recovery}回復"
end