Class: AlienSwarmStats

Inherits:
GameStats show all
Defined in:
lib/steam/community/alien_swarm/alien_swarm_stats.rb

Overview

This class represents the game statistics for a single user in Alien Swarm

Author:

  • Sebastian Staudt

Constant Summary collapse

BASE_URL =

The base URL for all images referenced in the stats

'http://cdn.steamcommunity.com/public/images/gamestats/swarm/'
WEAPONS =

The names of all weapons in Alien Swarm

%w(Autogun Cannon_Sentry Chainsaw Flamer Grenade_Launcher
Hand_Grenades Hornet_Barrage Incendiary_Sentry Laser_Mines
Marskman_Rifle Minigun Mining_Laser PDW Pistol Prototype_Rifle
Rail_Rifle Rifle Rifle_Grenade Sentry_Gun Shotgun Tesla_Cannon
Vindicator Vindicator_Grenade)

Instance Attribute Summary collapse

Attributes inherited from GameStats

#game, #hours_played, #privacy_state, #user

Instance Method Summary collapse

Methods inherited from GameStats

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

Methods included from XMLData

#parse

Constructor Details

#initialize(steam_id, fetch = true, bypass_cache = false) ⇒ AlienSwarmStats

Creates a new ‘AlienSwarmStats` instance by calling the super constructor with the game name `’alienswarm’‘

Parameters:

  • steam_id (String, Fixnum)

    The custom URL or the 64bit Steam ID of the user

  • fetch (Boolean)

    if ‘true` the object’s data is fetched after creation

  • bypass_cache (Boolean)

    if ‘true` the object’s data is fetched again even if it has been cached already



35
36
37
38
39
40
41
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
# File 'lib/steam/community/alien_swarm/alien_swarm_stats.rb', line 35

def initialize(steam_id)
  super steam_id, 'alienswarm'

  if public?
    lifetime_data = @xml_data['stats']['lifetime']

    @hours_played = lifetime_data['timeplayed']

    @lifetime_stats = {
      :accuracy                    => lifetime_data['accuracy'].to_f,
      :aliens_burned               => lifetime_data['aliensburned'].to_i,
      :aliens_killed               => lifetime_data['alienskilled'].to_i,
      :campaigns                   => lifetime_data['campaigns'].to_i,
      :damage_taken                => lifetime_data['damagetaken'].to_i,
      :experience                  => lifetime_data['experience'].to_i,
      :experience_required         => lifetime_data['xprequired'].to_i,
      :fast_hacks                  => lifetime_data['fasthacks'].to_i,
      :friendly_fire               => lifetime_data['friendlyfire'].to_i,
      :games_successful            => lifetime_data['gamessuccess'].to_i,
      :healing                     => lifetime_data['healing'].to_i,
      :kills_per_hour              => lifetime_data['killsperhour'].to_f,
      :level                       => lifetime_data['level'].to_i,
      :promotion                   => lifetime_data['promotion'].to_i,
      :next_unlock                 => lifetime_data['nextunlock'],
      :next_unlock_img             => BASE_URL + lifetime_data['nextunlockimg'],
      :shots_fired                 => lifetime_data['shotsfired'].to_i,
      :total_games                 => lifetime_data['totalgames'].to_i,
      :games_successful_percentage => (@lifetime_stats[:total_games] > 0) ? @lifetime_stats[:games_successful].to_f / @lifetime_stats[:total_games] : 0
    }

    @lifetime_stats[:promotion_img] = BASE_URL + lifetime_data['promotionpic'] if @lifetime_stats[:promotion] > 0
  end
end

Instance Attribute Details

#lifetime_statsHash<Symbol, Object> (readonly)

Returns general stats for the players

Returns:

  • (Hash<Symbol, Object>)

    The stats for the player



17
18
19
# File 'lib/steam/community/alien_swarm/alien_swarm_stats.rb', line 17

def lifetime_stats
  @lifetime_stats
end

Instance Method Details

#favoritesHash<Symbol, Object>

Returns the favorites of this user like weapons and marine

If the favorites haven’t been parsed already, parsing is done now.

Returns:

  • (Hash<Symbol, Object>)

    The favorites of this player



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/steam/community/alien_swarm/alien_swarm_stats.rb', line 74

