Skip to content

Commit

Permalink
BarabaraDice: 結果に出目と成功数を加える
Browse files Browse the repository at this point in the history
ゲームシステム独自コマンドから利用する際に、出目と成功数を直接
取得できるようにする
  • Loading branch information
ochaochaocha3 committed Dec 13, 2020
1 parent b0feed4 commit edbd54c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
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
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 edbd54c

Please sign in to comment.