From b0d42a638c35836f0bbf91080de2699791b4858e Mon Sep 17 00:00:00 2001 From: piernov Date: Sun, 8 May 2016 14:41:56 +0200 Subject: Fix Item deletion in Inventory + add call to consume() --- inc/Inventory.inc | 20 +++++++++++++++----- 1 file 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; -- cgit v1.2.3-54-g00ecf