Class: L4D2Stats

Inherits:
GameStats show all
Includes:
AbstractL4DStats
Defined in:
lib/steam/community/l4d/l4d2_stats.rb

Constant Summary collapse

SPECIAL_INFECTED =
SPECIAL_INFECTED + %w{charger jockey spitter}

Instance Attribute Summary

Attributes inherited from GameStats

#app_id, #custom_url, #game_friendly_name, #game_name, #hours_played, #privacy_state, #steam_id64

Instance Method Summary collapse

Methods included from AbstractL4DStats

#favorites, #teamplay_stats, #versus_stats

Methods inherited from GameStats

#achievements, #achievements_done, #achievements_percentage, #base_url, create_game_stats, #public?

Constructor Details

#initialize(steam_id) ⇒ L4D2Stats

Creates a L4D2Stats object by calling the super constructor with the game name “l4d2”



18
19
20
# File 'lib/steam/community/l4d/l4d2_stats.rb', line 18

def initialize(steam_id)
  super steam_id, 'l4d2'
end

Instance Method Details

#lifetime_statsObject

Returns a Hash of lifetime statistics for this user like the time played. If the lifetime statistics haven’t been parsed already, parsing is done now.

There are only a few additional lifetime statistics for Left4Dead 2 which are not generated for Left4Dead, so this calls AbstractL4DStats#lifetime_stats first and adds some additional stats.



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/steam/community/l4d/l4d2_stats.rb', line 28

def lifetime_stats
  return unless public?

  if @lifetime_stats.nil?
    super
    @lifetime_stats['avg_adrenaline_shared']   = @xml_data.elements['stats/lifetime/adrenalineshared'].text.to_f
    @lifetime_stats['avg_adrenaline_used']     = @xml_data.elements['stats/lifetime/adrenalineused'].text.to_f
    @lifetime_stats['avg_defibrillators_used'] = @xml_data.elements['stats/lifetime/defibrillatorsused'].text.to_f
  end

  @lifetime_stats
end

#scavenge_statsObject

Returns a Hash of Scavenge statistics for this user like the number of Scavenge rounds played. If the Scavenge statistics haven’t been parsed already, parsing is done now.



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
75
76
77
78
79
# File 'lib/steam/community/l4d/l4d2_stats.rb', line 44

def scavenge_stats
  return unless public?

  if @scavenge_stats.nil?
    @scavenge_stats = {}
    @scavenge_stats['avg_cans_per_round'] = @xml_data.elements['stats/scavenge/avgcansperround'].text.to_f
    @scavenge_stats['perfect_rounds']     = @xml_data.elements['stats/scavenge/perfect16canrounds'].text.to_i
    @scavenge_stats['rounds_lost']        = @xml_data.elements['stats/scavenge/roundslost'].text.to_i
    @scavenge_stats['rounds_played']      = @xml_data.elements['stats/scavenge/roundsplayed'].text.to_i
    @scavenge_stats['rounds_won']         = @xml_data.elements['stats/scavenge/roundswon'].text.to_i
    @scavenge_stats['total_cans']         = @xml_data.elements['stats/scavenge/totalcans'].text.to_i

    @scavenge_stats['maps'] = {}
    @xml_data.elements.each('stats/scavenge/mapstats/map') do |map_data|
      map_id = map_data.elements['name'].text
      @scavenge_stats['maps'][map_id] = {}
      @scavenge_stats['maps'][map_id]['avg_round_score']     = map_data.elements['avgscoreperround'].text.to_i
      @scavenge_stats['maps'][map_id]['highest_game_score']  = map_data.elements['highgamescore'].text.to_i
      @scavenge_stats['maps'][map_id]['highest_round_score'] = map_data.elements['highroundscore'].text.to_i
      @scavenge_stats['maps'][map_id]['name']                = map_data.elements['fullname'].text
      @scavenge_stats['maps'][map_id]['rounds_played']       = map_data.elements['roundsplayed'].text.to_i
      @scavenge_stats['maps'][map_id]['rounds_won']          = map_data.elements['roundswon'].text.to_i
    end

    @scavenge_stats['infected'] = {}
    @xml_data.elements.each('stats/scavenge/infectedstats/special') do |infected_data|
      infected_id = infected_data.elements['name'].text
      @scavenge_stats['infected'][infected_id] = {}
      @scavenge_stats['infected'][infected_id]['max_damage_per_life']   = infected_data.elements['maxdmg1life'].text.to_i
      @scavenge_stats['infected'][infected_id]['max_pours_interrupted'] = infected_data.elements['maxpoursinterrupted'].text.to_i
      @scavenge_stats['infected'][infected_id]['special_attacks']       = infected_data.elements['specialattacks'].text.to_i
    end
  end

  @scavenge_stats
end

#survival_statsObject

Returns a Hash of Survival statistics for this user like revived teammates. If the Survival statistics haven’t been parsed already, parsing is done now.

The XML layout for the Survival statistics for Left4Dead 2 differs a bit from Left4Dead’s Survival statistics. So we have to use a different way of parsing for the maps and we use a different map class (L4D2Map) which holds the additional information provided in Left4Dead 2’s statistics.



88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/steam/community/l4d/l4d2_stats.rb', line 88

def survival_stats
  return unless public?

  if @survival_stats.nil?
    super
    @survival_stats['maps'] = {}
    @xml_data.elements.each('stats/survival/maps/map') do |map_data|
      map = L4D2Map.new(map_data)
      @survival_stats['maps'][map.id] = map
    end
  end

  @survival_stats
end

#weapon_statsObject

Returns a Hash of L4D2Weapon for this user containing all Left4Dead 2 weapons. If the weapons haven’t been parsed already, parsing is done now.



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/steam/community/l4d/l4d2_stats.rb', line 106

def weapon_stats
  return unless public?

  if @weapon_stats.nil?
    @weapon_stats = {}
    @xml_data.elements.each('stats/weapons/*') do |weapon_data|
      next unless weapon_data.has_elements?

      unless %w{bilejars molotov pipes}.include? weapon_data.name
        weapon = L4D2Weapon.new(weapon_data)
      else
        weapon = L4DExplosive.new(weapon_data)
      end

      @weapon_stats[weapon_data.name] = weapon
    end
  end

  @weapon_stats
end