blob: f4c10afdec3bdec3c9022938ef1740675d21d034 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
<?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);
/**
* 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");
}
elseif(debitAccount(GUILD_COST)) {
$_SESSION["guild"] = true;
echo json_encode(array("cost" => GUILD_COST));
}
}
/**
* 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)){
$_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(){
return $_SESSION["mine"]["miners"];
}
?>
|