aboutsummaryrefslogtreecommitdiffstats
path: root/inc
diff options
context:
space:
mode:
Diffstat (limited to 'inc')
-rw-r--r--inc/guild.inc9
-rw-r--r--inc/messages.inc1
-rw-r--r--inc/mine.inc14
3 files changed, 21 insertions, 3 deletions
diff --git a/inc/guild.inc b/inc/guild.inc
index f4c10af..537b87a 100644
--- a/inc/guild.inc
+++ b/inc/guild.inc
@@ -16,6 +16,13 @@ define("GUILD_COST",10);
*/
define("MINER_COST",5);
+function initMinersIfNeeded() {
+ if(empty($_SESSION["mine"]))
+ $_SESSION["mine"] = array("miners" => 0);
+ else if(!array_key_exists("miners", $_SESSION["mine"]))
+ $_SESSION["mine"]["miners"] = 0;
+}
+
/**
* Create the miners guild in the session.
* Debits GUILD_COST from the player's gold.
@@ -43,6 +50,7 @@ function hireMiner(){
sendError("guild_not_yet_created");
}
elseif(debitAccount(MINER_COST)){
+ initMinersIfNeeded();
$_SESSION["mine"]["miners"]++;
echo json_encode(array("cost" => MINER_COST , "miners" => $_SESSION["mine"]["miners"]));
}
@@ -54,6 +62,7 @@ function hireMiner(){
* @return int number of miners in the guild
*/
function sendMiners(){
+ initMinersIfNeeded();
return $_SESSION["mine"]["miners"];
}
diff --git a/inc/messages.inc b/inc/messages.inc
index 8583dc0..7b0d624 100644
--- a/inc/messages.inc
+++ b/inc/messages.inc
@@ -16,6 +16,7 @@ $messages = array(
"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.",
+ "cant_withdraw_in_dungeon" => "You cannot withdraw gold from the mine while you are in the dungeon.",
"dungeon_already_available" => "You can already access the dungeon",
"gamesave_ok" => "Game saved.",
diff --git a/inc/mine.inc b/inc/mine.inc
index d27804a..fb5f612 100644
--- a/inc/mine.inc
+++ b/inc/mine.inc
@@ -12,8 +12,11 @@
*
* @return void
*/
-function initCraftMine() {
- $_SESSION["mine"] = array("gold" => 0, "miners" => 0);
+function initMineIfNeeded() {
+ if(empty($_SESSION["mine"]))
+ $_SESSION["mine"] = array("gold" => 0);
+ else if(!array_key_exists("gold", $_SESSION["mine"]))
+ $_SESSION["mine"]["gold"] = 0;
}
/**
@@ -23,7 +26,12 @@ function initCraftMine() {
*/
function withdrawMine() {
$amount = intval($_POST["amount"]);
+ if(!empty($_SESSION["dungeon"]) && !empty($_SESSION["dungeon"]["flat"])) { // player in dungeon
+ sendError("cant_withdraw_in_dungeon");
+ return;
+ }
if($amount == 0) return;
+ initMineIfNeeded();
$_SESSION["mine"]["gold"] += $amount;
echo json_encode($_SESSION["mine"]["gold"]);
}
@@ -34,7 +42,7 @@ function withdrawMine() {
* @return int amount of gold available
*/
function sendMine() {
- if(empty($_SESSION["mine"])) initCraftMine();
+ initMineIfNeeded();
$mine = $_SESSION["mine"];
return $mine["gold"];
}