diff options
author | alexichi <alexbankai96@gmail.com> | 2016-05-07 12:08:36 +0200 |
---|---|---|
committer | alexichi <alexbankai96@gmail.com> | 2016-05-07 12:08:36 +0200 |
commit | 79cfbb29042fd60dfbc76a6810f75cce21d3ffe0 (patch) | |
tree | ed1425c2bf94fd7e2b068bfe64134e0689f83285 /inc | |
parent | ee02581b7fabd087fc4056bda739c88656fbca14 (diff) | |
download | candybox-79cfbb29042fd60dfbc76a6810f75cce21d3ffe0.tar.gz candybox-79cfbb29042fd60dfbc76a6810f75cce21d3ffe0.tar.bz2 candybox-79cfbb29042fd60dfbc76a6810f75cce21d3ffe0.tar.xz candybox-79cfbb29042fd60dfbc76a6810f75cce21d3ffe0.zip |
add the use of the life bottle
Diffstat (limited to 'inc')
-rw-r--r-- | inc/Inventory.inc | 17 | ||||
-rw-r--r-- | inc/perso.inc | 2 | ||||
-rw-r--r-- | inc/shop.inc | 6 |
3 files changed, 24 insertions, 1 deletions
diff --git a/inc/Inventory.inc b/inc/Inventory.inc index 024a4fe..747c4db 100644 --- a/inc/Inventory.inc +++ b/inc/Inventory.inc @@ -46,6 +46,23 @@ class Inventory { $inv->_removeItem($item); } + 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]; + } + } + 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->addToXML($root); diff --git a/inc/perso.inc b/inc/perso.inc index 4fb05ef..0362d8c 100644 --- a/inc/perso.inc +++ b/inc/perso.inc @@ -10,7 +10,7 @@ function updatePerso(){ $xp = $_POST["xp"]; $lv = $_POST["lv"]; $_SESSION["perso"]["hp"] = $hp; - $_SESSION["perso"]["xp"] = $xp; + $_SESSION["perso"]["xp"] = intval($xp); $_SESSION["perso"]["lv"] = $lv; } diff --git a/inc/shop.inc b/inc/shop.inc index 49ee20b..32ecea2 100644 --- a/inc/shop.inc +++ b/inc/shop.inc @@ -60,5 +60,11 @@ function buyItem() { } } +function useItem(){ + $item = getItem($_POST["item"]); + $it = Inventory::useItem($item); + echo json_encode($it); +} + ?> |