diff options
Diffstat (limited to 'inc/mine.inc')
-rw-r--r-- | inc/mine.inc | 14 |
1 files changed, 11 insertions, 3 deletions
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"]; } |