Class: TF2Item

Inherits:
Object
  • Object
show all
Includes:
GameItem
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 ]

Instance Attribute Summary

Attributes included from GameItem

#attributes, #backpack_position, #class, #count, #defindex, #id, #level, #name, #quality, #slot, #type

Instance Method Summary collapse

Methods included from GameItem

#tradeable?

Constructor Details

#initialize(inventory, item_data) ⇒ TF2Item

Creates a new instance of a TF2Item with the given data



16
17
18
19
20
21
22
23
# File 'lib/steam/community/tf2/tf2_item.rb', line 16

def initialize(inventory, item_data)
  super

  @equipped = {}
  CLASSES.each_index do |class_id|
    @equipped[CLASSES[class_id]] = (item_data[:inventory] & (1 << 16 + class_id) != 0)
  end
end

Instance Method Details

#classes_equipped?Boolean

Returns the class symbols for each class this player has equipped this item

Returns:

  • (Boolean)


26
27
28
# File 'lib/steam/community/tf2/tf2_item.rb', line 26

def classes_equipped?
  @equipped.reject { |class_id, equipped| !equipped }
end

#equipped?Boolean

Returns whether this item is equipped by this player at all

Returns:

  • (Boolean)


31
32
33
# File 'lib/steam/community/tf2/tf2_item.rb', line 31

def equipped?
  @equipped.has_value? true
end