Class: Natural20::Shield

Inherits:
Spell
  • Object
show all
Defined in:
lib/natural_20/spell_library/shield.rb

Instance Attribute Summary

Attributes inherited from Spell

#errors, #properties, #source

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Spell

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

Constructor Details

This class inherits a constructor from Natural20::Spell

Class Method Details

.ac_bonus(_entity, _effect) ⇒ Object

Parameters:



29
30
31
# File 'lib/natural_20/spell_library/shield.rb', line 29

def self.ac_bonus(_entity, _effect)
  5
end

.after_attack_roll(battle, entity, _attacker, attack_roll, effective_ac, opts = {}) ⇒ Array<Array<Hash>,Symbol>

Parameters:

Returns:

  • (Array<Array<Hash>,Symbol>)


42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/natural_20/spell_library/shield.rb', line 42

def self.after_attack_roll(battle, entity, _attacker, attack_roll, effective_ac, opts = {})
  spell = battle.session.load_spell('shield')
  if attack_roll.nil? || attack_roll.result.between?(entity.armor_class, effective_ac + 4)
    [[{
      type: :shield,
      target: entity,
      source: entity,
      effect: Natural20::Shield.new(entity, 'shield', spell),
      spell: spell
    }], false]
  else
    [[], false]
  end
end

.apply!(battle, item) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/natural_20/spell_library/shield.rb', line 11

def self.apply!(battle, item)
  case item[:type]
  when :shield

    item[:source].add_casted_effect(effect: item[:effect])
    item[:target].register_effect(:ac_bonus, self, effect: item[:effect], source: item[:source],
                                                   duration: 8.hours.to_i)

    item[:target].register_event_hook(:start_of_turn, self, effect: item[:effect], effect: item[:effect],
                                                            source: item[:source])
    Natural20::EventManager.received_event(event: :spell_buf, spell: item[:effect], source: item[:source],
                                           target: item[:source])
    SpellAction.consume_resource(battle, item)
  end
end

.start_of_turn(entity, opts = {}) ⇒ Object



33
34
35
# File 'lib/natural_20/spell_library/shield.rb', line 33

def self.start_of_turn(entity, opts = {})
  entity.dismiss_effect!(opts[:effect])
end

Instance Method Details

#build_map(action) ⇒ Object



2
3
4
5
6
7
8
9
# File 'lib/natural_20/spell_library/shield.rb', line 2

def build_map(action)
  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)


60
61
62
63
64
65
66
67
68
# File 'lib/natural_20/spell_library/shield.rb', line 60

def resolve(_entity, _battle, spell_action)
  [{
    type: :shield,
    target: spell_action.source,
    source: spell_action.source,
    effect: self,
    spell: @properties
  }]
end