Class: Natural20::Firebolt

Inherits:
Spell
  • Object
show all
Includes:
Cover, SpellAttackHelper, Weapons
Defined in:
lib/natural_20/spell_library/firebolt.rb

Instance Attribute Summary

Attributes inherited from Spell

#errors, #properties, #source

Instance Method Summary collapse

Methods included from SpellAttackHelper

#evaluate_spell_attack

Methods included from AttackHelper

#after_attack_roll_hook, #calculate_cover_ac, #effective_ac

Methods included from Cover

#cover_calculation

Methods included from Weapons

#compute_advantages_and_disadvantages, #damage_modifier, #target_advantage_condition

Methods inherited from Spell

apply!, #id, #initialize, #label, #validate!

Constructor Details

This class inherits a constructor from Natural20::Spell

Instance Method Details

#build_map(action) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/natural_20/spell_library/firebolt.rb', line 6

def build_map(action)
  OpenStruct.new({
                   param: [
                     {
                       type: :select_target,
                       num: 1,
                       range: @properties[:range],
                       target_types: i[enemies]
                     }
                   ],
                   next: lambda { |target|
                           action.target = target
                           OpenStruct.new({
                                            param: nil,
                                            next: lambda {
                                                    action
                                                  }
                                          })
                         }
                 })
end

#resolve(entity, battle, spell_action) ⇒ Object

Parameters:

  • entity (Natural20::Entity)
  • battle (Natrual20::Battle)
  • spell_action (Natural20::SpellAction)


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/natural_20/spell_library/firebolt.rb', line 31

def resolve(entity, battle, spell_action)
  target = spell_action.target

  hit, attack_roll, advantage_mod, cover_ac_adjustments = evaluate_spell_attack(battle, entity, target, @properties)

  if hit
    level = 1
    level += 1 if entity.level >= 5
    level += 1 if entity.level >= 11
    level += 1 if entity.level >= 17

    damage_roll = Natural20::DieRoll.roll("#{level}d10", crit: attack_roll.nat_20?, battle: battle, entity: entity,
                                                         description: t('dice_roll.spells.firebolt'))
    [{
      source: entity,
      target: target,
      attack_name: t('spell.firebolt'),
      damage_type: @properties[:damage_type],
      attack_roll: attack_roll,
      damage_roll: damage_roll,
      advantage_mod: advantage_mod,
      damage: damage_roll,
      cover_ac: cover_ac_adjustments,
      type: :spell_damage,
      spell: @properties
    }]
  else
    [{
      type: :spell_miss,
      source: entity,
      target: target,
      attack_name: t('spell.firebolt'),
      damage_type: @properties[:damage_type],
      attack_roll: attack_roll,
      damage_roll: damage_roll,
      advantage_mod: advantage_mod,
      cover_ac: cover_ac_adjustments,
      spell: @properties
    }]
  end
end