Class: ShortRestAction

Inherits:
Natural20::Action show all
Defined in:
lib/natural_20/actions/short_rest_action.rb

Instance Attribute Summary collapse

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, #label, #name, #to_s, #validate

Constructor Details

This class inherits a constructor from Natural20::Action

Instance Attribute Details

#as_bonus_actionObject

Returns the value of attribute as_bonus_action.



2
3
4
# File 'lib/natural_20/actions/short_rest_action.rb', line 2

def as_bonus_action
  @as_bonus_action
end

Class Method Details

.apply!(battle, item) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/natural_20/actions/short_rest_action.rb', line 42

def self.apply!(battle, item)
  case (item[:type])
  when :short_rest
    Natural20::EventManager.received_event({ source: item[:source], event: :short_rest, targets: item[:targets] })
    item[:targets].each do |entity|
      entity.short_rest!(battle, prompt: true)
    end
    battle.session.increment_game_time!(60 * 60) # increment by an hour
  end
end

.build(session, source) ⇒ Object



17
18
19
20
# File 'lib/natural_20/actions/short_rest_action.rb', line 17

def self.build(session, source)
  action = ShortRestAction.new(session, source, :short_rest)
  action.build_map
end

.can?(entity, battle) ⇒ Boolean



6
7
8
# File 'lib/natural_20/actions/short_rest_action.rb', line 6

def self.can?(entity, battle)
  battle && !battle.combat? && (entity.conscious? || entity.stable?)
end

Instance Method Details

#build_mapObject



10
11
12
13
14
15
# File 'lib/natural_20/actions/short_rest_action.rb', line 10

def build_map
  OpenStruct.new({
                   param: nil,
                   next: -> { self }
                 })
end

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

Options Hash (opts):



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/natural_20/actions/short_rest_action.rb', line 23

def resolve(_session, _map, opts = {})
  battle = opts[:battle]

  # determine who in the party is eligible for short rest
  entities = battle.current_party.select do |entity|
    entity.conscious? || entity.stable?
  end

  @result = [{
    source: @source,
    targets: entities,
    type: :short_rest,
    battle: battle
  }]

  self
end