class Natural20::Shield
Public Class Methods
ac_bonus(_entity, _effect)
click to toggle source
@param entity [Natural20::Entity] @param effect [Object]
# 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 = {})
click to toggle source
@param battle [Natural20::Battle] @param entity [Natural20::Entity] @param attacker [Natural20::Entity] @param attack_roll [Natural20::DieRoll] @return [Array<Array<Hash>,Symbol>]
# 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)
click to toggle source
# 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 = {})
click to toggle source
# File lib/natural_20/spell_library/shield.rb, line 33 def self.start_of_turn(entity, opts = {}) entity.dismiss_effect!(opts[:effect]) end
Public Instance Methods
build_map(action)
click to toggle source
# 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)
click to toggle source
@param entity [Natural20::Entity] @param battle [Natrual20::Battle] @param spell_action [Natural20::SpellAction]
# 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