Module: GameItem
- Included in:
- Dota2Item, Portal2Item, TF2Item
- Defined in:
- lib/steam/community/game_item.rb
Overview
A module implementing basic functionality for classes representing an item in a game
Instance Attribute Summary collapse
-
#attributes ⇒ Hash<Symbol, Object>?
readonly
Return the attributes of this item.
-
#backpack_position ⇒ Fixnum
readonly
Returns the position of this item in the player’s inventory.
-
#count ⇒ Fixnum
readonly
Returns the number of items the player owns of this item.
-
#defindex ⇒ Fixnum
readonly
Returns the index where the item is defined in the schema.
-
#id ⇒ Fixnum
readonly
Returns the ID of this item.
-
#inventory ⇒ GameInventory
readonly
Returns the inventory this items belongs to.
-
#item_class ⇒ String
readonly
Returns the class of this item.
-
#item_set ⇒ Hash<Symbol, Object>?
readonly
Returns the item set this item belongs to.
-
#level ⇒ Fixnum
readonly
Returns the level of this item.
-
#name ⇒ String
readonly
Returns the level of this item.
-
#origin ⇒ String
readonly
Returns the origin of this item.
-
#original_id ⇒ Fixnum
readonly
Returns the original ID of this item.
-
#quality ⇒ String
readonly
Returns the quality of this item.
-
#type ⇒ String
readonly
Returns the type of this item.
Instance Method Summary collapse
-
#craftable? ⇒ Boolean
Returns whether this item is craftable.
-
#initialize(inventory, item_data) ⇒ Object
Creates a new instance of a GameItem with the given data.
-
#preliminary? ⇒ Boolean
Returns whether this item is preliminary.
-
#schema_data ⇒ Hash<Symbol, Object>
Returns the data for this item that’s defined in the item schema.
-
#tradeable? ⇒ Boolean
Returns whether this item is tradeable.
Instance Attribute Details
#attributes ⇒ Hash<Symbol, Object>? (readonly)
Return the attributes of this item
17 18 19 |
# File 'lib/steam/community/game_item.rb', line 17 def attributes @attributes end |
#backpack_position ⇒ Fixnum (readonly)
Returns the position of this item in the player’s inventory
22 23 24 |
# File 'lib/steam/community/game_item.rb', line 22 def backpack_position @backpack_position end |
#count ⇒ Fixnum (readonly)
Returns the number of items the player owns of this item
27 28 29 |
# File 'lib/steam/community/game_item.rb', line 27 def count @count end |
#defindex ⇒ Fixnum (readonly)
Returns the index where the item is defined in the schema
32 33 34 |
# File 'lib/steam/community/game_item.rb', line 32 def defindex @defindex end |
#id ⇒ Fixnum (readonly)
Returns the ID of this item
37 38 39 |
# File 'lib/steam/community/game_item.rb', line 37 def id @id end |
#inventory ⇒ GameInventory (readonly)
Returns the inventory this items belongs to
42 43 44 |
# File 'lib/steam/community/game_item.rb', line 42 def inventory @inventory end |
#item_class ⇒ String (readonly)
Returns the class of this item
47 48 49 |
# File 'lib/steam/community/game_item.rb', line 47 def item_class @item_class end |
#item_set ⇒ Hash<Symbol, Object>? (readonly)
Returns the item set this item belongs to
52 53 54 |
# File 'lib/steam/community/game_item.rb', line 52 def item_set @item_set end |
#level ⇒ Fixnum (readonly)
Returns the level of this item
57 58 59 |
# File 'lib/steam/community/game_item.rb', line 57 def level @level end |
#name ⇒ String (readonly)
Returns the level of this item
62 63 64 |
# File 'lib/steam/community/game_item.rb', line 62 def name @name end |
#origin ⇒ String (readonly)
Returns the origin of this item
67 68 69 |
# File 'lib/steam/community/game_item.rb', line 67 def origin @origin end |
#original_id ⇒ Fixnum (readonly)
Returns the original ID of this item
72 73 74 |
# File 'lib/steam/community/game_item.rb', line 72 def original_id @original_id end |
#quality ⇒ String (readonly)
Returns the quality of this item
77 78 79 |
# File 'lib/steam/community/game_item.rb', line 77 def quality @quality end |
#type ⇒ String (readonly)
Returns the type of this item
82 83 84 |
# File 'lib/steam/community/game_item.rb', line 82 def type @type end |
Instance Method Details
#craftable? ⇒ Boolean
Returns whether this item is craftable
125 126 127 |
# File 'lib/steam/community/game_item.rb', line 125 def craftable? @craftable end |
#initialize(inventory, item_data) ⇒ Object
Creates a new instance of a GameItem with the given data
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/steam/community/game_item.rb', line 88 def initialize(inventory, item_data) @inventory = inventory @defindex = item_data[:defindex] @backpack_position = item_data[:inventory] & 0xffff @count = item_data[:quantity] @craftable = !!item_data[:flag_cannot_craft] @id = item_data[:id] @item_class = schema_data[:item_class] @item_set = inventory.item_schema.item_sets[schema_data[:item_set]] @level = item_data[:level] @name = schema_data[:item_name] @origin = inventory.item_schema.origins[item_data[:origin]] @original_id = item_data[:original_id] @preliminary = item_data[:inventory] & 0x40000000 != 0 @quality = inventory.item_schema.qualities[item_data[:quality]] @tradeable = !!item_data[:flag_cannot_trade] @type = schema_data[:item_type_name] attributes_data = schema_data[:attributes] || [] attributes_data += item_data[:attributes] if item_data.key? :attributes @attributes = [] attributes_data.each do |attribute_data| attribute_key = attribute_data[:defindex] attribute_key = attribute_data[:name] if attribute_key.nil? unless attribute_key.nil? schema_attribute_data = inventory.item_schema.attributes[attribute_key] @attributes << attribute_data.merge(schema_attribute_data) end end end |
#preliminary? ⇒ Boolean
Returns whether this item is preliminary
Preliminary means that this item was just found or traded and has not yet been added to the inventory
135 136 137 |
# File 'lib/steam/community/game_item.rb', line 135 def preliminary? @preliminary end |
#schema_data ⇒ Hash<Symbol, Object>
Returns the data for this item that’s defined in the item schema
142 143 144 |
# File 'lib/steam/community/game_item.rb', line 142 def schema_data inventory.item_schema.items[@defindex] end |
#tradeable? ⇒ Boolean
Returns whether this item is tradeable
149 150 151 |
# File 'lib/steam/community/game_item.rb', line 149 def tradeable? @tradeable end |