Class: TF2Item
- Inherits:
-
Object
- Object
- TF2Item
- Defined in:
- lib/steam/community/tf2/tf2_item.rb
Overview
Represents a Team Fortress 2 item
Constant Summary collapse
- CLASSES =
[ :scout, :sniper, :soldier, :demoman, :medic, :heavy, :pyro, :spy ]
- @@attribute_schema =
nil
- @@item_schema =
nil
- @@schema_language =
'en'
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#backpack_position ⇒ Object
readonly
Returns the value of attribute backpack_position.
-
#class ⇒ Object
readonly
Returns the value of attribute class.
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#defindex ⇒ Object
readonly
Returns the value of attribute defindex.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#level ⇒ Object
readonly
Returns the value of attribute level.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#quality ⇒ Object
readonly
Returns the value of attribute quality.
-
#slot ⇒ Object
readonly
Returns the value of attribute slot.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
-
.attribute_schema ⇒ Object
Returns the attribute schema.
-
.item_schema ⇒ Object
Returns the item schema.
-
.schema_language=(language) ⇒ Object
Sets the language the schema should be fetched in (default is: ‘en’).
Instance Method Summary collapse
-
#classes_equipped? ⇒ Boolean
Returns the class symbols for each class this player has equipped this item.
-
#equipped? ⇒ Boolean
Returns whether this item is equipped by this player at all.
-
#initialize(item_data) ⇒ TF2Item
constructor
Creates a new instance of a TF2Item with the given data.
Constructor Details
#initialize(item_data) ⇒ TF2Item
Creates a new instance of a TF2Item with the given data
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/steam/community/tf2/tf2_item.rb', line 46 def initialize(item_data) update_schema if @@item_schema.nil? @defindex = item_data[:defindex] @backpack_position = item_data[:inventory] & 0xffff @class = @@item_schema[@defindex][:item_class] @count = item_data[:quantity] @id = item_data[:id] @level = item_data[:level] @name = @@item_schema[@defindex][:item_name] @quality = @@qualities[item_data[:quality]] @slot = @@item_schema[@defindex][:item_slot] @type = @@item_schema[@defindex][:item_type_name] @equipped = {} CLASSES.each_index do |class_id| @equipped[CLASSES[class_id]] = (item_data[:inventory] & (1 << 16 + class_id) != 0) end unless @@item_schema[@defindex][:attributes].nil? @attributes = @@item_schema[@defindex][:attributes][:attribute] end end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
13 14 15 |
# File 'lib/steam/community/tf2/tf2_item.rb', line 13 def attributes @attributes end |
#backpack_position ⇒ Object (readonly)
Returns the value of attribute backpack_position.
13 14 15 |
# File 'lib/steam/community/tf2/tf2_item.rb', line 13 def backpack_position @backpack_position end |
#class ⇒ Object (readonly)
Returns the value of attribute class.
13 14 15 |
# File 'lib/steam/community/tf2/tf2_item.rb', line 13 def class @class end |
#count ⇒ Object (readonly)
Returns the value of attribute count.
13 14 15 |
# File 'lib/steam/community/tf2/tf2_item.rb', line 13 def count @count end |
#defindex ⇒ Object (readonly)
Returns the value of attribute defindex.
13 14 15 |
# File 'lib/steam/community/tf2/tf2_item.rb', line 13 def defindex @defindex end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
13 14 15 |
# File 'lib/steam/community/tf2/tf2_item.rb', line 13 def id @id end |
#level ⇒ Object (readonly)
Returns the value of attribute level.
13 14 15 |
# File 'lib/steam/community/tf2/tf2_item.rb', line 13 def level @level end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
13 14 15 |
# File 'lib/steam/community/tf2/tf2_item.rb', line 13 def name @name end |
#quality ⇒ Object (readonly)
Returns the value of attribute quality.
13 14 15 |
# File 'lib/steam/community/tf2/tf2_item.rb', line 13 def quality @quality end |
#slot ⇒ Object (readonly)
Returns the value of attribute slot.
13 14 15 |
# File 'lib/steam/community/tf2/tf2_item.rb', line 13 def slot @slot end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
13 14 15 |
# File 'lib/steam/community/tf2/tf2_item.rb', line 13 def type @type end |
Class Method Details
.attribute_schema ⇒ Object
Returns the attribute schema
The attribute schema is fetched first if not done already
25 26 27 28 29 |
# File 'lib/steam/community/tf2/tf2_item.rb', line 25 def self.attribute_schema update_schema if @@attribute_schema.nil? @@attribute_schema end |
.item_schema ⇒ Object
Returns the item schema
The item schema is fetched first if not done already
34 35 36 37 38 |
# File 'lib/steam/community/tf2/tf2_item.rb', line 34 def self.item_schema update_schema if @@item_schema.nil? @@item_schema end |
.schema_language=(language) ⇒ Object
Sets the language the schema should be fetched in (default is: ‘en’)
41 42 43 |
# File 'lib/steam/community/tf2/tf2_item.rb', line 41 def self.schema_language=(language) @@schema_language = language end |
Instance Method Details
#classes_equipped? ⇒ Boolean
Returns the class symbols for each class this player has equipped this item
72 73 74 |
# File 'lib/steam/community/tf2/tf2_item.rb', line 72 def classes_equipped? @equipped.reject { |class_id, equipped| !equipped } end |
#equipped? ⇒ Boolean
Returns whether this item is equipped by this player at all
77 78 79 |
# File 'lib/steam/community/tf2/tf2_item.rb', line 77 def equipped? @equipped.has_value? true end |