Class: SecondWindAction

Inherits:
Natural20::Action show all
Defined in:
lib/natural_20/concerns/fighter_actions/second_wind_action.rb

Overview

typed: true

Instance Attribute Summary

Attributes inherited from Natural20::Action

#action_type, #errors, #result, #session, #source

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Natural20::Action

#initialize, #name, #to_s, #validate

Constructor Details

This class inherits a constructor from Natural20::Action

Class Method Details

.apply!(battle, item) ⇒ Object



36
37
38
39
40
41
42
43
44
# 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) ⇒ Object



19
20
21
22
# 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) ⇒ Boolean

Returns:

  • (Boolean)


3
4
5
# 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) ⇒ Object



46
47
48
# 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

Instance Method Details

#build_mapObject



11
12
13
14
15
16
17
# 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

#labelObject



7
8
9
# File 'lib/natural_20/concerns/fighter_actions/second_wind_action.rb', line 7

def label
  'Second Wind'
end

#resolve(_session, _map, opts = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# 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