class BCDice::GameSystem::Skynauts
Constants
- DIRECTION_INFOS
- 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/Skynauts.rb, line 37 def initialize(command) super(command) @round_type = RoundType::FLOOR # 端数切り捨て end
Public Instance Methods
eval_game_system_specific_command(command)
click to toggle source
# File lib/bcdice/game_system/Skynauts.rb, line 42 def eval_game_system_specific_command(command) debug("\n=======================================\n") debug("eval_game_system_specific_command command", command) return get_judge_result(command) || navigation_result(command) || get_fire_result(command) || get_bomb_result(command) || get_avoid_result(command) end
Private Instance Methods
get_avoid_result(command)
click to toggle source
# File lib/bcdice/game_system/Skynauts.rb, line 223 def get_avoid_result(command) return nil unless (m = /^AVO(\d*)?(@([2468]))(\(?\[縦\d+,横\d+\]\)?,?)+$/.match(command)) debug("====get_avoid_result====", command) direction = m[3].to_i debug("回避方向", direction) judge_command = command.slice(/^AVO(\d*)?(@([2468]))/) # 判定部分 sn = get_judge_result("SN" + Regexp.last_match(1).to_s) if sn.failure? sn.text = "#{judge_command} > 《回避運動》#{sn.text}" return sn end point_command = command.slice(/(\(?\[縦\d+,横\d+\]\)?,?)+/) # 砲撃座標 fire_point = scan_fire_point(point_command) fire_count = fire_point.size Result.success([ judge_command, "《回避運動》#{sn.text}\n", point_command, "《回避運動》:" + get_direction_info(direction, :name, "") + "\n", get_fire_point_text(fire_point, fire_count, direction).text ].compact.join(" > ")) end
get_bomb_result(command)
click to toggle source
# File lib/bcdice/game_system/Skynauts.rb, line 201 def get_bomb_result(command) return nil unless (m = %r{^BOM(\d*)?/D([12346789]*)(\[.+\])*/(\d+)(@([2468]))?$}i.match(command)) debug("====get_bomb_result====", command) target = m[1].to_s direction = m[6].to_i debug("弾道学方向", direction) sn = get_judge_result("SN" + target) # 砲撃判定 if sn.failure? sn.text = "#{command} > #{sn.text}" return sn end # ダメージチェック部分 fire_command = command.slice(%r{D([12346789]*)(\[.+\])*/(\d+)(@([2468]))?}) sn.text = "#{command} > #{sn.text}\n > #{get_fire_result(fire_command).text}" sn end
get_direction_info(direction, key, default_value = nil)
click to toggle source
# File lib/bcdice/game_system/Skynauts.rb, line 100 def get_direction_info(direction, key, default_value = nil) info = DIRECTION_INFOS[direction.to_i] return default_value if info.nil? return info[key] end
get_fire_point(fire_range, fire_count)
click to toggle source
# File lib/bcdice/game_system/Skynauts.rb, line 129 def get_fire_point(fire_range, fire_count) debug("====get_fire_point====") fire_point = [] fire_count.times do |count| debug("\n砲撃回数", count + 1) fire_point << [] y_pos = @randomizer.roll_once(6) # 縦 x_pos = @randomizer.roll_sum(2, 6) # 横 position = [x_pos, y_pos] fire_point[-1] << position debug("着弾点", fire_point) fire_range.chars do |range_text| debug("範囲", range_text) position_diff = get_direction_info(range_text, :position_diff, {}) position = [x_pos + position_diff[:x].to_i, y_pos + position_diff[:y].to_i] fire_point[-1] << position debug("着弾点:範囲", fire_point) end end debug("\n最終着弾点", fire_point) return fire_point end
get_fire_point_text(fire_point, _fire_count, direction = 0)
click to toggle source
# File lib/bcdice/game_system/Skynauts.rb, line 163 def get_fire_point_text(fire_point, _fire_count, direction = 0) debug("====get_fire_point_text====") fire_text_list = [] fire_point.each do |point| text = "" point.each do |x, y| # 《弾道学》《回避運動》などによる座標移動 x, y = get_move_point(x, y, direction) # マップ外の座標は括弧を付ける text += in_map_position?(x, y) ? "[縦#{y},横#{x}]" : "([縦#{y},横#{x}])" debug("着弾点テキスト", text) end fire_text_list << text end Result.new(fire_text_list.join(",")) end
get_fire_result(command)
click to toggle source
# File lib/bcdice/game_system/Skynauts.rb, line 107 def get_fire_result(command) return nil unless (m = %r{^D([12346789]*)(\[.+\])*/(\d{1,2})(@([2468]))?$}.match(command)) debug("====get_fire_result====") fire_count = m[3].to_i # 砲撃回数 fire_range = m[1].to_s # 砲撃範囲 ballistics = m[5].to_i # 《弾道学》 debug("fire_count", fire_count) debug("fire_range", fire_range) debug("ballistics", ballistics) fire_point = get_fire_point(fire_range, fire_count) # 着弾座標取得(3次元配列) result = [command, get_fire_point_text(fire_point, fire_count).text] # 表示用文字列作成 if ballistics != 0 # 《弾道学》有 result << "《弾道学》:#{get_direction_info(ballistics, :name, '')}\n" result << get_fire_point_text(fire_point, fire_count, ballistics).text end Result.new(result.join(" > ")) end
get_judge_result(command)
click to toggle source
# File lib/bcdice/game_system/Skynauts.rb, line 52 def get_judge_result(command) return nil unless (m = (/^2D6<=(\d)$/i.match(command) || /^SN(\d*)$/i.match(command))) debug("====get_judge_result====") target = m[1].empty? ? 7 : m[1].to_i # 目標値。省略時は7 debug("目標値", target) dice_list = @randomizer.roll_barabara(2, 6) total = dice_list.sum() text = "(2D6<=#{target}) > #{total}[#{dice_list.join(',')}] > #{total}" if total <= 2 Result.fumble(text + " > ファンブル") elsif total <= target Result.success(text + " > 成功") else Result.failure(text + " > 失敗") end end
get_move_point(x, y, direction)
click to toggle source
# File lib/bcdice/game_system/Skynauts.rb, line 188 def get_move_point(x, y, direction) debug("====get_move_point====") debug("方向", direction) debug("座標移動前(x,y)", x, y) position_diff = get_direction_info(direction, :position_diff, {}) x += position_diff[:x].to_i y += position_diff[:y].to_i debug("\n座標移動後(x,y)", x, y) return x, y end
in_map_position?(x, y)
click to toggle source
# File lib/bcdice/game_system/Skynauts.rb, line 184 def in_map_position?(x, y) ((1 <= y) && (y <= 6)) && ((2 <= x) && (x <= 12)) end
scan_fire_point(command)
click to toggle source
# File lib/bcdice/game_system/Skynauts.rb, line 251 def scan_fire_point(command) debug("====scan_fire_point====", command) command = command.gsub(/\(|\)/, "") # 正規表現が大変なので最初に括弧を外しておく fire_point = [] # 一組ずつに分ける("[縦y,横xの単位) command.split(/\],/).each do |point_text| debug("point_text", point_text) fire_point << [] # D以外の砲撃範囲がある時に必要 point_text.split(/\]/).each do |point| debug("point", point) fire_point[-1] << [] next unless point =~ /[^\d]*(\d+),[^\d]*(\d+)/ y = Regexp.last_match(1).to_i x = Regexp.last_match(2).to_i fire_point[-1][-1] = [x, y] debug("着弾点", fire_point) end end return fire_point end