class BCDice::CommonCommand::AddDice::Node::DiceRoll
ダイスロールのノード
Public Class Methods
new(times, sides)
click to toggle source
ノードを初期化する @param [Number] times ダイスを振る回数のノード @param [Number] sides ダイスの面数のノード
# File lib/bcdice/common_command/add_dice/node.rb, line 377 def initialize(times, sides) @times = times @sides = sides # ダイスを振った結果の出力 @text = nil end
Public Instance Methods
eval(game_system, randomizer)
click to toggle source
ノードを評価する(ダイスを振る)
評価結果は出目の合計値になる。 出目はランダマイザに記録される。
@param [Randomizer] randomizer ランダマイザ @return [Integer] 評価結果(出目の合計値)
# File lib/bcdice/common_command/add_dice/node.rb, line 392 def eval(game_system, randomizer) times = @times.eval(game_system, nil) sides = eval_sides(game_system) dice_list = randomizer.roll(times, sides) total = dice_list.sum() @text = "#{total}[#{dice_list.join(',')}]" return total end
expr(game_system)
click to toggle source
文字列に変換する @return [String]
# File lib/bcdice/common_command/add_dice/node.rb, line 411 def expr(game_system) times = @times.eval(game_system, nil) sides = eval_sides(game_system) "#{times}D#{sides}" end
include_dice?()
click to toggle source
@return [Boolean]
# File lib/bcdice/common_command/add_dice/node.rb, line 405 def include_dice? true end
output()
click to toggle source
メッセージへの出力を返す @return [String]
# File lib/bcdice/common_command/add_dice/node.rb, line 420 def output @text end
s_exp()
click to toggle source
ノードのS式を返す @return [String]
# File lib/bcdice/common_command/add_dice/node.rb, line 426 def s_exp "(DiceRoll #{@times.s_exp} #{@sides.s_exp})" end
Private Instance Methods
eval_sides(game_system)
click to toggle source
# File lib/bcdice/common_command/add_dice/node.rb, line 432 def eval_sides(game_system) @sides.eval(game_system, nil) end