Class: TF2LineParser::Events::Airshot

Inherits:
Damage show all
Defined in:
lib/tf2_line_parser/events/airshot.rb

Instance Attribute Summary

Attributes inherited from Damage

#crit, #damage, #headshot, #healing, #realdamage

Attributes inherited from Event

#airshot, #cap_name, #cap_number, #customkill, #healing, #item, #length, #message, #method, #player, #role, #score, #target, #team, #time, #type, #ubercharge, #unknown, #value, #weapon

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Damage

regex_crit, regex_damage_against, regex_headshot, regex_healing, regex_realdamage, regex_weapon

Methods inherited from Event

parse_player_section, parse_target_section, #parse_time, regex_cap, regex_console, regex_message, regex_player, regex_target, regex_time, time_format, types

Constructor Details

#initialize(time, player_name, player_uid, player_steamid, player_team, target_name, target_uid, target_steamid, target_team, value, realdamage, weapon, healing, crit, airshot) ⇒ Airshot

Returns a new instance of Airshot.



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/tf2_line_parser/events/airshot.rb', line 46

def initialize(time, player_name, player_uid, player_steamid, player_team, target_name, target_uid, target_steamid, target_team, value, realdamage, weapon, healing, crit, airshot)
  @time = parse_time(time)
  @player = Player.new(player_name, player_uid, player_steamid, player_team)
  @target = Player.new(target_name, target_uid, target_steamid, target_team) if target_name
  @value = value.to_i
  @damage = @value
  @realdamage = realdamage.to_i if realdamage && !realdamage.empty?
  @weapon = weapon
  @healing = healing.to_i if healing
  @crit = crit
  @headshot = nil
  @airshot = (airshot.to_i == 1)
end

Class Method Details

.attributesObject



19
20
21
# File 'lib/tf2_line_parser/events/airshot.rb', line 19

def self.attributes
  @attributes ||= %i[time player_section target_section realdamage weapon healing crit airshot]
end

.regexObject



6
7
8
9
# File 'lib/tf2_line_parser/events/airshot.rb', line 6

def self.regex
  # Airshot can appear after weapon, with optional crit/healing between weapon and airshot
  @regex ||= /#{regex_time} #{regex_player} triggered "damage" #{regex_damage_against}\(damage "(?'value'\d+)"\)#{regex_realdamage}#{regex_weapon}#{regex_healing}#{regex_crit}#{regex_airshot}#{regex_height}/.freeze
end

.regex_airshotObject



11
12
13
# File 'lib/tf2_line_parser/events/airshot.rb', line 11

def self.regex_airshot
  @regex_airshot ||= / \(airshot "(?'airshot'\w*)"\)/
end

.regex_heightObject



15
16
17
# File 'lib/tf2_line_parser/events/airshot.rb', line 15

def self.regex_height
  @regex_height ||= /(?: \(height "(?'height'\d*)"\))?/
end

.regex_results(matched_line) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/tf2_line_parser/events/airshot.rb', line 23

def self.regex_results(matched_line)
  time = matched_line['time']
  player_section = matched_line['player_section']
  target_section = matched_line['target_section']
  value = matched_line['value']
  realdamage = matched_line['realdamage']
  weapon = matched_line['weapon']
  healing = matched_line['healing']
  crit = matched_line['crit']
  airshot = matched_line['airshot']

  # Parse player section
  player_name, player_uid, player_steamid, player_team = parse_player_section(player_section)

  # Parse target section if present
  target_name, target_uid, target_steamid, target_team = nil, nil, nil, nil
  if target_section
    target_name, target_uid, target_steamid, target_team = parse_target_section(target_section)
  end

  [time, player_name, player_uid, player_steamid, player_team, target_name, target_uid, target_steamid, target_team, value, realdamage, weapon, healing, crit, airshot]
end