Skip to content

Commit

Permalink
rand_resultsを初期化しておくようにする (#159)
Browse files Browse the repository at this point in the history
* Set initial value of rand_results

Fix #155

* Fix #setCollectRandResult

Array#clearだと、外部から参照された配列の中身も丸ごと消してしまうので、元の挙動の通り空配列で初期化する
  • Loading branch information
ysakasin authored Apr 21, 2020
1 parent 215a989 commit f68d2aa
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/bcdiceCore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f68d2aa

Please sign in to comment.