Module: Natural20::AttackHelper
- Included in:
- AttackAction, MagicMissile, SpellAttackHelper
- Defined in:
- lib/natural_20/concerns/attack_helper.rb
Overview
Helper module for utilities in computing attacks
Instance Method Summary collapse
-
#after_attack_roll_hook(battle, target, source, attack_roll, effective_ac, opts = {}) ⇒ Object
Handles after attack event hooks.
-
#calculate_cover_ac(map, target) ⇒ Integer
Computes cover armor class adjustment.
- #effective_ac(battle, target) ⇒ Object
Instance Method Details
#after_attack_roll_hook(battle, target, source, attack_roll, effective_ac, opts = {}) ⇒ Object
Handles after attack event hooks
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/natural_20/concerns/attack_helper.rb', line 7 def after_attack_roll_hook(battle, target, source, attack_roll, effective_ac, opts = {}) force_miss = false # check prepared spells of target for a possible reaction events = target.prepared_spells.map do |spell| spell_details = battle.session.load_spell(spell) _qty, resource = spell_details[:casting_time].split(':') next unless target.has_reaction?(battle) next unless resource == 'reaction' spell_class = spell_details[:spell_class].constantize next unless spell_class.respond_to?(:after_attack_roll) result, force_miss_result = spell_class.after_attack_roll(battle, target, source, attack_roll, effective_ac, opts) force_miss = true if force_miss_result == :force_miss result end.flatten.compact events.each do |item| Natural20::Action.descendants.each do |klass| klass.apply!(battle, item) end end force_miss end |
#calculate_cover_ac(map, target) ⇒ Integer
Computes cover armor class adjustment
50 51 52 |
# File 'lib/natural_20/concerns/attack_helper.rb', line 50 def calculate_cover_ac(map, target) cover_calculation(map, @source, target) end |
#effective_ac(battle, target) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/natural_20/concerns/attack_helper.rb', line 35 def effective_ac(battle, target) cover_ac_adjustments = 0 ac = if battle.map cover_ac_adjustments = calculate_cover_ac(battle.map, target) target.armor_class + cover_ac_adjustments # calculate AC with cover else target.armor_class end [ac, cover_ac_adjustments] end |