aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpiernov <piernov@piernov.org>2016-05-08 14:41:56 +0200
committerpiernov <piernov@piernov.org>2016-05-08 14:41:56 +0200
commitb0d42a638c35836f0bbf91080de2699791b4858e (patch)
tree30ebbf74b77f6d9d9df4f493dac8956f5b80e38c
parentf734770dd4fe464a8c263218efa90fd487c6a608 (diff)
downloadcandybox-b0d42a638c35836f0bbf91080de2699791b4858e.tar.gz
candybox-b0d42a638c35836f0bbf91080de2699791b4858e.tar.bz2
candybox-b0d42a638c35836f0bbf91080de2699791b4858e.tar.xz
candybox-b0d42a638c35836f0bbf91080de2699791b4858e.zip
Fix Item deletion in Inventory + add call to consume()
-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;