Class: DropGrappleAction

Inherits:
Natural20::Action show all
Defined in:
lib/natural_20/actions/grapple_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, #validate

Constructor Details

This class inherits a constructor from Natural20::Action

Instance Attribute Details

#targetObject

Returns the value of attribute target.



119
120
121
# File 'lib/natural_20/actions/grapple_action.rb', line 119

def target
  @target
end

Class Method Details

.apply!(_battle, item) ⇒ Object



170
171
172
173
174
175
176
177
178
179
180
# File 'lib/natural_20/actions/grapple_action.rb', line 170

def self.apply!(_battle, item)
  case item[:type]
  when :drop_grapple
    item[:target].escape_grapple_from!(item[:source])
    Natural20::EventManager.received_event(event: :drop_grapple,
                                           target: item[:target], source: item[:source],
                                           source_roll: item[:source_roll],
                                           target_roll: item[:target_roll])

  end
end

.build(session, source) ⇒ Object



149
150
151
152
# File 'lib/natural_20/actions/grapple_action.rb', line 149

def self.build(session, source)
  action = DropGrappleAction.new(session, source, :grapple)
  action.build_map
end

.can?(entity, battle, _options = {}) ⇒ Boolean

Returns:

  • (Boolean)


121
122
123
# File 'lib/natural_20/actions/grapple_action.rb', line 121

def self.can?(entity, battle, _options = {})
  battle.nil? || entity.grappling?
end

Instance Method Details

#build_mapObject



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/natural_20/actions/grapple_action.rb', line 129

def build_map
  OpenStruct.new({
                   action: self,
                   param: [
                     {
                       type: :select_target,
                       targets: @source.grappling_targets,
                       num: 1
                     }
                   ],
                   next: lambda { |target|
                     self.target = target
                     OpenStruct.new({
                                      param: nil,
                                      next: -> { self }
                                    })
                   }
                 })
end

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

Parameters:

Options Hash (opts):



158
159
160
161
162
163
164
165
166
167
168
# File 'lib/natural_20/actions/grapple_action.rb', line 158

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

#to_sObject



125
126
127
# File 'lib/natural_20/actions/grapple_action.rb', line 125

def to_s
  @action_type.to_s.humanize
end