class BCDice::GameSystem::Irisbane

Constants

ALIAS
ATTACK_ROLL_REG
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/Irisbane.rb, line 43
def initialize(command)
  super(command)

  @sort_barabara_dice = true
  @round_type = RoundType::CEIL
end

Public Instance Methods

eval_game_system_specific_command(command) click to toggle source
# File lib/bcdice/game_system/Irisbane.rb, line 50
def eval_game_system_specific_command(command)
  command = ALIAS[command] || command

  if (m = ATTACK_ROLL_REG.match(command))
    roll_attack(m[2], m[3], m[4], m[6], m[7])
  else
    roll_tables(command, TABLES)
  end
end

Private Instance Methods

make_command_text(power, dice_count, border, modification_operator, modification_value) click to toggle source
# File lib/bcdice/game_system/Irisbane.rb, line 106
def make_command_text(power, dice_count, border, modification_operator, modification_value)
  text = "(ATTACK#{power}@#{dice_count}<=#{border}"
  text += "[#{modification_operator}#{modification_value}]" if modification_operator
  text += ")"
  text
end
parse_operator(operator) click to toggle source
# File lib/bcdice/game_system/Irisbane.rb, line 113
def parse_operator(operator)
  case operator
  when '+'
    lambda { |x, y| x + y }
  when '-'
    lambda { |x, y| x - y }
  end
end
roll_attack(power_expression, dice_count_expression, border_expression, modification_operator, modification_expression) click to toggle source
# File lib/bcdice/game_system/Irisbane.rb, line 62
def roll_attack(power_expression, dice_count_expression, border_expression, modification_operator, modification_expression)
  power = Arithmetic.eval(power_expression, RoundType::CEIL)
  dice_count = Arithmetic.eval(dice_count_expression, RoundType::CEIL)
  border = Arithmetic.eval(border_expression, RoundType::CEIL)
  modification_value = modification_expression.nil? ? nil : Arithmetic.eval(modification_expression, RoundType::CEIL)
  return if power.nil? || dice_count.nil? || border.nil?
  return if modification_operator && modification_value.nil?

  power = 0 if power < 0
  border = border.clamp(1, 6)

  command = make_command_text(power, dice_count, border, modification_operator, modification_value)

  if dice_count <= 0
    return "#{command} > 判定数が 0 です"
  end

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

  success_dice_count = dices.count { |dice| dice <= border }
  damage = success_dice_count * power

  message_elements = []
  message_elements << command
  message_elements << dices.join(',')
  message_elements << "成功ダイス数 #{success_dice_count}"
  message_elements << "× 攻撃力 #{power}" if success_dice_count > 0

  if success_dice_count > 0
    if modification_operator && modification_value
      message_elements << "ダメージ #{damage}#{modification_operator}#{modification_value}"
      damage = parse_operator(modification_operator).call(damage, modification_value)
      damage = 0 if damage < 0
      message_elements << damage.to_s
    else
      message_elements << "ダメージ #{damage}"
    end
  end

  Result.new(message_elements.join(' > ')).tap do |r|
    r.condition = success_dice_count > 0
  end
end