diff options
author | alexichi <alexbankai96@gmail.com> | 2016-05-11 11:56:19 +0200 |
---|---|---|
committer | alexichi <alexbankai96@gmail.com> | 2016-05-11 11:56:19 +0200 |
commit | 35efaf74e828b738a20324a664cf9c2e08ef47d4 (patch) | |
tree | 183b4704c87c61b690010efbd6f3b30218328bcc /inc/mine.inc | |
parent | 2350d43a09495db18b22b86ffc815a84eeb35579 (diff) | |
parent | 1158d2063f00f38de19a4600566b244a942d86ba (diff) | |
download | candybox-35efaf74e828b738a20324a664cf9c2e08ef47d4.tar.gz candybox-35efaf74e828b738a20324a664cf9c2e08ef47d4.tar.bz2 candybox-35efaf74e828b738a20324a664cf9c2e08ef47d4.tar.xz candybox-35efaf74e828b738a20324a664cf9c2e08ef47d4.zip |
Merge branch 'master' of piernov.org:candybox into alexichialexichi
Conflicts:
inc/perso.inc
Diffstat (limited to 'inc/mine.inc')
-rw-r--r-- | inc/mine.inc | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/inc/mine.inc b/inc/mine.inc index 752fc69..fb5f612 100644 --- a/inc/mine.inc +++ b/inc/mine.inc @@ -1,18 +1,48 @@ <?php +/** + * Manages the mine. + * + * @packageĀ inc\mine.inc + * @author Alexandre Renoux + * @author Pierre-Emmanuel Novac + */ -function initCraftMine() { - $_SESSION["mine"] = array("gold" => 0, "miners" => 0); +/** + * Initializes the gold amount and miners count in the session. + * + * @return void + */ +function initMineIfNeeded() { + if(empty($_SESSION["mine"])) + $_SESSION["mine"] = array("gold" => 0); + else if(!array_key_exists("gold", $_SESSION["mine"])) + $_SESSION["mine"]["gold"] = 0; } +/** + * Transfers all gold from the mine to the player's account. + * + * @return void + */ 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"]); } +/** + * Returns the amount of gold currently owned by the player. + * + * @return int amount of gold available + */ function sendMine() { - if(empty($_SESSION["mine"])) initCraftMine(); + initMineIfNeeded(); $mine = $_SESSION["mine"]; return $mine["gold"]; } |