Class: DefenseGridStats

Inherits:
GameStats show all
Defined in:
lib/steam/community/defense_grid/defense_grid_stats.rb

Overview

This class represents the game statistics for a single user in Defense Grid: The Awakening

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) ⇒ DefenseGridStats

Creates a ‘DefenseGridStats` instance by calling the super constructor with the game name `’defensegrid:awakening’‘



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 130

def initialize(steam_id)
  super(steam_id, 'defensegrid:awakening')

  if public?
    general_data = @xml_data['stats']['general']

    @bronze_medals           = general_data['bronze_medals_won']['value'].to_i
    @silver_medals           = general_data['silver_medals_won']['value'].to_i
    @gold_medals             = general_data['gold_medals_won']['value'].to_i
    @levels_played           = general_data['levels_played_total']['value'].to_i
    @levels_played_campaign  = general_data['levels_played_campaign']['value'].to_i
    @levels_played_challenge = general_data['levels_played_challenge']['value'].to_i
    @levels_won              = general_data['levels_won_total']['value'].to_i
    @levels_won_campaign     = general_data['levels_won_campaign']['value'].to_i
    @levels_won_challenge    = general_data['levels_won_challenge']['value'].to_i
    @encountered             = general_data['total_aliens_encountered']['value'].to_i
    @killed                  = general_data['total_aliens_killed']['value'].to_i
    @killed_campaign         = general_data['total_aliens_killed_campaign']['value'].to_i
    @killed_challenge        = general_data['total_aliens_killed_challenge']['value'].to_i
    @resources               = general_data['resources_recovered']['value'].to_i
    @heat_damage             = general_data['heatdamage']['value'].to_f
    @time_played             = general_data['time_played']['value'].to_f
    @interest                = general_data['interest_gained']['value'].to_f
    @damage_done             = general_data['tower_damage_total']['value'].to_f
    @damage_campaign         = general_data['tower_damage_total_campaign']['value'].to_f
    @damage_challenge        = general_data['tower_damage_total_challenge']['value'].to_f
    @orbital_laser_fired     = @xml_data['stats']['orbitallaser']['fired']['value'].to_i
    @orbital_laser_damage    = @xml_data['stats']['orbitallaser']['damage']['value'].to_f
  end
end

Instance Attribute Details

#bronze_medalsFixnum (readonly)

Returns the bronze medals won by this player



17
18
19
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 17

def bronze_medals
  @bronze_medals
end

#damage_campaignFloat (readonly)

Returns the damage done during the campaign by this player



27
28
29
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 27

def damage_campaign
  @damage_campaign
end

#damage_challengeFloat (readonly)

Returns the damage done during challenges by this player



32
33
34
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 32

def damage_challenge
  @damage_challenge
end

#damage_doneFloat (readonly)

Returns the damage done by this player



22
23
24
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 22

def damage_done
  @damage_done
end

#encounteredFixnum (readonly)

Returns the aliens encountered by this player



37
38
39
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 37

def encountered
  @encountered
end

#gold_medalsFixnum (readonly)

Returns the gold medals won by this player



42
43
44
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 42

def gold_medals
  @gold_medals
end

#heat_damageFloat (readonly)

Returns the heat damage done by this player



47
48
49
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 47

def heat_damage
  @heat_damage
end

#interestFixnum (readonly)

Returns the interest gained by the player



52
53
54
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 52

def interest
  @interest
end

#killedFixnum (readonly)

Returns the aliens killed by the player



57
58
59
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 57

def killed
  @killed
end

#killed_campaignFixnum (readonly)

Returns the aliens killed during the campaign by the player



62
63
64
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 62

def killed_campaign
  @killed_campaign
end

#killed_challengeFixnum (readonly)

Returns the aliens killed during challenges by the player



67
68
69
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 67

def killed_challenge
  @killed_challenge
end

#levels_playedFixnum (readonly)

Returns the number of levels played by the player



72
73
74
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 72

def levels_played
  @levels_played
