aboutsummaryrefslogtreecommitdiffstats
path: root/inc/Inventory.inc
diff options
context:
space:
mode:
Diffstat (limited to 'inc/Inventory.inc')
-rw-r--r--inc/Inventory.inc36
1 files changed, 33 insertions, 3 deletions
diff --git a/inc/Inventory.inc b/inc/Inventory.inc
index 73d82c8..58cf709 100644
--- a/inc/Inventory.inc
+++ b/inc/Inventory.inc
@@ -8,9 +8,9 @@
* @author Pierre-Emmanuel Novac
*/
class Inventory {
- /**
- * Arrays of array with Item and Item's count
- */
+ /**
+ * @var array Arrays of array with Item object and Item's count as int
+ */
public $items = array();
/**
@@ -74,6 +74,12 @@ class Inventory {
return $tab;
}
+ /**
+ * Removes an Item object from the Inventory, not taking into account the Item's count.
+ *
+ * @param Item $item Item to remove from the Inventory
+ * @return void
+ */
private function _removeItem($item) {
foreach($this->items as $k => $object) {
if($object[0] == $item) {
@@ -83,11 +89,23 @@ class Inventory {
}
}
+ /**
+ * Removes an Item object to the singleton's Inventory from session, not taking into account the Item's count.
+ *
+ * @param Item $item Item to remove from the Inventory
+ * @return void
+ */
public static function removeItem($item) {
$inv = self::get();
$inv->_removeItem($item);
}
+ /**
+ * Consumes an Item object from the Inventory, decrementing the Item's count and removing it if count reaches 0.
+ *
+ * @param Item $item Item to consume from the Inventory
+ * @return array|false Item and updated Item's count, false if it was not found
+ */
private function _useItem($item) {
foreach($this->items as $k => $object){
if($object[0] == $item) {
@@ -103,12 +121,24 @@ class Inventory {
return false;
}
+ /**
+ * Consumes an Item object to the singleton's Inventory from session, decrementing the Item's count and removing it if count reaches 0.
+ *
+ * @param Item $item Item to consume from the Inventory
+ * @return array|false Item and updated Item's count, false if it was not found
+ */
public static function useItem($item) {
$inv = self::get();
$it = $inv->_useItem($item);
return $it;
}
+ /**
+ * Generates an XML tree describing the Inventory
+ *
+ * @param SimpleXMLElement $root root XML element to add the Inventory's Items to
+ * @return void
+ */
public function addToXML($root) {
foreach($this->items as $item)
$item[0]->addToXML($root, $item[1]);