def favorites
  return unless public?

  if @favorites.nil?
    favorites_data = @xml_data['stats']['favorites']

    @favorites = {
      :class                       => favorites_data['class'],
      :class_img                   => favorites_data['classimg'],
      :class_percentage            => favorites_data['classpct'].to_f,
      :difficulty                  => favorites_data['difficulty'],
      :difficulty_percentage       => favorites_data['difficultypct'].to_f,
      :extra                       => favorites_data['extra'],
      :extra_img                   => favorites_data['extraimg'],
      :extra_percentage            => favorites_data['extrapct'].to_f,
      :marine                      => favorites_data['marine'],
      :marine_img                  => favorites_data['marineimg'],
      :marine_percentage           => favorites_data['marinepct'].to_f,
      :mission                     => favorites_data['mission'],
      :mission_img                 => favorites_data['missionimg'],
      :mission_percentage          => favorites_data['missionpct'].to_f,
      :primary_weapon              => favorites_data['primary'],
      :primary_weapon_img          => favorites_data['primaryimg'],
      :primary_weapon_percentage   => favorites_data['primarypct'].to_f,
      :secondary_weapon            => favorites_data['secondary'],
      :secondary_weapon_img        => favorites_data['secondaryimg'],
      :secondary_weapon_percentage => favorites_data['secondarypct'].to_f
    }
  end

  @favorites
end

#item_statsHash<Symbol, Object>

Returns the item stats for this user like ammo deployed and medkits used

If the items haven’t been parsed already, parsing is done now.

Returns:

  • (Hash<Symbol, Object>)

    The item stats of this player



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/steam/community/alien_swarm/alien_swarm_stats.rb', line 113

def item_stats
  return unless public?

  if @item_stats.nil?
    weapons_data = @xml_data['stats']['weapons']

    @item_stats = {
      :ammo_deployed             => weapons_data['ammo_deployed'].to_i,
      :sentryguns_deployed       => weapons_data['sentryguns_deployed'].to_i,
      :sentry_flamers_deployed   => weapons_data['sentry_flamers_deployed'].to_i,
      :sentry_freeze_deployed    => weapons_data['sentry_freeze_deployed'].to_i,
      :sentry_cannon_deployed    => weapons_data['sentry_cannon_deployed'].to_i,
      :medkits_used              => weapons_data['medkits_used'].to_i,
      :flares_used               => weapons_data['flares_used'].to_i,
      :adrenaline_used           => weapons_data['adrenaline_used'].to_i,
      :tesla_traps_deployed      => weapons_data['tesla_traps_deployed'].to_i,
      :freeze_grenades_thrown    => weapons_data['freeze_grenades_thrown'].to_i,
      :electric_armor_used       => weapons_data['electric_armor_used'].to_i,
      :healgun_heals             => weapons_data['healgun_heals'].to_i,
      :healgun_heals_self        => weapons_data['healgun_heals_self'].to_i,
      :healbeacon_heals          => weapons_data['healbeacon_heals'].to_i,
      :healbeacon_heals_self     => weapons_data['healbeacon_heals_self'].to_i,
      :damage_amps_used          => weapons_data['damage_amps_used'].to_i,
      :healbeacons_deployed      => weapons_data['healbeacons_deployed'].to_i,
      :healbeacon_heals_pct      => weapons_data['healbeacon_heals_pct'].to_f,
      :healgun_heals_pct         => weapons_data['healgun_heals_pct'].to_f,
      :healbeacon_heals_pct_self => weapons_data['healbeacon_heals_pct_self'].to_f,
      :healgun_heals_pct_self    => weapons_data['healgun_heals_pct_self'].to_f
    }
  end

  @item_stats
end

#mission_statsHash<String, AlienSwarmMission>

Returns the stats for individual missions for this user containing all Alien Swarm missions

If the mission stats haven’t been parsed already, parsing is done now.

Returns:



153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/steam/community/alien_swarm/alien_swarm_stats.rb', line 153

def mission_stats
  return unless public?

  if @mission_stats.nil?
    @mission_stats = {}
    @xml_data['stats']['missions'].each do |mission_data|
      mission = AlienSwarmMission.new *mission_data
      @mission_stats[mission.name] = mission
    end
  end

  @mission_stats
end

#weapon_statsHash<String, AlienSwarmWeapon>

Returns the stats for individual weapons for this user containing all Alien Swarm weapons

If the weapon stats haven’t been parsed already, parsing is done now.

Returns:



173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/steam/community/alien_swarm/alien_swarm_stats.rb', line 173

def weapon_stats
  return unless public?

  if @weapon_stats.nil?
    @weapon_stats = {}
    WEAPONS.each do |weapon_node|
      weapon_data = @xml_data['stats']['weapons'][weapon_node]
      weapon = AlienSwarmWeapon.new(weapon_data)
      @weapon_stats[weapon.name] = weapon
    end
  end

  @weapon_stats
end