end

#levels_played_campaignFixnum (readonly)

Returns the number of levels played during the campaign by the player



77
78
79
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 77

def levels_played_campaign
  @levels_played_campaign
end

#levels_played_challengeFixnum (readonly)

Returns the number of levels played during challenges by the player



82
83
84
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 82

def levels_played_challenge
  @levels_played_challenge
end

#levels_wonFixnum (readonly)

Returns the number of levels won by the player



87
88
89
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 87

def levels_won
  @levels_won
end

#levels_won_campaignFixnum (readonly)

Returns the number of levels won during the campaign by the player



92
93
94
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 92

def levels_won_campaign
  @levels_won_campaign
end

#levels_won_challengeFixnum (readonly)

Returns the number of levels won during challenges by the player



97
98
99
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 97

def levels_won_challenge
  @levels_won_challenge
end

#orbital_laser_damageFixnum (readonly)

Returns the number of times the orbital lasers has been fired by the player



107
108
109
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 107

def orbital_laser_damage
  @orbital_laser_damage
end

#orbital_laser_firedFloat (readonly)

Returns the damage dealt by the orbital laser



102
103
104
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 102

def orbital_laser_fired
  @orbital_laser_fired
end

#resourcesFixnum (readonly)

Returns the amount of resources harvested by the player



112
113
114
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 112

def resources
  @resources
end

#silver_medalsFixnum (readonly)

Returns the silver medals won by this player



117
118
119
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 117

def silver_medals
  @silver_medals
end

#time_playedFloat (readonly)

Returns the time played in seconds by the player



122
123
124
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 122

def time_played
  @time_played
end

Instance Method Details

#alien_statsHash<String, Array<Fixnum>>

Returns stats about the aliens encountered by the player

The Hash returned uses the names of the aliens as keys. Every value of the Hash is an Array containing the number of aliens encountered as the first element and the number of aliens killed as the second element.



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 168

def alien_stats
  return unless public?

  if @alien_stats.nil?
    alien_data = @xml_data['stats']['aliens']
    @alien_stats = {}
    aliens = %w{swarmer juggernaut crasher spire grunt bulwark drone manta dart
                decoy rumbler seeker turtle walker racer stealth}

    aliens.each do |alien|
      @alien_stats[alien] = [
        alien_data[alien]['encountered']['value'].to_i,
        alien_data[alien]['killed']['value'].to_i
      ]
    end
  end

  @alien_stats
end

#tower_statsHash<String, Array<Fixnum>>

Returns stats about the towers built by the player

The Hash returned uses the names of the towers as keys. Every value of the Hash is another Hash using the keys 1 to 3 for different tower levels. The values of these Hash is an Array containing the number of towers built as the first element and the damage dealt by this specific tower type as the second element.

The Command tower uses the resources gained as second element. The Temporal tower doesn’t have a second element.



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 200

def tower_stats
  return unless public?

  if @tower_stats.nil?
    tower_data = @xml_data['stats']['towers']
    @tower_stats = {}
    towers = %w{cannon flak gun inferno laser meteor missile tesla}

    towers.each do |tower|
      @tower_stats[tower] = {}
      (1..3).each do |i|
        tower_level = tower_data[tower].detect { |t| t['level'].to_i == i }
        @tower_stats[tower][i] = [
          tower_level['built']['value'].to_i,
          tower_level['damage']['value'].to_f
        ]
      end
    end

    @tower_stats['command'] = {}
    (1..3).each do |i|
      tower_level = tower_data['command'].detect { |t| t['level'].to_i == i }
      @tower_stats['command'][i] = [
        tower_level['built']['value'].to_i,
        tower_level['resource']['value'].to_f
      ]
    end

    @tower_stats['temporal'] = {}
    (1..3).each do |i|
      tower_level = tower_data['temporal'].detect { |t| t['level'].to_i == i }
      @tower_stats['temporal'][i] = [ tower_level['built']['value'].to_i ]
    end
  end

  @tower_stats
end