aboutsummaryrefslogtreecommitdiffstats
path: root/inc/Inventory.inc
diff options
context:
space:
mode:
Diffstat (limited to 'inc/Inventory.inc')
-rw-r--r--inc/Inventory.inc50
1 files changed, 47 insertions, 3 deletions
diff --git a/inc/Inventory.inc b/inc/Inventory.inc
index efe54f2..3e0137d 100644
--- a/inc/Inventory.inc
+++ b/inc/Inventory.inc
@@ -1,5 +1,7 @@
<?php
+require_once("perso.inc");
+
class Inventory {
public $items = array();
@@ -20,22 +22,64 @@ class Inventory {
}
private function _addItem($item) {
- $this->items[] = $item;
+ foreach($this->items as $k => $object){
+ if($object[0] == $item){
+ $this->items[$k][1]++;
+ return $this->items[$k];
+ }
+ }
+ $tab = array($item,1);
+ $this->items[] = $tab;
+ return $tab;
}
public static function addItem($item) {
$inv = self::get();
- $inv->_addItem($item);
+ $tab = $inv->_addItem($item);
+ return $tab;
}
private function _removeItem($item) {
- unset($this->items[array_search($item, $this->items)]);
+ foreach($this->items as $k => $object) {
+ if($object[0] == $item) {
+ unset($this->items[$k]);
+ return;
+ }
+ }
}
public static function removeItem($item) {
$inv = self::get();
$inv->_removeItem($item);
}
+
+ private function _useItem($item) {
+ foreach($this->items as $k => $object){
+ if($object[0] == $item) {
+ $nb = $this->items[$k][1];
+ if(limitUse($this->items[$k][0])){
+ if($nb > 0) {
+ $this->items[$k][0]->consume();
+ $this->items[$k][1]--;
+ }
+ if($nb-1 <= 0) $this->_removeItem($item);
+ return array($object[0], $nb-1);
+ }
+ }
+ }
+ return false;
+ }
+
+ public static function useItem($item) {
+ $inv = self::get();
+ $it = $inv->_useItem($item);
+ return $it;
+ }
+
+ public function addToXML($root) {
+ foreach($this->items as $item)
+ $item[0]->addToXML($root, $item[1]);
+ }
}
?>