Class: EscapeGrappleAction

Inherits:
Natural20::Action show all
Defined in:
lib/natural_20/actions/escape_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.



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

def target
  @target
end

Class Method Details

.apply!(battle, item) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/natural_20/actions/escape_grapple_action.rb', line 76

def self.apply!(battle, item)
  case (item[:type])
  when :grapple_escape
    if item[:success]
      item[:source].escape_grapple_from!(item[:target])
      Natural20::EventManager.received_event(event: :escape_grapple_success,
                                             target: item[:target], source: item[:source],
                                             source_roll: item[:source_roll],
                                             target_roll: item[:target_roll])
    else
      Natural20::EventManager.received_event(event: :escape_grapple_failure,
                                             target: item[:target], source: item[:source],
                                             source_roll: item[:source_roll],
                                             target_roll: item[:target_roll])
    end

    battle.consume(item[:source], :action)
  end
end

.build(session, source) ⇒ Object



32
33
34
35
# File 'lib/natural_20/actions/escape_grapple_action.rb', line 32

def self.build(session, source)
  action = EscapeGrappleAction.new(session, source, :escape_grapple)
  action.build_map
end

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

Returns:

  • (Boolean)


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

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

Instance Method Details

#build_mapObject



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

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

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

Build the attack roll information

Parameters:

Options Hash (opts):



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/natural_20/actions/escape_grapple_action.rb', line 42

def resolve(_session, _map, opts = {})
  battle = opts[:battle]
  target = @source.grapples.first

  strength_roll = target.athletics_check!(battle)
  athletics_stats = (@source.athletics_proficient? ? @source.proficiency_bonus : 0) + @source.str_mod
  acrobatics_stats = (@source.acrobatics_proficient? ? @source.proficiency_bonus : 0) + @source.dex_mod

  contested_roll = athletics_stats > acrobatics_stats ? @source.athletics_check!(battle) : @source.acrobatics_check!(battle)
  grapple_success = strength_roll.result >= contested_roll.result

  @result = if grapple_success
              [{
                source: @source,
                target: target,
                type: :grapple_escape,
                success: true,
                battle: battle,
                source_roll: contested_roll,
                target_roll: strength_roll
              }]
            else
              [{
                source: @source,
                target: target,
                type: :grapple_escape,
                success: false,
                battle: battle,
                source_roll: contested_roll,
                target_roll: strength_roll
              }]
            end
end

#to_sObject



8
9
10
# File 'lib/natural_20/actions/escape_grapple_action.rb', line 8

def to_s
  @action_type.to_s.humanize
end