class BCDice::GameSystem::Revulture

Constants

ATTACK_ROLL_REG
HELP_MESSAGE

ダイスボットの使い方

ID

ゲームシステムの識別子

NAME

ゲームシステム名

SORT_KEY

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

Public Instance Methods

eval_game_system_specific_command(command) click to toggle source
# File lib/bcdice/game_system/Revulture.rb, line 44
def eval_game_system_specific_command(command)
  if (m = ATTACK_ROLL_REG.match(command))
    roll_attack(m[1], m[5], m[7])
  end
end

Private Instance Methods

calc_damage(hit_count, additional_damage_rules) click to toggle source
# File lib/bcdice/game_system/Revulture.rb, line 91
def calc_damage(hit_count, additional_damage_rules)
  return nil unless additional_damage_rules

  damage = hit_count
  parse_additional_damage_rules(additional_damage_rules).each do |rule|
    if rule[:condition].call(hit_count)
      damage += rule[:additinal_damage]
    end
  end

  damage
end
make_additional_damage_condition(comparer, comparing_target) click to toggle source
# File lib/bcdice/game_system/Revulture.rb, line 113
def make_additional_damage_condition(comparer, comparing_target)
  case comparer
  when '='
    lambda { |hit_count| hit_count == comparing_target }
  when '>='
    lambda { |hit_count| hit_count >= comparing_target }
  end
end
make_command_text(dice_count, border, additional_damage_rules) click to toggle source
# File lib/bcdice/game_system/Revulture.rb, line 83
def make_command_text(dice_count, border, additional_damage_rules)
  command = "#{dice_count}attack"
  command += "<=#{border}" if border
  command += additional_damage_rules if additional_damage_rules

  "(#{command})"
end
parse_additional_damage_rules(source) click to toggle source
# File lib/bcdice/game_system/Revulture.rb, line 104
def parse_additional_damage_rules(source)
  source.scan(/\[(>?=)(\d+):\+(\d+)\]/).map do |matched|
    {
      condition: make_additional_damage_condition(matched[0], matched[1].to_i),
      additinal_damage: matched[2].to_i,
    }
  end
end
roll_attack(dice_count_expression, border_expression, additional_damage_rules) click to toggle source
# File lib/bcdice/game_system/Revulture.rb, line 52
def roll_attack(dice_count_expression, border_expression, additional_damage_rules)
  dice_count = Arithmetic.eval(dice_count_expression, RoundType::FLOOR)
  border = Arithmetic.eval(border_expression, RoundType::FLOOR).clamp(1, 6) if border_expression

  command = make_command_text(dice_count, border, additional_damage_rules)

  if dice_count <= 0
    return "#{command} > ダイス数が 0 です"
  elsif border.nil? && additional_damage_rules
    return "#{command} > 目標値が指定されていないため、追加ダメージを算出できません"
  end

  dices = @randomizer.roll_barabara(dice_count, 6).sort

  critical_hit_count = dices.count(1)
  hit_count = dices.count { |dice| dice <= border } + critical_hit_count if border
  damage = calc_damage(hit_count, additional_damage_rules)

  message_elements = []
  message_elements << command
  message_elements << dices.join(',')
  message_elements << "クリティカル #{critical_hit_count}" if critical_hit_count > 0
  message_elements << "ヒット数 #{hit_count}" if hit_count
  message_elements << "ダメージ #{damage}" if damage

  Result.new(message_elements.join(' > ')).tap do |r|
    r.condition = hit_count > 0 if hit_count
    r.critical = critical_hit_count > 0
  end
end