Class: BCDice::GameSystem::EdgeFlippers::HSCommand
- Inherits:
-
Object
- Object
- BCDice::GameSystem::EdgeFlippers::HSCommand
- Defined in:
- lib/bcdice/game_system/EdgeFlippers.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(h, s, targets, same_value) ⇒ HSCommand
constructor
A new instance of HSCommand.
- #roll(randomizer) ⇒ Object
Constructor Details
#initialize(h, s, targets, same_value) ⇒ HSCommand
Returns a new instance of HSCommand.
86 87 88 89 90 91 |
# File 'lib/bcdice/game_system/EdgeFlippers.rb', line 86 def initialize(h, s, targets, same_value) @h = h @s = s @targets = targets @same_value = same_value end |
Class Method Details
.parse(command) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/bcdice/game_system/EdgeFlippers.rb', line 61 def parse(command) m = /^(?:(\d+)HD(?:\+(\d+)SD)?|(\d+)SD(?:\+(\d+)HD)?)(?:=(?:([\d,]+)|X(\d+)))?$/.match(command) return nil unless m h = m[1]&.to_i || m[4]&.to_i || 0 s = m[2]&.to_i || m[3]&.to_i || 0 targets = parse_target(m[5]) same_value = m[6]&.to_i if h == 0 && s == 0 return nil end return HSCommand.new(h, s, targets, same_value) end |
Instance Method Details
#roll(randomizer) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/bcdice/game_system/EdgeFlippers.rb', line 93 def roll(randomizer) @hv = randomizer.(@h, 6).sort @sv = randomizer.(@s, 10).sort values = (@hv + @sv).sort @is_success = if @targets subset?(values, @targets) elsif @same_value values.group_by(&:itself).any? { |_k, v| v.length >= @same_value } end Result.new.tap do |r| r.text = [expr(), result_values(), result_label].compact.join(" > ") unless @is_success.nil? r.condition = @is_success end end end |