Skip to content

Commit

Permalink
Merge pull request #335 from bcdice/barabara_dice-extend_result
Browse files Browse the repository at this point in the history
バラバラロール(xBn)の結果に出目と成功数を加える
  • Loading branch information
ysakasin authored Dec 20, 2020
2 parents dea62b7 + 07ae345 commit a6e0435
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 29 deletions.
8 changes: 7 additions & 1 deletion lib/bcdice/common_command/barabara_dice/node.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "bcdice/format"
require "bcdice/common_command/barabara_dice/result"

module BCDice
module CommonCommand
Expand All @@ -12,7 +13,9 @@ def initialize(secret:, notations:, cmp_op:, target_number:)
@target_number = target_number
end

# @return [String, nil]
# @param game_system [Base] ゲームシステム
# @param randomizer [Randomizer] ランダマイザ
# @return [Result]
def eval(game_system, randomizer)
round_type = game_system.round_type
notations = @notations.map { |n| n.to_dice(round_type) }
Expand All @@ -38,6 +41,9 @@ def eval(game_system, randomizer)
Result.new.tap do |r|
r.secret = @secret
r.text = sequence.join(" > ")
r.rands = randomizer.rand_results
r.detailed_rands = randomizer.detailed_rand_results
r.success_num = success_num
end
end
end
Expand Down
22 changes: 22 additions & 0 deletions lib/bcdice/common_command/barabara_dice/result.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

require "bcdice/result"

module BCDice
module CommonCommand
module BarabaraDice
# バラバラロールの結果を表すクラス
class Result < ::BCDice::Result
# @return [Integer] 成功数
attr_accessor :success_num

# @param text [String, nil] 結果の文章
def initialize(text = nil)
super(text)

@success_num = 0
end
end
end
end
end
54 changes: 26 additions & 28 deletions lib/bcdice/game_system/NinjaSlayer.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

require 'bcdice/common_command/barabara_dice'
require 'bcdice/dice_table/table'

module BCDice
Expand Down Expand Up @@ -69,9 +70,6 @@ def initialize(command)
# 電子戦の正規表現
EL_RE = /\AEL(\d+)#{DIFFICULTY_RE}?\z/io.freeze

# バラバラロール結果の "(" の前までの先頭部分
B_ROLL_RESULT_HEAD_RE = /\A[^(]+/.freeze

# 回避判定のノード
EV = Struct.new(:num, :difficulty, :targetValue)
# 近接攻撃のノード
Expand Down Expand Up @@ -169,55 +167,55 @@ def parseEL(m)
# @return [String] 回避判定結果
def executeEV(ev)
command = bRollCommand(ev.num, ev.difficulty)
roll_result = BCDice::CommonCommand::BarabaraDice.eval(command, self, @randomizer)

rollResult = BCDice::CommonCommand::BarabaraDice.eval(command, self, @randomizer).text.sub(B_ROLL_RESULT_HEAD_RE, '')
return rollResult unless ev.targetValue

m = /成功数(\d+)/.match(rollResult)
raise '成功数が見つかりません' unless m
parts = [roll_result.text]

numOfSuccesses = m[1].to_i
if numOfSuccesses > ev.targetValue
return "#{rollResult} > カウンターカラテ!!"
if ev.targetValue && roll_result.success_num > ev.targetValue
parts.push("カウンターカラテ!!")
end

return rollResult
return parts.join(" > ")
end

# 近接攻撃を行う
# @param [AT] at 近接攻撃ノード
# @return [String] 近接攻撃結果
def executeAT(at)
command = bRollCommand(at.num, at.difficulty)
rollResult = BCDice::CommonCommand::BarabaraDice.eval(command, self, @randomizer).text.sub(B_ROLL_RESULT_HEAD_RE, '')
roll_result = BCDice::CommonCommand::BarabaraDice.eval(command, self, @randomizer)

values = roll_result.rands.map { |v, _| v }
num_of_max_values = values.count(6)

# バラバラロールの出目を取得する
# TODO: バラバラロールの結果として、出目を配列で取得できるようにする
m = /> (\d+(?:,\d+)*)/.match(rollResult)
values = m[1].split(',').map(&:to_i)
parts = [roll_result.text]

numOfMaxValues = values.count(6)
if num_of_max_values >= 2
parts.push("サツバツ!!")
end

return numOfMaxValues >= 2 ? "#{rollResult}サツバツ!!" : rollResult
return parts.join("")
end

# 電子戦を行う
# @param [EL] el 電子戦ノード
# @return [String] 電子戦結果
def executeEL(el)
command = bRollCommand(el.num, el.difficulty)
rollResult = BCDice::CommonCommand::BarabaraDice.eval(command, self, @randomizer).text.sub(B_ROLL_RESULT_HEAD_RE, '')

# バラバラロールの出目を取得する
# TODO: バラバラロールの結果として、出目を配列で取得できるようにする
m = /> (\d+(?:,\d+)*)/.match(rollResult)
values = m[1].split(',').map(&:to_i)
roll_result = BCDice::CommonCommand::BarabaraDice.eval(command, self, @randomizer)

numOfMaxValues = values.count(6)
values = roll_result.rands.map { |v, _| v }
num_of_max_values = values.count(6)
sum_of_true_values = values.count { |v| v >= el.difficulty }

sumOfTrueValues = values.count { |v| v >= el.difficulty }
if num_of_max_values >= 1
return [
"#{roll_result.text} + #{num_of_max_values}",
sum_of_true_values + num_of_max_values
].join(" > ")
end

return numOfMaxValues >= 1 ? "#{rollResult} + #{numOfMaxValues}#{sumOfTrueValues + numOfMaxValues}" : rollResult
return roll_result.text
end

# 難易度の整数値を返す
Expand Down
2 changes: 2 additions & 0 deletions lib/bcdice/result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ def nothing

def initialize(text = nil)
@text = text
@rands = nil
@detailed_rands = nil
@secret = false
@success = false
@failure = false
Expand Down

0 comments on commit a6e0435

Please sign in to comment.