Class: BCDice::CommonCommand::UpperDice::Node::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/bcdice/common_command/upper_dice/node.rb

Instance Method Summary collapse

Constructor Details

#initialize(secret:, notations:, modifier:, cmp_op:, target_number:, reroll_threshold: nil) ⇒ Command

Returns a new instance of Command.

Parameters:

  • secret (Boolean)
  • notations (Array<Notation>)
  • modifier (Integer)
  • cmp_op (Symbol, nil)
  • target_number (Integer, nil)
  • reroll_threshold (Integer) (defaults to: nil)


14
15
16
17
18
19
20
21
# File 'lib/bcdice/common_command/upper_dice/node.rb', line 14

def initialize(secret:, notations:, modifier:, cmp_op:, target_number:, reroll_threshold: nil)
  @secret = secret
  @notations = notations
  @modifier = modifier
  @cmp_op = cmp_op
  @target_number = target_number
  @reroll_threshold = reroll_threshold
end

Instance Method Details

#eval(game_system, randomizer) ⇒ Result?

上方無限ロールを実行する

Parameters:

Returns:



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/bcdice/common_command/upper_dice/node.rb', line 27

def eval(game_system, randomizer)
  round_type = game_system.round_type

  dice_list = @notations.map { |n| n.to_dice(round_type) }
  reroll_threshold = @reroll_threshold&.eval(round_type) || game_system.upper_dice_reroll_threshold || 0
  modifier = @modifier&.eval(round_type) || 0
  target_number = @target_number&.eval(round_type)

  expr = expr(dice_list, reroll_threshold, modifier, target_number)

  if reroll_threshold <= 1
    return result_with_text("(#{expr}) > 無限ロールの条件がまちがっています")
  end

  roll_list = dice_list.map do |n|
    n.roll(randomizer, reroll_threshold, game_system.sort_barabara_dice?)
  end.reduce([], :concat)

  result =
    if @cmp_op
      result_success_count(roll_list, modifier, target_number)
    else
      result_max_sum(roll_list, modifier)
    end

  sequence = [
    "(#{expr})",
    interlim_expr(roll_list, modifier),
    result
  ]

  result_with_text(sequence.join(""))
end