aboutsummaryrefslogtreecommitdiffstats
path: root/inc/guild.inc
diff options
context:
space:
mode:
authoralexichi <alexbankai96@gmail.com>2016-05-11 11:56:19 +0200
committeralexichi <alexbankai96@gmail.com>2016-05-11 11:56:19 +0200
commit35efaf74e828b738a20324a664cf9c2e08ef47d4 (patch)
tree183b4704c87c61b690010efbd6f3b30218328bcc /inc/guild.inc
parent2350d43a09495db18b22b86ffc815a84eeb35579 (diff)
parent1158d2063f00f38de19a4600566b244a942d86ba (diff)
downloadcandybox-alexichi.tar.gz
candybox-alexichi.tar.bz2
candybox-alexichi.tar.xz
candybox-alexichi.zip
Merge branch 'master' of piernov.org:candybox into alexichialexichi
Conflicts: inc/perso.inc
Diffstat (limited to 'inc/guild.inc')
-rw-r--r--inc/guild.inc39
1 files changed, 39 insertions, 0 deletions
diff --git a/inc/guild.inc b/inc/guild.inc
index c0e8264..537b87a 100644
--- a/inc/guild.inc
+++ b/inc/guild.inc
@@ -1,8 +1,34 @@
<?php
+/**
+ * Manages miners guild.
+ *
+ * @package inc\guild.inc
+ * @author Alexandre Renoux
+ * @author Pierre-Emmanuel Novac
+ */
+/**
+ * Amount of gold required to build the miners guild.
+ */
define("GUILD_COST",10);
+/**
+ * Amount of gold required to hire a miner.
+ */
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.
+ *
+ * @return void
+ */
function createGuild(){
if(!empty($_SESSION["guild"])) {
sendError("guild_already_built");
@@ -13,17 +39,30 @@ function createGuild(){
}
}
+/**
+ * Hire one miner.
+ * Debits MINER_COST from the player's gold.
+ *
+ * @return void
+ */
function hireMiner(){
if(!isset($_SESSION["guild"])){
sendError("guild_not_yet_created");
}
elseif(debitAccount(MINER_COST)){
+ initMinersIfNeeded();
$_SESSION["mine"]["miners"]++;
echo json_encode(array("cost" => MINER_COST , "miners" => $_SESSION["mine"]["miners"]));
}
}
+/**
+ * Returns the number of miners currently in the guild.
+ *
+ * @return int number of miners in the guild
+ */
function sendMiners(){
+ initMinersIfNeeded();
return $_SESSION["mine"]["miners"];
}