Module: AbstractL4DWeapon

Includes:
GameWeapon
Included in:
L4D2Weapon, L4DWeapon
Defined in:
lib/steam/community/l4d/abstract_l4d_weapon.rb

Overview

This abstract class is a base class for weapons in Left4Dead and Left4Dead 2 as the weapon stats for both games are very similar

Author:

  • Sebastian Staudt

Instance Attribute Summary collapse

Attributes included from GameWeapon

#kills

Instance Method Summary collapse

Methods included from GameWeapon

#avg_shots_per_kill

Instance Attribute Details

#accuracyString (readonly)

Returns the overall accuracy of the player with this weapon

Returns:

  • (String)

    The accuracy of the player with this weapon



19
20
21
# File 'lib/steam/community/l4d/abstract_l4d_weapon.rb', line 19

def accuracy
  @accuracy
end

#headshots_percentageString (readonly)

Returns the percentage of kills with this weapon that have been headshots

Returns:

  • (String)

    The percentage of headshots with this weapon



24
25
26
# File 'lib/steam/community/l4d/abstract_l4d_weapon.rb', line 24

def headshots_percentage
  @headshots_percentage
end

#idString (readonly)

Returns the ID of the weapon

Returns:

  • (String)

    The ID of the weapon



29
30
31
# File 'lib/steam/community/l4d/abstract_l4d_weapon.rb', line 29

def id
  @id
end

#kill_percentageString (readonly)

Returns the percentage of overall kills of the player that have been achieved with this weapon

Returns:

  • (String)

    The percentage of kills with this weapon



35
36
37
# File 'lib/steam/community/l4d/abstract_l4d_weapon.rb', line 35

def kill_percentage
  @kill_percentage
end

#shotsFixnum (readonly)

Returns the number of shots the player has fired with this weapon

Returns:

  • (Fixnum)

    The number of shots with this weapon



40
41
42
# File 'lib/steam/community/l4d/abstract_l4d_weapon.rb', line 40

def shots
  @shots
end

Instance Method Details

#initialize(weapon_name, weapon_data) ⇒ Object

Creates a new instance of weapon from the given XML data and parses common data for both, ‘L4DWeapon` and `L4D2Weapon`

Parameters:

  • weapon_name (String)

    The name of this weapon

  • weapon_data (Hash<String, Object>)

    The XML data for this weapon



47
48
49
50
51
52
53
54
# File 'lib/steam/community/l4d/abstract_l4d_weapon.rb', line 47

def initialize(weapon_name, weapon_data)
  super weapon_data

  @accuracy             = weapon_data['accuracy'].to_f * 0.01
  @headshots_percentage = weapon_data['headshots'].to_f * 0.01
  @id                   = weapon_name
  @shots                = weapon_data['shots'].to_i
end