From edbd54cb5cad8a9d8df5839a538343685c6ac0a7 Mon Sep 17 00:00:00 2001 From: ocha Date: Mon, 14 Dec 2020 01:28:25 +0900 Subject: [PATCH] =?UTF-8?q?BarabaraDice:=20=E7=B5=90=E6=9E=9C=E3=81=AB?= =?UTF-8?q?=E5=87=BA=E7=9B=AE=E3=81=A8=E6=88=90=E5=8A=9F=E6=95=B0=E3=82=92?= =?UTF-8?q?=E5=8A=A0=E3=81=88=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ゲームシステム独自コマンドから利用する際に、出目と成功数を直接 取得できるようにする --- .../common_command/barabara_dice/node.rb | 8 ++++++- .../common_command/barabara_dice/result.rb | 22 +++++++++++++++++++ lib/bcdice/result.rb | 2 ++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 lib/bcdice/common_command/barabara_dice/result.rb diff --git a/lib/bcdice/common_command/barabara_dice/node.rb b/lib/bcdice/common_command/barabara_dice/node.rb index 814941bd7..022dfc268 100644 --- a/lib/bcdice/common_command/barabara_dice/node.rb +++ b/lib/bcdice/common_command/barabara_dice/node.rb @@ -1,4 +1,5 @@ require "bcdice/format" +require "bcdice/common_command/barabara_dice/result" module BCDice module CommonCommand @@ -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) } @@ -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 diff --git a/lib/bcdice/common_command/barabara_dice/result.rb b/lib/bcdice/common_command/barabara_dice/result.rb new file mode 100644 index 000000000..8177c6155 --- /dev/null +++ b/lib/bcdice/common_command/barabara_dice/result.rb @@ -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 diff --git a/lib/bcdice/result.rb b/lib/bcdice/result.rb index 09e90440a..2c3b1fc6a 100644 --- a/lib/bcdice/result.rb +++ b/lib/bcdice/result.rb @@ -38,6 +38,8 @@ def nothing def initialize(text = nil) @text = text + @rands = nil + @detailed_rands = nil @secret = false @success = false @failure = false