From f68d2aa3859588db32cc263a740476a8eb1ca36c Mon Sep 17 00:00:00 2001 From: SAKATA Sinji Date: Tue, 21 Apr 2020 20:20:52 +0900 Subject: [PATCH] =?UTF-8?q?rand=5Fresults=E3=82=92=E5=88=9D=E6=9C=9F?= =?UTF-8?q?=E5=8C=96=E3=81=97=E3=81=A6=E3=81=8A=E3=81=8F=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=E3=81=99=E3=82=8B=20(#159)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Set initial value of rand_results Fix #155 * Fix #setCollectRandResult Array#clearだと、外部から参照された配列の中身も丸ごと消してしまうので、元の挙動の通り空配列で初期化する --- src/bcdiceCore.rb | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/bcdiceCore.rb b/src/bcdiceCore.rb index 5c96368f2..a357a4d55 100755 --- a/src/bcdiceCore.rb +++ b/src/bcdiceCore.rb @@ -111,6 +111,10 @@ def initialize(parent, cardTrader, diceBot, counterInfos, tableFileData) @rands = nil @isKeepSecretDice = true @isIrcMode = true + + @collect_rand_results = false + @rand_results = [] + @detailed_rand_results = [] end def setDir(dir, prefix) @@ -1015,7 +1019,7 @@ def rand_inner(max) value = randFromRands(max) end - unless @rand_results.nil? + if @collect_rand_results @rand_results << [(value + 1), max] end @@ -1057,21 +1061,18 @@ def roll_d9() return ret end + # @param b [Boolean] def setCollectRandResult(b) - if b - @rand_results = [] - @detailed_rand_results = [] - else - @rand_results = nil - @detailed_rand_results = nil - end + @collect_rand_results = b + @rand_results = [] + @detailed_rand_results = [] end # @params [Symbol] kind # @params [Integer] sides # @params [Integer] value def push_to_detail(kind, sides, value) - unless @detailed_rand_results.nil? + if @collect_rand_results detail = DetailedRandResult.new(kind, sides, value) @detailed_rand_results.push(detail) end