Class: Portal2Item

Inherits:
GameItem show all
Defined in:
lib/steam/community/portal2/portal2_item.rb

Overview

Represents a Portal 2 item

Author:

  • Sebastian Staudt

Constant Summary collapse

BOTS =

The names of the bots available in Portal 2

[ :pbody, :atlas ]

Instance Attribute Summary collapse

Attributes inherited from GameItem

#attributes, #backpack_position, #count, #defindex, #id, #inventory, #item_class, #item_set, #level, #name, #origin, #original_id, #quality, #type

Instance Method Summary collapse

Methods inherited from GameItem

#craftable?, #preliminary?, #schema_data, #tradeable?

Constructor Details

#initialize(inventory, item_data) ⇒ Portal2Item

Creates a new instance of a Portal 2 item with the given data

Parameters:

  • inventory (Portal2Inventory)

    The inventory this item is contained in

  • item_data (Hash<Symbol, Object>)

    The data specifying this item

Raises:



27
28
29
30
31
32
33
34
35
36
# File 'lib/steam/community/portal2/portal2_item.rb', line 27

def initialize(inventory, item_data)
  super

  @slot = schema_data[:item_slot]

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

Instance Attribute Details

#slotString? (readonly)

Returns the slot where this item can be equipped in or ‘nil` if this item cannot be equipped

Returns:

  • (String, nil)

    The slot where this item can be equipped in



20
21
22
# File 'lib/steam/community/portal2/portal2_item.rb', line 20

def slot
  @slot
end

Instance Method Details

#bots_equipped?Array<String>

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

Returns:

  • (Array<String>)

    The names of the bots this player has equipped this item



42
43
44
# File 'lib/steam/community/portal2/portal2_item.rb', line 42

def bots_equipped?
  @equipped.reject { |bot_id, equipped| !equipped }
end

#equipped?Boolean

Returns whether this item is equipped by this player at all

Returns:

  • (Boolean)

    ‘true` if the player has equipped this item at all



49
50
51
# File 'lib/steam/community/portal2/portal2_item.rb', line 49

def equipped?
  @equipped.has_value? true
end