aboutsummaryrefslogtreecommitdiffstats
path: root/inc
diff options
context:
space:
mode:
authoralexichi <alexbankai96@gmail.com>2016-04-27 12:59:51 +0200
committeralexichi <alexbankai96@gmail.com>2016-04-27 12:59:51 +0200
commit349c6fe7ecf10e5929dc27c2446853f0fe416077 (patch)
treeccb968ac0c1b507f0b88b42d42b47866c893b225 /inc
parent8140617aeb2f32f7095a443ca743c6d6915739c6 (diff)
downloadcandybox-349c6fe7ecf10e5929dc27c2446853f0fe416077.tar.gz
candybox-349c6fe7ecf10e5929dc27c2446853f0fe416077.tar.bz2
candybox-349c6fe7ecf10e5929dc27c2446853f0fe416077.tar.xz
candybox-349c6fe7ecf10e5929dc27c2446853f0fe416077.zip
add loadShop() and categories in the xml file and modify the presentation of the items in the shop
Diffstat (limited to 'inc')
-rw-r--r--inc/shop.inc36
1 files changed, 21 insertions, 15 deletions
diff --git a/inc/shop.inc b/inc/shop.inc
index 11cf97b..6e30923 100644
--- a/inc/shop.inc
+++ b/inc/shop.inc
@@ -5,19 +5,26 @@ require_once("account.inc");
require_once("Item.inc");
require_once("Inventory.inc");
-$shop = array(
- "cost" => 3,
- "items" => array(
- new Item("cat", 6, "🐈", "Nyan!"),
- new Item("torch", 3, "🔦", "Electric torch"),
- ),
-);
+function loadShop(){
+ $items = simplexml_load_file('data/items.xml');
+ $shop = array("cost"=>(string)$items["cost"],"items"=>array());
+ foreach($items as $cat){
+ $category = (string)$cat["name"];
+ $shop["items"][$category] = array();
+ foreach($cat as $item){
+ $shop["items"][$category][] = new Item((string)$item->name,intval($item->cost),(string)$item->icon,(string)$item->description);
+ }
+ }
+ return $shop;
+}
function getItem($name) {
- global $shop;
- foreach($shop["items"] as $item) {
- if($name == $item->name) {
- return $item;
+ $shop=loadShop();
+ foreach($shop["items"] as $cat) {
+ foreach($cat as $item){
+ if($name == $item->name) {
+ return $item;
+ }
}
}
sendError("shop_missing_item");
@@ -29,21 +36,20 @@ function initShop() {
}
function sendShop() {
- global $shop;
if(!empty($_SESSION["shop"]))
- return $shop;
+ return loadShop();
else return false;
}
function buildShop() {
- global $shop;
+ $shop=loadShop();
if(!empty($_SESSION["shop"])) {
sendError("shop_already_built");
}
elseif(debitAccount($shop["cost"])) {
initShop();
$_SESSION["mine"]["gold"] -= $shop["cost"];
- echo json_encode(sendShop());
+ echo json_encode($shop);
}
}