class BCDice::GameSystem::FilledWith::FW

Attributes

critical[RW]
dice_count[RW]
fumble[RW]
target[RW]

Public Class Methods

new() click to toggle source
# File lib/bcdice/game_system/FilledWith.rb, line 124
def initialize
  @target = nil
end
parse(command) click to toggle source
# File lib/bcdice/game_system/FilledWith.rb, line 134
def self.parse(command)
  if (m = /^(\d[+\-\d]*)-(\d+)FW(?:@(\d+))?(?:\#(\d+))?$/.match(command))
    new.tap do |fw|
      fw.dice_count = m[2].to_i
      fw.target = Arithmetic.eval(m[1], RoundType::FLOOR)
      fw.critical = m[3]&.to_i || 4
      fw.fumble = m[4]&.to_i || 17
    end
  elsif (m = /(\d+)FW(?:@(\d+))?(?:\#(\d+))?(?:<=([+\-\d]+))?/.match(command))
    new.tap do |fw|
      fw.dice_count = m[1].to_i
      fw.target = Arithmetic.eval(m[4], RoundType::FLOOR) if m[4]
      fw.critical = m[2]&.to_i || 4
      fw.fumble = m[3]&.to_i || 17
    end
  end
end
roll(command, randomizer) click to toggle source
# File lib/bcdice/game_system/FilledWith.rb, line 128
def self.roll(command, randomizer)
  fw = parse(command)

  return fw&.roll(randomizer)
end

Public Instance Methods

roll(randomizer) click to toggle source
# File lib/bcdice/game_system/FilledWith.rb, line 152
def roll(randomizer)
  dice_list = randomizer.roll_barabara(@dice_count, 6)
  dice = dice_list.sum()
  dice_str = dice_list.join(",")

  res = result(dice)

  sequence = [
    "(#{expr})",
    "#{dice}[#{dice_str}]",
    res.text,
  ].compact

  res.text = sequence.join(" > ")

  return res
end

Private Instance Methods

expr() click to toggle source
# File lib/bcdice/game_system/FilledWith.rb, line 172
def expr
  ret = "#{@dice_count}FW"
  ret += "@#{@critical}" if @critical != 4
  ret += "##{@fumble}" if @fumble != 17
  ret += "<=#{@target}" if @target

  return ret
end
result(total) click to toggle source
# File lib/bcdice/game_system/FilledWith.rb, line 181
def result(total)
  if total <= @critical
    Result.critical("クリティカル!")
  elsif total >= @fumble
    Result.fumble("ファンブル!")
  elsif @target
    success = @target - total
    if total <= @target
      Result.success("成功(成功度:#{success})")
    else
      Result.failure("失敗(失敗度:#{success})")
    end
  else
    Result.new
  end
end