Class: FifthedSim::Attack
- Inherits:
-
Object
- Object
- FifthedSim::Attack
- Defined in:
- lib/fifthed_sim/attack.rb
Overview
Model an attack vs AC
Defined Under Namespace
Classes: DefinitionProxy
Class Method Summary collapse
Instance Method Summary collapse
- #against(other) ⇒ Object
- #hit_roll ⇒ Object
-
#initialize(attrs) ⇒ Attack
constructor
A new instance of Attack.
- #raw_damage ⇒ Object
Constructor Details
#initialize(attrs) ⇒ Attack
Returns a new instance of Attack.
58 59 60 61 62 63 64 |
# 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 |
Class Method Details
.define(name, &block) ⇒ Object
53 54 55 56 |
# File 'lib/fifthed_sim/attack.rb', line 53 def self.define(name, &block) d = DefinitionProxy.new(name, &block) self.new(d.attrs) end |
Instance Method Details
#against(other) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 |
# 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 ⇒ Object
66 67 68 |
# File 'lib/fifthed_sim/attack.rb', line 66 def hit_roll 1.d(20) + @to_hit end |
#raw_damage ⇒ Object
82 83 84 |
# File 'lib/fifthed_sim/attack.rb', line 82 def raw_damage @damage.raw end |