Class: TF2Item
- Inherits:
-
Object
- Object
- TF2Item
- Includes:
- GameItem
- Defined in:
- lib/steam/community/tf2/tf2_item.rb
Overview
Represents a Team Fortress 2 item
Constant Summary collapse
- CLASSES =
The names of the classes available in Team Fortress 2
[ :scout, :sniper, :soldier, :demoman, :medic, :heavy, :pyro, :spy ]
Instance Attribute Summary collapse
-
#slot ⇒ String?
readonly
Returns the slot where this item can be equipped in or ‘nil` if this item cannot be equipped.
Attributes included from GameItem
#attributes, #backpack_position, #count, #defindex, #id, #inventory, #item_class, #item_set, #level, #name, #origin, #original_id, #quality, #type
Instance Method Summary collapse
-
#classes_equipped? ⇒ Array<String>
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(inventory, item_data) ⇒ TF2Item
constructor
Creates a new instance of a TF2 item with the given data.
Methods included from GameItem
#craftable?, #preliminary?, #schema_data, #tradeable?
Constructor Details
#initialize(inventory, item_data) ⇒ TF2Item
Creates a new instance of a TF2 item with the given data
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/steam/community/tf2/tf2_item.rb', line 29 def initialize(inventory, item_data) super @slot = schema_data[:item_slot] @equipped = {} CLASSES.each_index do |class_id| @equipped[CLASSES[class_id]] = (item_data[:inventory] & (1 << 16 + class_id) != 0) end end |
Instance Attribute Details
#slot ⇒ String? (readonly)
Returns the slot where this item can be equipped in or ‘nil` if this item cannot be equipped
22 23 24 |
# File 'lib/steam/community/tf2/tf2_item.rb', line 22 def slot @slot end |
Instance Method Details
#classes_equipped? ⇒ Array<String>
Returns the class symbols for each class this player has equipped this item
44 45 46 |
# File 'lib/steam/community/tf2/tf2_item.rb', line 44 def classes_equipped? @equipped.reject { |class_id, equipped| !equipped } end |
#equipped? ⇒ Boolean
Returns whether this item is equipped by this player at all
51 52 53 |
# File 'lib/steam/community/tf2/tf2_item.rb', line 51 def equipped? @equipped.has_value? true end |