Inventory

Represent the player's Inventory.

Implemented as a singleton in the session.

package

inc\Inventory.inc

author

Alexandre Renoux

author

Pierre-Emmanuel Novac

Methods

Adds an Item object to the Inventory, incrementing the Item's count if it was already present.

_addItem(\Item $item) : array

Arguments

$item

\Item

Item to add to the Inventory

Response

array

Item and Item's count

Removes an Item object from the Inventory, not taking into account the Item's count.

_removeItem(\Item $item) : void

Arguments

$item

\Item

Item to remove from the Inventory

Consumes an Item object from the Inventory, decrementing the Item's count and removing it if count reaches 0.

_useItem(\Item $item) : array|false

Arguments

$item

\Item

Item to consume from the Inventory

Response

array|false

Item and updated Item's count, false if it was not found

Adds an Item object to the singleton's Inventory from session.

addItem(\Item $item) : array
static

Arguments

$item

\Item

Item to add to the Inventory

Response

array

Item and Item's count

Generates an XML tree describing the Inventory

addToXML(\SimpleXMLElement $root) : void

Arguments

$root

\SimpleXMLElement

root XML element to add the Inventory's Items to

Checks if the Inventory was already created in the session

created() : boolean
static

Response

boolean

true if Inventory was already created, false otherwise

Returns the Inventory from the session.

get() : \Inventory
static

Implements the singleton pattern.

Response

\Inventory

the Inventory object

Removes an Item object to the singleton's Inventory from session, not taking into account the Item's count.

removeItem(\Item $item) : void
static

Arguments

$item

\Item

Item to remove from the Inventory

Returns the Inventory's content from the session.

sendContent() : array
static

Response

array

array of Items and number

Consumes an Item object to the singleton's Inventory from session, decrementing the Item's count and removing it if count reaches 0.

useItem(\Item $item) : array|false
static

Arguments

$item

\Item

Item to consume from the Inventory

Response

array|false

Item and updated Item's count, false if it was not found

Properties

Arrays of array with Item object and Item's count as int

items : array
var

Arrays of array with Item object and Item's count as int

Type(s)

array