Class: FifthedSim::AdditionNode
Instance Method Summary
collapse
#*, #-, #/, #difference_from_average, #max, #min, #or_greater, #or_least, #percentile, #range, #test_then, #to_dice_expression, #to_f, #to_i
Constructor Details
Returns a new instance of AdditionNode.
8
9
10
11
|
# File 'lib/fifthed_sim/nodes/addition_node.rb', line 8
def initialize(*values)
values.each(&method(:check_type))
@components = values.flatten
end
|
Instance Method Details
#+(other) ⇒ Object
13
14
15
16
|
# File 'lib/fifthed_sim/nodes/addition_node.rb', line 13
def +(other)
check_type(other)
self.class.new(*@components, other)
end
|
#average ⇒ Object
28
29
30
|
# File 'lib/fifthed_sim/nodes/addition_node.rb', line 28
def average
@components.map{|x| x.average}.inject(:+)
end
|
#dice ⇒ Object
24
25
26
|
# File 'lib/fifthed_sim/nodes/addition_node.rb', line 24
def dice
self.class.new(*@components.find_all{|x| x.is_a?(RollNode)})
end
|
#distribution ⇒ Object
40
41
42
43
44
45
|
# File 'lib/fifthed_sim/nodes/addition_node.rb', line 40
def distribution
@components.map{|x| x.distribution}.inject do |memo, p|
memo.convolve(p)
end
end
|
#expression_equation ⇒ Object
59
60
61
62
63
|
# File 'lib/fifthed_sim/nodes/addition_node.rb', line 59
def expression_equation
"(" + @components.map do |c|
c.expression_equation
end.inject{|m, x| m + "+ #{x}"} + ")"
end
|
#has_crit? ⇒ Boolean
36
37
38
|
# File 'lib/fifthed_sim/nodes/addition_node.rb', line 36
def has_crit?
@components.any?{|x| x.has_crit?}
end
|
#has_critfail? ⇒ Boolean
32
33
34
|
# File 'lib/fifthed_sim/nodes/addition_node.rb', line 32
def has_critfail?
@components.any?{|x| x.has_critfail?}
end
|
#reroll ⇒ Object
47
48
49
|
# File 'lib/fifthed_sim/nodes/addition_node.rb', line 47
def reroll
self.class.new(*@components.map{|x| x.reroll})
end
|
#value ⇒ Object
18
19
20
21
22
|
# File 'lib/fifthed_sim/nodes/addition_node.rb', line 18
def value
@components.map{|x| x.value}.inject(:+)
end
|
#value_equation(terminal: false) ⇒ Object
52
53
54
55
56
57
|
# File 'lib/fifthed_sim/nodes/addition_node.rb', line 52
def value_equation(terminal: false)
arglist = @components.map do |c|
c.value_equation(terminal: terminal)
end.inject{|m, x| m + "+ #{x}"}
"(#{arglist})"
end
|