Class: L4D2Map

Inherits:
L4DMap show all
Defined in:
lib/steam/community/l4d/l4d2_map.rb

Overview

L4D2Map holds statistical information about maps played by a player in Survival mode of Left4Dead 2. The basic information provided is more or less the same for Left4Dead and Left4Dead 2, but parsing has to be done differently.

Author:

  • Sebastian Staudt

Constant Summary collapse

INFECTED =

The names of the special infected in Left4Dead 2

%w{boomer charger common hunter jockey smoker spitter tank}
ITEMS =

The items available in Left4Dead 2

%w{adrenaline defibs medkits pills}

Constants inherited from L4DMap

L4DMap::BRONZE, L4DMap::GOLD, L4DMap::NONE, L4DMap::SILVER

Instance Attribute Summary collapse

Attributes inherited from L4DMap

#best_time, #id, #medal, #name, #times_played

Instance Method Summary collapse

Constructor Details

#initialize(map_data) ⇒ L4D2Map

Creates a new instance of a map based on the given XML data

The map statistics for the Survival mode of Left4Dead 2 hold much more information than those for Left4Dead, e.g. the teammates and items are listed.

Parameters:

  • map_data (Hash<String, Object>)

    The XML data for this map



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
80
81
# File 'lib/steam/community/l4d/l4d2_map.rb', line 47

def initialize(map_data)
  @id        = map_data['img'].match(/http:\/\/cdn\.steamcommunity\.com\/public\/images\/gamestats\/550\/(.*).jpg/)[1]
  @name      = map_data['name']
  @played    = (map_data['hasPlayed'].to_i == 1)

  if @played
    @best_time = map_data['besttimemilliseconds'].to_f / 1000

    @teammates = []
    map_data['teammates']['steamID64'].each do |teammate|
      @teammates << SteamId.new(teammate, false)
    end

    @items = {}
    ITEMS.each do |item|
      @items[item] = map_data["items_#{item}"].to_i
    end

    @kills = {}
    INFECTED.each do |infected|
      @kills[infected] = map_data["kills_#{infected}"].to_i
    end

    case map_data['medal']
      when 'gold'
        @medal = L4D2Map::GOLD
      when 'silver'
        @medal = L4D2Map::SILVER
      when 'bronze'
        @medal = L4D2Map::BRONZE
      else
        @medal = L4D2Map::NONE
    end
  end
end

Instance Attribute Details

#itemsHash<Symbol, Fixnum> (readonly)

Returns statistics about the items used by the player on this map

Returns:

  • (Hash<Symbol, Fixnum>)

    The items used by the player



20
21
22
# File 'lib/steam/community/l4d/l4d2_map.rb', line 20

def items
  @items
end

#killsHash<Symbol, Fixnum> (readonly)

Returns the number of special infected killed by the player grouped by the names of the special infected

Returns:

  • (Hash<Symbol, Fixnum>)

    The special infected killed by the player



26
27
28
# File 'lib/steam/community/l4d/l4d2_map.rb', line 26

def kills
  @kills
end

#teammatesArray<SteamId> (readonly)

Returns the SteamIDs of the teammates of the player in his best game on this map

Returns:

  • (Array<SteamId>)

    The SteamIDs of the teammates in the best game



32
33
34
# File 'lib/steam/community/l4d/l4d2_map.rb', line 32

def teammates
  @teammates
end

Instance Method Details

#played?Boolean

Returns whether the player has already played this map

Returns:

  • (Boolean)

    ‘true` if the player has already played this map



86
87
88
# File 'lib/steam/community/l4d/l4d2_map.rb', line 86

def played?
  @played
end