Module: Api::ActionExtension

Included in:
Action
Defined in:
lib/sc2ai/protocol/extensions/action.rb

Overview

Adds additional functionality and fixes quirks with color specifically pertaining to debug commands

Instance Method Summary collapse

Instance Method Details

#ability_idInteger?

Finds ability_id for the action, if applicable

Returns:

  • (Integer, nil)

    Api::AbilityID::* or nil if n/a



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/sc2ai/protocol/extensions/action.rb', line 43

def ability_id
  if action_type == Api::ActionRaw
    case action_raw.action
    when :unit_command # ActionRawUnitCommand
      return action_raw.unit_command.ability_id
    when :toggle_autocast # ActionRawToggleAutocast
      return action_raw.toggle_autocast.ability_id
    end
  elsif action_type == Api::ActionSpatial && action_ui.action == :unit_command  # ActionSpatialUnitCommand
    return action_ui.unit_command.ability_id
  end

  nil
end

#action_typeClass

Checks the action type and returns corresponding class

Returns:

  • (Class)

    class of type, i.e. Api::ActionRaw



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/sc2ai/protocol/extensions/action.rb', line 6

def action_type
  @action_type ||= if has_action_raw?
    Api::ActionRaw
  elsif has_action_chat?
    Api::ActionChat
  elsif has_action_feature_layer?
    Api::ActionSpatial
  elsif has_action_ui?
    Api::ActionUI
  end
end

#unit_tagsArray<Integer>

Finds unit tags for action, if applicable

Returns:

  • (Array<Integer>)

    an array of unit tags



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/sc2ai/protocol/extensions/action.rb', line 20

def unit_tags
  tags = []
  if action_type == Api::ActionRaw
    case action_raw.action
    when :unit_command # ActionRawUnitCommand
      tags = action_raw.unit_command.unit_tags
    when :toggle_autocast # ActionRawToggleAutocast
      tags = action_raw.toggle_autocast.unit_tags
    end
    # when Api::ActionSpatial
    #   if action == :unit_command # ActionSpatialUnitCommand
    #     # For spatial unit commands, one _could_ assume the errors came from
    #     # the last selected allied units on the previous frame.
    #     # Since we don't have bot access here, leaving this empty.
    #     # tags = @bot.previous.all_units.owned.select(&:is_selected).tags
    #   end
  end

  tags
end