Class: HelpAction

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

Overview

typed: true

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

#targetObject

Returns the value of attribute target.



3
4
5
# File 'lib/natural_20/actions/help_action.rb', line 3

def target
  @target
end

Class Method Details

.apply!(battle, item) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/natural_20/actions/help_action.rb', line 45

def self.apply!(battle, item)
  case item[:type]
  when :help
    Natural20::EventManager.received_event({ source: item[:source], target: item[:target], event: :help })
    item[:source].help!(item[:battle], item[:target])
    battle.consume!(item[:source], :action)
  end
end

.build(session, source) ⇒ Object



30
31
32
33
# File 'lib/natural_20/actions/help_action.rb', line 30

def self.build(session, source)
  action = HelpAction.new(session, source, :help)
  action.build_map
end

.can?(entity, battle) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/natural_20/actions/help_action.rb', line 5

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

Instance Method Details

#build_mapObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/natural_20/actions/help_action.rb', line 9

def build_map
  OpenStruct.new({
                   action: self,
                   param: [
                     {
                       type: :select_target,
                       target_types: %i[allies enemies],
                       range: 5,
                       num: 1
                     }
                   ],
                   next: lambda { |target|
                     self.target = target
                     OpenStruct.new({
                                      param: nil,
                                      next: -> { self }
                                    })
                   }
                 })
end

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



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

def resolve(_session, _map, opts = {})
  @result = [{
    source: @source,
    target: @target,
    type: :help,
    battle: opts[:battle]
  }]
  self
end