Class: DashAction

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

Overview

typed: true

Direct Known Subclasses

DashBonusAction

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.



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

def as_bonus_action
  @as_bonus_action
end

Class Method Details

.apply!(battle, item) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/natural_20/actions/dash_action.rb', line 25

def self.apply!(battle, item)
  case item[:type]
  when :dash
    Natural20::EventManager.received_event({ source: item[:source], event: :dash })
    battle.entity_state_for(item[:source])[:movement] += item[:source].speed
    if as_bonus_action
      battle.entity_state_for(item[:source])[:bonus_action] -= 1
    else
      battle.entity_state_for(item[:source])[:action] -= 1
    end
  end
end

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

Returns:

  • (Boolean)


12
13
14
# File 'lib/natural_20/actions/dash_action.rb', line 12

def self.can?(entity, battle, _options = {})
  battle && entity.total_actions(battle).positive?
end

Instance Method Details

#build_mapObject



5
6
7
8
9
10
# File 'lib/natural_20/actions/dash_action.rb', line 5

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

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



16
17
18
19
20
21
22
23
# File 'lib/natural_20/actions/dash_action.rb', line 16

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