Class: HideAction

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

Direct Known Subclasses

HideBonusAction

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/hide_action.rb', line 2

def as_bonus_action
  @as_bonus_action
end

Class Method Details

.apply!(battle, item) ⇒ Object

Parameters:



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/natural_20/actions/hide_action.rb', line 33

def self.apply!(battle, item)
  case (item[:type])
  when :hide
    Natural20::EventManager.received_event({ source: item[:source], roll: item[:roll], event: :hide })
    item[:source].hiding!(battle, item[:roll].result)
    if item[:bonus_action]
      battle.consume(item[:source], :bonus_action)
    else
      battle.consume(item[:source], :action)
    end
  end
end

.build(session, source) ⇒ Object



15
16
17
18
# File 'lib/natural_20/actions/hide_action.rb', line 15

def self.build(session, source)
  action = HideAction.new(session, source, :attack)
  action.build_map
end

.can?(entity, battle) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
# File 'lib/natural_20/actions/hide_action.rb', line 4

def self.can?(entity, battle)
  battle && entity.total_actions(battle).positive?
end

Instance Method Details

#build_mapObject



8
9
10
11
12
13
# File 'lib/natural_20/actions/hide_action.rb', line 8

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

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



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/natural_20/actions/hide_action.rb', line 20

def resolve(_session, _map, opts = {})
  stealth_roll = @source.stealth_check!(opts[:battle])
  @result = [{
    source: @source,
    bonus_action: as_bonus_action,
    type: :hide,
    roll: stealth_roll,
    battle: opts[:battle]
  }]
  self
end