(string)$items["cost"],"items"=>array()); foreach($items as $cat){ $category = (string)$cat["name"]; $shop["items"][$category] = array(); foreach($cat as $item){ $feats = array(); foreach($item->features[0] as $k => $v) $feats[(string)$k] = (string)$v; $shop["items"][$category][] = new Item( (string)$item->name, intval($item->cost), (string)$item->icon, (string)$item->description, $feats); } } return $shop; } function getItem($name) { $shop=loadShop(); foreach($shop["items"] as $cat) { foreach($cat as $item){ if($name == $item->name) { return $item; } } } sendError("shop_missing_item"); return false; } function initShop() { $_SESSION["shop"] = true; } function sendShop() { if(!empty($_SESSION["shop"])) return loadShop(); else return false; } function buildShop() { $shop=loadShop(); if(!empty($_SESSION["shop"])) { sendError("shop_already_built"); } elseif(debitAccount($shop["cost"])) { initShop(); echo json_encode($shop); } } function buyItem() { $item = getItem($_POST["item"]); if($item && debitAccount($item->cost)) { $tab = Inventory::addItem($item); echo json_encode($tab); //renvoyer un tableau avec comme première entrée $item et comme deuxième entrée le nombre } } function useItem(){ $item = getItem($_POST["item"]); $it = Inventory::useItem($item); echo json_encode(array("perso" => sendPerso(), "item" => $it)); } ?>