aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoralexichi <alexbankai96@gmail.com>2016-04-25 13:37:08 +0200
committeralexichi <alexbankai96@gmail.com>2016-04-25 13:37:08 +0200
commit29d23898c7ec5d3280e9a7f01a6209f8c8f2d5f8 (patch)
treecbfaaea85e3739abd0b4c59c1bef4e28ff69a84a
parent1ffba62faae83e18597270b68580a90ac3032a31 (diff)
downloadcandybox-29d23898c7ec5d3280e9a7f01a6209f8c8f2d5f8.tar.gz
candybox-29d23898c7ec5d3280e9a7f01a6209f8c8f2d5f8.tar.bz2
candybox-29d23898c7ec5d3280e9a7f01a6209f8c8f2d5f8.tar.xz
candybox-29d23898c7ec5d3280e9a7f01a6209f8c8f2d5f8.zip
Mise en commun du shop et de la guilde
-rw-r--r--inc/account.inc2
-rw-r--r--inc/craftmine.inc1
-rw-r--r--inc/guild.inc29
-rw-r--r--inc/messages.inc2
-rw-r--r--js/craftmine.js3
-rw-r--r--js/guild.js27
6 files changed, 30 insertions, 34 deletions
diff --git a/inc/account.inc b/inc/account.inc
index 19f311d..6f398bb 100644
--- a/inc/account.inc
+++ b/inc/account.inc
@@ -2,7 +2,7 @@
require_once("messages.inc");
function debitAccount($amount) {
- if($_SESSION["mine"]["gold"] <= $amount) {
+ if($_SESSION["mine"]["gold"] < $amount) {
sendError("gold_insufficient");
return false;
}
diff --git a/inc/craftmine.inc b/inc/craftmine.inc
index a30538c..33a28d7 100644
--- a/inc/craftmine.inc
+++ b/inc/craftmine.inc
@@ -7,6 +7,7 @@ function sendCraftMine() {
$data = array("gold" => sendMine(),
"shop" => sendShop(),
"inventory" => Inventory::sendContent(),
+ "miners" => sendMiners()
);
echo json_encode($data);
}
diff --git a/inc/guild.inc b/inc/guild.inc
index 4ca0262..c0e8264 100644
--- a/inc/guild.inc
+++ b/inc/guild.inc
@@ -1,30 +1,31 @@
<?php
+define("GUILD_COST",10);
+define("MINER_COST",5);
+
function createGuild(){
- if($_SESSION["mine"]["gold"] >= 50 && !isset($_SESSION["guild"])){
- $_SESSION["guild"]= array("miners" => 1);
- $_SESSION["mine"]["gold"] -= 50;
- echo "Guild has been successfully created";
+ if(!empty($_SESSION["guild"])) {
+ sendError("guild_already_built");
}
- else{
- echo "g";
+ elseif(debitAccount(GUILD_COST)) {
+ $_SESSION["guild"] = true;
+ echo json_encode(array("cost" => GUILD_COST));
}
}
function hireMiner(){
if(!isset($_SESSION["guild"])){
- echo "you need to create a guild first";
+ sendError("guild_not_yet_created");
}
- if($_SESSION["mine"]["gold"] >= 20 && isset($_SESSION["guild"])){
- $_SESSION["guild"]["miners"]++;
- $_SESSION["mine"]["gold"] -= 20;
- $_SESSION["mine"]["miners"] = $_SESSION["guild"]["miners"];
- $mine = $_SESSION["mine"];
- echo $mine["gold"] +","+ $mine["miners"];
+ elseif(debitAccount(MINER_COST)){
+ $_SESSION["mine"]["miners"]++;
+ echo json_encode(array("cost" => MINER_COST , "miners" => $_SESSION["mine"]["miners"]));
}
}
-//function buy($obj,$prix){}
+function sendMiners(){
+ return $_SESSION["mine"]["miners"];
+}
?>
diff --git a/inc/messages.inc b/inc/messages.inc
index f1ca8b3..d6ea87e 100644
--- a/inc/messages.inc
+++ b/inc/messages.inc
@@ -4,6 +4,8 @@ $messages = array(
"shop_already_built" => "You have already built a shop.",
"gold_insufficient" => "You don't have enough gold.",
"shop_missing_item" => "This item does not exist.",
+ "guild_not_yet_created" => "You need to create a guild first.",
+ "guild_already_built" => "You have aready built a guild."
);
function sendError($msg) {
diff --git a/js/craftmine.js b/js/craftmine.js
index 000a8f2..92fa45a 100644
--- a/js/craftmine.js
+++ b/js/craftmine.js
@@ -49,7 +49,8 @@ function initCraftMine() {
data.gold = parseInt(ret.gold); // Server's response is a string
if(ret.shop) displayShop(ret.shop);
displayInventory(ret.inventory);
- updateData("gold");
+ data.miners = parseInt(ret.miners);
+ updateData("gold","miners");
})
}
diff --git a/js/guild.js b/js/guild.js
index cb9e783..8d4d91b 100644
--- a/js/guild.js
+++ b/js/guild.js
@@ -1,26 +1,17 @@
function hireMiner(){
- sendRequest("craftmine.php", "op=hireMiner", function(xhr) {
- //data.gold -= 40;
- var ret = xhr.responseText;
- if(ret != "you need to create a guild first" && ret!=""){
- console.log(ret);
- var tmp = ret.split(",");
- console.log(tmp);
- data.gold = parseInt(tmp[0]);
- data.miners = parseInt(tmp[1]);
- updateData("gold","miners");
+ sendRequest("craftmine.php", "op=hireMiner", function(ret) {
+ debitAccount(parseInt(ret.cost));
+ data.miners = parseInt(ret.miners);
+ updateData("miners");
}
- })
+ )
}
function createGuild(){
- sendRequest("craftmine.php", "op=createGuild", function(xhr) {
- var ret = xhr.responseText;
- if(ret != "g"){
- document.getElementById("guild").innerHTML = ret;
- data.gold -= 50;
- updateData("gold");
+ sendRequest("craftmine.php", "op=createGuild", function(ret) {
+ showInfo("Your guild has been successfully created");
+ debitAccount(parseInt(ret.cost));
}
- })
+ )
}