Module: GameItem

Included in:
Portal2Item, TF2Item
Defined in:
lib/steam/community/game_item.rb

Overview

Provides basic functionality to represent an item in a game

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



11
12
13
# File 'lib/steam/community/game_item.rb', line 11

def attributes
  @attributes
end

#backpack_positionObject (readonly)

Returns the value of attribute backpack_position.



11
12
13
# File 'lib/steam/community/game_item.rb', line 11

def backpack_position
  @backpack_position
end

#classObject (readonly)

Returns the value of attribute class.



11
12
13
# File 'lib/steam/community/game_item.rb', line 11

def class
  @class
end

#countObject (readonly)

Returns the value of attribute count.



11
12
13
# File 'lib/steam/community/game_item.rb', line 11

def count
  @count
end

#defindexObject (readonly)

Returns the value of attribute defindex.



11
12
13
# File 'lib/steam/community/game_item.rb', line 11

def defindex
  @defindex
end

#idObject (readonly)

Returns the value of attribute id.



11
12
13
# File 'lib/steam/community/game_item.rb', line 11

def id
  @id
end

#levelObject (readonly)

Returns the value of attribute level.



11
12
13
# File 'lib/steam/community/game_item.rb', line 11

def level
  @level
end

#nameObject (readonly)

Returns the value of attribute name.



11
12
13
# File 'lib/steam/community/game_item.rb', line 11

def name
  @name
end

#qualityObject (readonly)

Returns the value of attribute quality.



11
12
13
# File 'lib/steam/community/game_item.rb', line 11

def quality
  @quality
end

#slotObject (readonly)

Returns the value of attribute slot.



11
12
13
# File 'lib/steam/community/game_item.rb', line 11

def slot
  @slot
end

#typeObject (readonly)

Returns the value of attribute type.



11
12
13
# File 'lib/steam/community/game_item.rb', line 11

def type
  @type
end

Instance Method Details

#initialize(inventory, item_data) ⇒ Object

Creates a new instance of a GameItem with the given data



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/steam/community/game_item.rb', line 15

def initialize(inventory, item_data)
  @defindex          = item_data[:defindex]
  @backpack_position = item_data[:inventory] & 0xffff
  @class             = inventory.item_schema[@defindex][:item_class]
  @count             = item_data[:quantity]
  @id                = item_data[:id]
  @level             = item_data[:level]
  @name              = inventory.item_schema[@defindex][:item_name]
  @quality           = inventory.qualities[item_data[:quality]]
  @slot              = inventory.item_schema[@defindex][:item_slot]
  @tradeable         = !(item_data[:flag_cannot_trade] == true)
  @type              = inventory.item_schema[@defindex][:item_type_name]

  unless inventory.item_schema[@defindex][:attributes].nil?
    @attributes = inventory.item_schema[@defindex][:attributes]
  end
end

#tradeable?Boolean

Returns whether this item is tradeable

Returns:

  • (Boolean)


34
35
36
# File 'lib/steam/community/game_item.rb', line 34

def tradeable?
  @tradeable
end