class BCDice::GameSystem::RokumonSekai2

Constants

HELP_MESSAGE

ダイスボットの使い方

ID

ゲームシステムの識別子

NAME

ゲームシステム名

SORT_KEY

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

Public Class Methods

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

  @sort_add_dice = true
end

Public Instance Methods

eval_game_system_specific_command(string) click to toggle source
# File lib/bcdice/game_system/RokumonSekai2.rb, line 40
def eval_game_system_specific_command(string)
  string = replace_text(string)
  unless /3R6([+\-\d]*)<=(\d+)\[(\d+)\]/i =~ string
    return nil
  end

  modText = Regexp.last_match(1)
  target = Regexp.last_match(2).to_i
  abl = Regexp.last_match(3).to_i

  mod = 0
  if modText
    mod = ArithmeticEvaluator.eval(modText)
  end

  dstr, suc, sum = rokumon2_roll(mod, target, abl)
  output = "#{sum}[#{dstr}] > #{suc} > 評価#{rokumon2_suc_rank(suc)}"

  if suc != 0
    output += "(+#{suc}d6)"
  end

  output = "(#{string}) > #{output}"

  return output
end
replace_text(string) click to toggle source
# File lib/bcdice/game_system/RokumonSekai2.rb, line 33
def replace_text(string)
  string = string.gsub(/(\d+)RS([+\-][+\-\d]+)<=(\d+)/i) { "3R6#{Regexp.last_match(2)}<=#{Regexp.last_match(3)}[#{Regexp.last_match(1)}]" }
  string = string.gsub(/(\d+)RS<=(\d+)/i) { "3R6<=#{Regexp.last_match(2)}[#{Regexp.last_match(1)}]" }

  return string
end
rokumon2_roll(mod, target, abl) click to toggle source
# File lib/bcdice/game_system/RokumonSekai2.rb, line 67
def rokumon2_roll(mod, target, abl)
  suc = 0

  dice = @randomizer.roll_barabara(3 + mod.abs, 6).sort
  dicestr = dice.join(",")

  mod.abs.times do |_i|
    if mod < 0
      dice.shift
    else
      dice.pop
    end
  end

  cnt5 = 0
  cnt2 = 0
  sum = 0

  dice.each do |die1|
    cnt5 += 1 if die1 >= 5
    cnt2 += 1 if die1 <= 2
    suc += 1  if die1 <= abl
    sum += die1
  end

  if sum < target
    suc += 2
  elsif sum == target
    suc += 1
  end

  suc = 0 if cnt5 >= 3
  suc = 5 if cnt2 >= 3

  return dicestr, suc, sum
end
rokumon2_suc_rank(suc) click to toggle source
# File lib/bcdice/game_system/RokumonSekai2.rb, line 104
def rokumon2_suc_rank(suc)
  suc_rank = ['E', 'D', 'C', 'B', 'A', 'S']
  return suc_rank[suc]
end