Class: BCDice::GameSystem::FilledWith::FW
- Inherits:
-
Object
- Object
- BCDice::GameSystem::FilledWith::FW
- Defined in:
- lib/bcdice/game_system/FilledWith.rb
Instance Attribute Summary collapse
-
#critical ⇒ Object
Returns the value of attribute critical.
-
#dice_count ⇒ Object
Returns the value of attribute dice_count.
-
#fumble ⇒ Object
Returns the value of attribute fumble.
-
#target ⇒ Object
Returns the value of attribute target.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#critical ⇒ Object
Returns the value of attribute critical.
122 123 124 |
# File 'lib/bcdice/game_system/FilledWith.rb', line 122 def critical @critical end |
#dice_count ⇒ Object
Returns the value of attribute dice_count.
122 123 124 |
# File 'lib/bcdice/game_system/FilledWith.rb', line 122 def dice_count @dice_count end |
#fumble ⇒ Object
Returns the value of attribute fumble.
122 123 124 |
# File 'lib/bcdice/game_system/FilledWith.rb', line 122 def fumble @fumble end |
#target ⇒ Object
Returns the value of attribute target.
122 123 124 |
# File 'lib/bcdice/game_system/FilledWith.rb', line 122 def target @target end |
Class Method Details
.parse(command) ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/bcdice/game_system/FilledWith.rb', line 130 def self.parse(command) if (m = /^(\d[+\-\d]*)-(\d+)FW(?:@(\d+))?(?:\#(\d+))?$/.match(command)) new.tap do |fw| fw.dice_count = m[2].to_i fw.target = Arithmetic.eval(m[1], RoundType::FLOOR) fw.critical = m[3]&.to_i || 4 fw.fumble = m[4]&.to_i || 17 end elsif (m = /(\d+)FW(?:@(\d+))?(?:\#(\d+))?(?:<=([+\-\d]+))?/.match(command)) new.tap do |fw| fw.dice_count = m[1].to_i fw.target = Arithmetic.eval(m[4], RoundType::FLOOR) if m[4] fw.critical = m[2]&.to_i || 4 fw.fumble = m[3]&.to_i || 17 end end end |
.roll(command, randomizer) ⇒ Object
124 125 126 127 128 |
# File 'lib/bcdice/game_system/FilledWith.rb', line 124 def self.roll(command, randomizer) fw = parse(command) return fw&.roll(randomizer) end |
Instance Method Details
#roll(randomizer) ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/bcdice/game_system/FilledWith.rb', line 148 def roll(randomizer) dice_list = randomizer.(@dice_count, 6) dice = dice_list.sum() dice_str = dice_list.join(",") res = result(dice) sequence = [ "(#{expr})", "#{dice}[#{dice_str}]", res.text, ].compact res.text = sequence.join(" > ") return res end |