Class: Portal2Item

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

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) ⇒ 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:



23
24
25
26
27
28
29
30
# File 'lib/steam/community/portal2/portal2_item.rb', line 23

def initialize(inventory, item_data)
  super

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



36
37
38
# File 'lib/steam/community/portal2/portal2_item.rb', line 36

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



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

def equipped?
  @equipped.has_value? true
end