Class: TF2LineParser::Events::Damage

Inherits:
Event
  • Object
show all
Defined in:
lib/tf2_line_parser/events/damage.rb

Direct Known Subclasses

Airshot, HeadshotDamage

Instance Attribute Summary collapse

Attributes inherited from Event

#airshot, #cap_name, #cap_number, #customkill, #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 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, headshot) ⇒ Damage

Returns a new instance of Damage.



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/tf2_line_parser/events/damage.rb', line 63

def initialize(time, player_name, player_uid, player_steamid, player_team, target_name, target_uid, target_steamid, target_team, value, realdamage, weapon, healing, crit, headshot)
  @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 = (headshot == '1') if headshot
end

Instance Attribute Details

#critObject (readonly)

Returns the value of attribute crit.



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

def crit
  @crit
end

#damageObject (readonly)

Returns the value of attribute damage.



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

def damage
  @damage
end

#headshotObject (readonly)

Returns the value of attribute headshot.



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

def headshot
  @headshot
end

#healingObject (readonly)

Returns the value of attribute healing.



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

def healing
  @healing
end

#realdamageObject (readonly)

Returns the value of attribute realdamage.



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

def realdamage
  @realdamage
end

Class Method Details

.attributesObject



36
37
38
# File 'lib/tf2_line_parser/events/damage.rb', line 36

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

.regexObject



8
9
10
# File 'lib/tf2_line_parser/events/damage.rb', line 8

def self.regex
  @regex ||= /#{regex_time} #{regex_player} triggered "damage" #{regex_damage_against}\(damage "(?'value'\d+)"\)#{regex_realdamage}#{regex_weapon}#{regex_healing}#{regex_crit}#{regex_headshot}/.freeze
end

.regex_critObject



28
29
30
# File 'lib/tf2_line_parser/events/damage.rb', line 28

def self.regex_crit
  @regex_crit ||= /(?: \(crit "(?'crit'[^"]*)"\))?/.freeze
end

.regex_damage_againstObject



12
13
14
# File 'lib/tf2_line_parser/events/damage.rb', line 12

def self.regex_damage_against
  @regex_damage_against ||= /(against #{regex_target} )?/.freeze
end

.regex_headshotObject



32
33
34
# File 'lib/tf2_line_parser/events/damage.rb', line 32

def self.regex_headshot
  @regex_headshot ||= /(?: \(headshot "(?'headshot'\d*)"\))?/.freeze
end

.regex_healingObject



24
25
26
# File 'lib/tf2_line_parser/events/damage.rb', line 24

def self.regex_healing
  @regex_healing ||= /(?: \(healing "(?'healing'\d*)"\))?/.freeze
end

.regex_realdamageObject



16
17
18
# File 'lib/tf2_line_parser/events/damage.rb', line 16

def self.regex_realdamage
  @regex_realdamage ||= /(?: \(realdamage "(?'realdamage'\d*)"\))?/.freeze
end

.regex_results(matched_line) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/tf2_line_parser/events/damage.rb', line 40

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']
  headshot = matched_line['headshot']

  # 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, headshot]
end

.regex_weaponObject



20
21
22
# File 'lib/tf2_line_parser/events/damage.rb', line 20

def self.regex_weapon
  @regex_weapon ||= /(?: \(weapon "(?'weapon'[^"]*)"\))?/.freeze
end