class BCDice::CommonCommand::AddDice::Node::DiceRollWithFilter

フィルタ処理付きダイスロールのノード。

ダイスロール後、条件に従って出目を選択し、和を求める。

Constants

DROP_HIGHEST

大きな出目から複数個除く

DROP_LOWEST

小さな出目から複数個除く

Filter

フィルタの構造体

各フィルタには、あらかじめソートされた出目の配列が渡される。

@!attribute abbr

@return [Symbol] フィルタの略称

@!attribute apply

@return [Proc] フィルタ処理の内容
KEEP_HIGHEST

大きな出目から複数個取る

KEEP_LOWEST

小さな出目から複数個取る

Public Class Methods

new(times, sides, n_filtering, filter) click to toggle source

ノードを初期化する @param [Object] times ダイスを振る回数のノード @param [Object] sides ダイスの面数のノード @param [Object] n_filtering ダイスを残す/減らす個数のノード @param [Filter] filter フィルタ

# File lib/bcdice/common_command/add_dice/node.rb, line 499
def initialize(times, sides, n_filtering, filter)
  @times = times
  @sides = sides
  @n_filtering = n_filtering
  @filter = filter

  # ダイスを振った結果の出力
  @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 516
def eval(game_system, randomizer)
  times = @times.eval(game_system, nil)
  sides = @sides.eval(game_system, nil)
  n_filtering = @n_filtering.eval(game_system, nil)

  sorted_values = randomizer.roll(times, sides).sort
  total = @filter
          .apply[sorted_values, n_filtering]
          .sum()

  @text = "#{total}[#{sorted_values.join(',')}]"

  return total
end
expr(game_system) click to toggle source

文字列に変換する @return [String]

# File lib/bcdice/common_command/add_dice/node.rb, line 538
def expr(game_system)
  times = @times.eval(game_system, nil)
  sides = @sides.eval(game_system, nil)
  n_filtering = @n_filtering.eval(game_system, nil)

  "#{times}D#{sides}#{@filter.abbr}#{n_filtering}"
end
include_dice?() click to toggle source

@return [Boolean]

# File lib/bcdice/common_command/add_dice/node.rb, line 532
def include_dice?
  true
end
output() click to toggle source

メッセージへの出力を返す @return [String]

# File lib/bcdice/common_command/add_dice/node.rb, line 548
def output
  @text
end
s_exp() click to toggle source

ノードのS式を返す @return [String]

# File lib/bcdice/common_command/add_dice/node.rb, line 554
def s_exp
  "(DiceRollWithFilter #{@times.s_exp} #{@sides.s_exp} #{@filter.abbr.inspect} #{@n_filtering.s_exp})"
end