class BCDice::GameSystem::BeastBindTrinity::BBCommand
Public Class Methods
new(command)
click to toggle source
# File lib/bcdice/game_system/BeastBindTrinity.rb, line 61 def initialize(command) @command = command parse() end
Public Instance Methods
roll(randomizer)
click to toggle source
# File lib/bcdice/game_system/BeastBindTrinity.rb, line 66 def roll(randomizer) if @parse_error return nil end @randomizer = randomizer dice_list_org = roll_with_dice_pool() if dice_list_org.empty? return "ERROR:振るダイスの数が0個です" end dice_list_filtered = dice_list_org.map { |dice| [dice, @dice_value_lower_limit].max }.sort @dice_total = dice_list_filtered.last(2).inject(0, :+) total = calc_total() dice_list_org_str = "[#{dice_list_org.join(',')}]" if dice_list_filtered != dice_list_org result = result_compare(total) result.critical = critical? result.fumble = fumble? dice_status = if result.fumble? "ファンブル" elsif result.critical? "クリティカル" end result_str = if result.success? "成功" elsif result.failure? "失敗" end sequence = [ command_expr(), dice_list_org_str, interim_expr(dice_list_filtered), dice_status, total.to_s, result_str ].compact result.text = sequence.join(" > ") return result end
Private Instance Methods
calc_total()
click to toggle source
# File lib/bcdice/game_system/BeastBindTrinity.rb, line 216 def calc_total total = @dice_total + @modify_number if fumble? total = 0 unless @keep_value_on_fumble elsif critical? total += 20 end if total < 0 total = 0 end return total end
command_expr()
click to toggle source
# File lib/bcdice/game_system/BeastBindTrinity.rb, line 196 def command_expr modifier = Format.modifier(@modify_number) "(#{@dice_num}BB#{modifier}@#{@critical}\##{@fumble}#{@cmp_op}#{@target_number})" end
critical?()
click to toggle source
# File lib/bcdice/game_system/BeastBindTrinity.rb, line 212 def critical? @dice_total >= @critical end
critical_from_humanity(humanity)
click to toggle source
# File lib/bcdice/game_system/BeastBindTrinity.rb, line 163 def critical_from_humanity(humanity) if humanity <= 0 9 elsif humanity <= 20 10 elsif humanity <= 40 11 else 12 end end
fumble?()
click to toggle source
# File lib/bcdice/game_system/BeastBindTrinity.rb, line 208 def fumble? @dice_total <= @fumble end
interim_expr(dice_list)
click to toggle source
# File lib/bcdice/game_system/BeastBindTrinity.rb, line 201 def interim_expr(dice_list) expr = "#{@dice_total}[#{dice_list.join(',')}]#{Format.modifier(@modify_number)}" expr += "+20" if critical? return expr end
parse()
click to toggle source
# File lib/bcdice/game_system/BeastBindTrinity.rb, line 117 def parse() m = /^(\d+)(?:R6|BB6?)((?:[+\-]\d+)+)?(?:%(-?\d+))?(?:@([+\-\d]+))?(?:#(A)?([+\-\d]+))?(?:\$([1-6]+))?(?:&([1-6]))?(?:([>=]+)(\d+))?$/.match(@command) unless m @parse_error = true return end @dice_num = m[1].to_i @modify_number = m[2] ? ArithmeticEvaluator.eval(m[2]) : 0 @critical = parse_critical(m[3], m[4]) @keep_value_on_fumble = !m[5].nil? @fumble = parse_fumble(m[6]) @dice_pool = m[7] ? m[7].split("").map(&:to_i) : [] @dice_pool.pop(@dice_pool.size - @dice_num) if @dice_pool.size > @dice_num @dice_value_lower_limit = m[8].to_i @cmp_op = Normalize.comparison_operator(m[9]) @target_number = m[10]&.to_i @parse_error = false end
parse_critical(humanity, atmark)
click to toggle source
@param humanity [String, nil] @param atmark [String, nil] @return [Integer]
# File lib/bcdice/game_system/BeastBindTrinity.rb, line 147 def parse_critical(humanity, atmark) humanity = humanity ? humanity.to_i : 99 atmark_value = atmark ? ArithmeticEvaluator.eval(atmark) : 0 critical = if /^[+-]/.match(atmark) [critical_from_humanity(humanity) + atmark_value, 12].min elsif atmark atmark_value else critical_from_humanity(humanity) end return critical end
parse_fumble(sharp)
click to toggle source
@param sharp [String, nil] @return [Integer]
# File lib/bcdice/game_system/BeastBindTrinity.rb, line 177 def parse_fumble(sharp) sharp_value = sharp ? ArithmeticEvaluator.eval(sharp) : 0 if /^[+-]/.match(sharp) 2 + sharp_value elsif sharp sharp_value else 2 end end
result_compare(total)
click to toggle source
# File lib/bcdice/game_system/BeastBindTrinity.rb, line 231 def result_compare(total) if @cmp_op if total.send(@cmp_op, @target_number) Result.success(nil) else Result.failure(nil) end else Result.new end end
roll_with_dice_pool()
click to toggle source
# File lib/bcdice/game_system/BeastBindTrinity.rb, line 189 def roll_with_dice_pool dice_times = @dice_num - @dice_pool.size dice_list = @randomizer.roll_barabara(dice_times, 6) + @dice_pool return dice_list.sort end