class SecondWindAction

typed: true

Public Class Methods

apply!(battle, item) click to toggle source
# File lib/natural_20/concerns/fighter_actions/second_wind_action.rb, line 36
def self.apply!(battle, item)
  case (item[:type])
  when :second_wind
    Natural20::EventManager.received_event(action: self.class, source: item[:source], roll: item[:roll],
                                           event: :second_wind)
    item[:source].second_wind!(item[:roll].result)
    battle.entity_state_for(item[:source])[:bonus_action] -= 1
  end
end
build(session, source) click to toggle source
# File lib/natural_20/concerns/fighter_actions/second_wind_action.rb, line 19
def self.build(session, source)
  action = SecondWindAction.new(session, source, :second_wind)
  action.build_map
end
can?(entity, battle) click to toggle source
# File lib/natural_20/concerns/fighter_actions/second_wind_action.rb, line 3
def self.can?(entity, battle)
  (battle.nil? || entity.total_bonus_actions(battle).positive?) && entity.second_wind_count.positive?
end
describe(event) click to toggle source
# File lib/natural_20/concerns/fighter_actions/second_wind_action.rb, line 46
def self.describe(event)
  "#{event[:source].name.colorize(:green)} uses " + 'Second Wind'.colorize(:blue) + " with #{event[:roll]} healing"
end

Public Instance Methods

build_map() click to toggle source
# File lib/natural_20/concerns/fighter_actions/second_wind_action.rb, line 11
def build_map
  OpenStruct.new({
                   action: self,
                   param: nil,
                   next: -> { self }
                 })
end
label() click to toggle source
# File lib/natural_20/concerns/fighter_actions/second_wind_action.rb, line 7
def label
  'Second Wind'
end
resolve(_session, _map, opts = {}) click to toggle source
# File lib/natural_20/concerns/fighter_actions/second_wind_action.rb, line 24
def resolve(_session, _map, opts = {})
  second_wind_roll = Natural20::DieRoll.roll(@source.second_wind_die, description: t('dice_roll.second_wind'),
                                                                      entity: @source, battle: opts[:battle])
  @result = [{
    source: @source,
    roll: second_wind_roll,
    type: :second_wind,
    battle: opts[:battle]
  }]
  self
end