Class: BCDice::GameSystem::FilledWith::FW

Inherits:
Object
  • Object
show all
Defined in:
lib/bcdice/game_system/FilledWith.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFW

Returns a new instance of FW.



124
125
126
# File 'lib/bcdice/game_system/FilledWith.rb', line 124

def initialize
  @target = nil
end

Instance Attribute Details

#criticalObject

Returns the value of attribute critical.



122
123
124
# File 'lib/bcdice/game_system/FilledWith.rb', line 122

def critical
  @critical
end

#dice_countObject

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

#fumbleObject

Returns the value of attribute fumble.



122
123
124
# File 'lib/bcdice/game_system/FilledWith.rb', line 122

def fumble
  @fumble
end

#targetObject

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



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/bcdice/game_system/FilledWith.rb', line 134

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



128
129
130
131
132
# File 'lib/bcdice/game_system/FilledWith.rb', line 128

def self.roll(command, randomizer)
  fw = parse(command)

  return fw&.roll(randomizer)
end

Instance Method Details

#roll(randomizer) ⇒ Object



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/bcdice/game_system/FilledWith.rb', line 152

def roll(randomizer)
  dice_list = randomizer.roll_barabara(@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