class FifthedSim::Attack
Model an attack vs AC
Public Class Methods
define(name, &block)
click to toggle source
# File lib/fifthed_sim/attack.rb, line 53 def self.define(name, &block) d = DefinitionProxy.new(name, &block) self.new(d.attrs) end
new(attrs)
click to toggle source
# File lib/fifthed_sim/attack.rb, line 58 def initialize(attrs) @name = attrs[:name] @to_hit = attrs[:to_hit] @damage = attrs[:damage] @crit_threshold = attrs[:crit_threshold] @crit_damage = attrs[:crit_damage] end
Public Instance Methods
against(other)
click to toggle source
# File lib/fifthed_sim/attack.rb, line 70 def against(other) hit_roll.test_then do |res| if res < other.ac 0.to_dice_expression elsif res > other.ac && res < (@crit_threshold + @to_hit) @damage.to(other) else @crit_damage.to(other) end end end
hit_roll()
click to toggle source
# File lib/fifthed_sim/attack.rb, line 66 def hit_roll 1.d(20) + @to_hit end
raw_damage()
click to toggle source
# File lib/fifthed_sim/attack.rb, line 82 def raw_damage @damage.raw end