class BCDice::GameSystem::NightWizard
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/NightWizard.rb, line 33 def initialize(command) super(command) @nw_command = "NW" end
Public Instance Methods
eval_game_system_specific_command(string)
click to toggle source
@return [String, nil]
# File lib/bcdice/game_system/NightWizard.rb, line 40 def eval_game_system_specific_command(string) cmd = parse_nw(string) || parse_2r6(string) unless cmd return nil end total, interim_expr, status = roll_nw(cmd) result = if cmd.cmp_op total.send(cmd.cmp_op, cmd.target_number) ? "成功" : "失敗" end sequence = [ "(#{cmd})", interim_expr, status, total.to_s, result, ].compact return sequence.join(" > ") end
Private Instance Methods
fumble_base_number(parsed)
click to toggle source
@return [Integer]
# File lib/bcdice/game_system/NightWizard.rb, line 226 def fumble_base_number(parsed) parsed.passive_modify_number end
parse_2r6(string)
click to toggle source
@return [Parsed2R6, nil]
# File lib/bcdice/game_system/NightWizard.rb, line 145 def parse_2r6(string) m = /^2R6m\[([-+]?\d+(?:[-+]\d+)*)(?:,([-+]?\d+(?:[-+]\d+)*))?\](?:c\[(\d+(?:,\d+)*)\])?(?:f\[(\d+(?:,\d+)*)\])?(?:([>=]+)(\d+))?/i.match(string) unless m return nil end command = Parsed2R6.new command.passive_modify_number = ArithmeticEvaluator.eval(m[1]) command.active_modify_number = ArithmeticEvaluator.eval(m[2]) command.critical_numbers = m[3] ? m[3].split(',').map(&:to_i) : [10] command.fumble_numbers = m[4] ? m[4].split(',').map(&:to_i) : [5] command.cmp_op = Normalize.comparison_operator(m[5]) command.target_number = m[6]&.to_i return command end
parse_nw(string)
click to toggle source
@return [ParsedNW, nil]
# File lib/bcdice/game_system/NightWizard.rb, line 125 def parse_nw(string) m = /^([-+]?\d+)?#{@nw_command}((?:[-+]\d+)+)?(?:@(\d+(?:,\d+)*))?(?:#(\d+(?:,\d+)*))?(?:\$(\d+(?:,\d+)*))?((?:[-+]\d+)+)?(?:([>=]+)(\d+))?$/.match(string) unless m return nil end command = ParsedNW.new(@nw_command) command.base = m[1].to_i command.modify_number = ArithmeticEvaluator.eval(m[2]) command.critical_numbers = m[3] ? m[3].split(',').map(&:to_i) : [10] command.fumble_numbers = m[4] ? m[4].split(',').map(&:to_i) : [5] command.prana = m[5]&.to_i command.active_modify_number = ArithmeticEvaluator.eval(m[6]) command.cmp_op = Normalize.comparison_operator(m[7]) command.target_number = m[8]&.to_i return command end
roll_nw(parsed)
click to toggle source
# File lib/bcdice/game_system/NightWizard.rb, line 162 def roll_nw(parsed) @critical_numbers = parsed.critical_numbers @fumble_numbers = parsed.fumble_numbers @total = 0 @interim_expr = "" @status = nil status = roll_once_first() while status == :critical status = roll_once() end if status != :fumble && parsed.prana dice_list = @randomizer.roll_barabara(parsed.prana, 6) prana_bonus = dice_list.sum() prana_list = dice_list.join(",") @total += prana_bonus @interim_expr += "+#{prana_bonus}[#{prana_list}]" end base = if status == :fumble fumble_base_number(parsed) else parsed.passive_modify_number + parsed.active_modify_number end @total += base @interim_expr = base.to_s + @interim_expr return @total, @interim_expr, @status end
roll_once(fumbleable = false)
click to toggle source
@return [Symbol, nil]
# File lib/bcdice/game_system/NightWizard.rb, line 198 def roll_once(fumbleable = false) dice_list = @randomizer.roll_barabara(2, 6) dice_value = dice_list.sum() dice_str = dice_list.join(",") if fumbleable && @fumble_numbers.include?(dice_value) @total -= 10 @interim_expr += "-10[#{dice_str}]" @status = "ファンブル" return :fumble elsif @critical_numbers.include?(dice_value) @total += 10 @interim_expr += "+10[#{dice_str}]" @status = "クリティカル" return :critical else @total += dice_value @interim_expr += "+#{dice_value}[#{dice_str}]" return nil end end
roll_once_first()
click to toggle source
@return [Symbol, nil]
# File lib/bcdice/game_system/NightWizard.rb, line 221 def roll_once_first roll_once(true) end