aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--inc/Inventory.inc20
1 files changed, 15 insertions, 5 deletions
diff --git a/inc/Inventory.inc b/inc/Inventory.inc
index 751f728..c4096b7 100644
--- a/inc/Inventory.inc
+++ b/inc/Inventory.inc
@@ -38,7 +38,12 @@ class Inventory {
}
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) {
@@ -48,10 +53,15 @@ class Inventory {
private function _useItem($item) {
foreach($this->items as $k => $object){
- if($object[0] == $item){
- if($this->items[$k][1]>0)$this->items[$k][1]--;
- //if($this->items[$k][1] == 0) _removeItem($item);
- return $this->items[$k];
+ if($object[0] == $item) {
+ $nb = $this->items[$k][1];
+ if($nb > 0) {
+ $this->items[$k][0]->consume();
+ $this->items[$k][1]--;
+ if($nb <= 0) $this->_removeItem($item);
+ return array($object[0], $nb-1);
+ }
+ else $this->_removeItem($item);
}
}
return false;