Class: DefenseGridStats

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

Overview

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

Instance Attribute Summary collapse

Attributes inherited from GameStats

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

Instance Method Summary collapse

Methods inherited from GameStats

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

Constructor Details

#initialize(steam_id) ⇒ DefenseGridStats

Creates a DefenseGridStats object by calling the super constructor with the game name “defensegrid:awakening”



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 21

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

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

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

Instance Attribute Details

#bronze_medalsObject (readonly)

Returns the value of attribute bronze_medals.



12
13
14
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 12

def bronze_medals
  @bronze_medals
end

#damage_campaignObject (readonly)

Returns the value of attribute damage_campaign.



12
13
14
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 12

def damage_campaign
  @damage_campaign
end

#damage_challengeObject (readonly)

Returns the value of attribute damage_challenge.



12
13
14
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 12

def damage_challenge
  @damage_challenge
end

#damage_doneObject (readonly)

Returns the value of attribute damage_done.



12
13
14
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 12

def damage_done
  @damage_done
end

#encounteredObject (readonly)

Returns the value of attribute encountered.



12
13
14
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 12

def encountered
  @encountered
end

#gold_medalsObject (readonly)

Returns the value of attribute gold_medals.



12
13
14
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 12

def gold_medals
  @gold_medals
end

#heat_damageObject (readonly)

Returns the value of attribute heat_damage.



12
13
14
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 12

def heat_damage
  @heat_damage
end

#interestObject (readonly)

Returns the value of attribute interest.



12
13
14
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 12

def interest
  @interest
end

#killedObject (readonly)

Returns the value of attribute killed.



12
13
14
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 12

def killed
  @killed
end

#killed_campaignObject (readonly)

Returns the value of attribute killed_campaign.



12
13
14
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 12

def killed_campaign
  @killed_campaign
end

#killed_challengeObject (readonly)

Returns the value of attribute killed_challenge.



12
13
14
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 12

def killed_challenge
  @killed_challenge
end

#levels_playedObject (readonly)

Returns the value of attribute levels_played.



12
13
14
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 12

def levels_played
  @levels_played
end

#levels_played_campaignObject (readonly)

Returns the value of attribute levels_played_campaign.



12
13
14
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 12

def levels_played_campaign
  @levels_played_campaign
end

#levels_played_challengeObject (readonly)

Returns the value of attribute levels_played_challenge.



12
13
14
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 12

def levels_played_challenge
  @levels_played_challenge
end

#levels_wonObject (readonly)

Returns the value of attribute levels_won.



12
13
14
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 12

def levels_won
  @levels_won
end

#levels_won_campaignObject (readonly)

Returns the value of attribute levels_won_campaign.



12
13
14
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 12

def levels_won_campaign
  @levels_won_campaign
end

#levels_won_challengeObject (readonly)

Returns the value of attribute levels_won_challenge.



12
13
14
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 12

def levels_won_challenge
  @levels_won_challenge
end

#orbital_laser_damageObject (readonly)

Returns the value of attribute orbital_laser_damage.



12
13
14
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 12

def orbital_laser_damage
  @orbital_laser_damage
end

#orbital_laser_firedObject (readonly)

Returns the value of attribute orbital_laser_fired.



12
13
14
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 12

def orbital_laser_fired
  @orbital_laser_fired
end

#resourcesObject (readonly)

Returns the value of attribute resources.



12
13
14
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 12

def resources
  @resources
end

#silver_medalsObject (readonly)

Returns the value of attribute silver_medals.



12
13
14
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 12

def silver_medals
  @silver_medals
end

#time_playedObject (readonly)

Returns the value of attribute time_played.



12
13
14
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 12

def time_played
  @time_played
end

Instance Method Details

#alien_statsObject

Returns stats about the towers built

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.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 57

def alien_stats
  return unless public?

  if @alien_stats.nil?
    alien_data = @xml_data.elements['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.elements["#{alien}/encountered/value"].text.to_i,
        alien_data.elements["#{alien}/killed/value"].text.to_i
      ]
    end
  end

  @alien_stats
end

#tower_statsObject

Returns stats about the towers built

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.



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/steam/community/defense_grid/defense_grid_stats.rb', line 87

def tower_stats
  return unless public?

  if @tower_stats.nil?
    tower_data = @xml_data.elements['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_stats[tower][i] = [
          tower_data.elements["#{tower}[@level=#{i}]/built/value"].text.to_i,
          tower_data.elements["#{tower}[@level=#{i}]/damage/value"].text.to_f
        ]
      end
    end

    @tower_stats['command'] = {}
    (1..3).each do |i|
      @tower_stats['command'][i] = [
        tower_data.elements["command[@level=#{i}]/built/value"].text.to_i,
        tower_data.elements["command[@level=#{i}]/resource/value"].text.to_f
      ]
    end

    @tower_stats['temporal'] = {}
    (1..3).each do |i|
      @tower_stats['temporal'][i] = [
        tower_data.elements["temporal[@level=#{i}]/built/value"].text.to_i,
      ]
    end
  end

  @tower_stats
end