Class: SteamCondenser::Community::GameItem

Inherits:
Object
  • Object
show all
Defined in:
lib/steam-condenser/community/game_item.rb

Overview

A module implementing basic functionality for classes representing an item in a game

Direct Known Subclasses

Dota2Item, Portal2Item, TF2Item

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(inventory, item_data) ⇒ GameItem

Creates a new instance of a GameItem with the given data


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
121
122
123
124
# File 'lib/steam-condenser/community/game_item.rb', line 90

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]
  @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]

  if item_data.key? :origin
    @origin = inventory.item_schema.origins[item_data[:origin]]
  end

  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_data[:name]

    unless attribute_key.nil?
      schema_attribute_data = inventory.item_schema.attributes[attribute_key]
      @attributes << attribute_data.merge(schema_attribute_data)
    end
  end
end

Instance Attribute Details

#attributesHash<Symbol, Object>? (readonly)

Return the attributes of this item


19
20
21
# File 'lib/steam-condenser/community/game_item.rb', line 19

def attributes
  @attributes
end

#backpack_positionFixnum (readonly)

Returns the position of this item in the player's inventory


24
25
26
# File 'lib/steam-condenser/community/game_item.rb', line 24

def backpack_position
  @backpack_position
end

#countFixnum (readonly)

Returns the number of items the player owns of this item


29
30
31
# File 'lib/steam-condenser/community/game_item.rb', line 29

def count
  @count
end

#defindexFixnum (readonly)

Returns the index where the item is defined in the schema


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

def defindex
  @defindex
end

#idFixnum (readonly)

Returns the ID of this item


39
40
41
# File 'lib/steam-condenser/community/game_item.rb', line 39

def id
  @id
end

#inventoryGameInventory (readonly)

Returns the inventory this items belongs to


44
45
46
# File 'lib/steam-condenser/community/game_item.rb', line 44

def inventory
  @inventory
end

#item_classString (readonly)

Returns the class of this item


49
50
51
# File 'lib/steam-condenser/community/game_item.rb', line 49

def item_class
  @item_class
end

#item_setHash<Symbol, Object>? (readonly)

Returns the item set this item belongs to


54
55
56
# File 'lib/steam-condenser/community/game_item.rb', line 54

def item_set
  @item_set
end

#levelFixnum (readonly)

Returns the level of this item


59
60
61
# File 'lib/steam-condenser/community/game_item.rb', line 59

def level
  @level
end

#nameString (readonly)

Returns the level of this item


64
65
66
# File 'lib/steam-condenser/community/game_item.rb', line 64

def name
  @name
end

#originString (readonly)

Returns the origin of this item


69
70
71
# File 'lib/steam-condenser/community/game_item.rb', line 69

def origin
  @origin
end

#original_idFixnum (readonly)

Returns the original ID of this item


74
75
76
# File 'lib/steam-condenser/community/game_item.rb', line 74

def original_id
  @original_id
end

#qualityString (readonly)

Returns the quality of this item


79
80
81
# File 'lib/steam-condenser/community/game_item.rb', line 79

def quality
  @quality
end

#typeString (readonly)

Returns the type of this item


84
85
86
# File 'lib/steam-condenser/community/game_item.rb', line 84

def type
  @type
end

Instance Method Details

#craftable?Boolean

Returns whether this item is craftable


129
130
131
# File 'lib/steam-condenser/community/game_item.rb', line 129

def craftable?
  @craftable
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


139
140
141
# File 'lib/steam-condenser/community/game_item.rb', line 139

def preliminary?
  @preliminary
end

#schema_dataHash<Symbol, Object>

Returns the data for this item that's defined in the item schema


146
147
148
# File 'lib/steam-condenser/community/game_item.rb', line 146

def schema_data
  inventory.item_schema.items[@defindex]
end

#tradeable?Boolean

Returns whether this item is tradeable


153
154
155
# File 'lib/steam-condenser/community/game_item.rb', line 153

def tradeable?
  @tradeable
end