aboutsummaryrefslogtreecommitdiffstats
path: root/inc
diff options
context:
space:
mode:
authorpiernov <piernov@piernov.org>2016-04-25 19:10:53 +0200
committerpiernov <piernov@piernov.org>2016-04-25 19:10:53 +0200
commit8770f9ddccfafaad935f66ccbf254624b41545f3 (patch)
treee07d2e93e95a34e9f70f22f52aafa82c09682e4b /inc
parentb141eb3d70b3dc2d75ee8f2bf2edba1fed71f5b6 (diff)
parent8140617aeb2f32f7095a443ca743c6d6915739c6 (diff)
downloadcandybox-8770f9ddccfafaad935f66ccbf254624b41545f3.tar.gz
candybox-8770f9ddccfafaad935f66ccbf254624b41545f3.tar.bz2
candybox-8770f9ddccfafaad935f66ccbf254624b41545f3.tar.xz
candybox-8770f9ddccfafaad935f66ccbf254624b41545f3.zip
Merge remote-tracking branch 'origin/alexichi' into piernov
Diffstat (limited to 'inc')
-rw-r--r--inc/account.inc2
-rw-r--r--inc/craftmine.inc1
-rw-r--r--inc/guild.inc31
-rw-r--r--inc/messages.inc2
-rw-r--r--inc/mine.inc2
-rw-r--r--inc/mine.inc~20
6 files changed, 36 insertions, 22 deletions
diff --git a/inc/account.inc b/inc/account.inc
index 19f311d..6f398bb 100644
--- a/inc/account.inc
+++ b/inc/account.inc
@@ -2,7 +2,7 @@
require_once("messages.inc");
function debitAccount($amount) {
- if($_SESSION["mine"]["gold"] <= $amount) {
+ if($_SESSION["mine"]["gold"] < $amount) {
sendError("gold_insufficient");
return false;
}
diff --git a/inc/craftmine.inc b/inc/craftmine.inc
index a30538c..33a28d7 100644
--- a/inc/craftmine.inc
+++ b/inc/craftmine.inc
@@ -7,6 +7,7 @@ function sendCraftMine() {
$data = array("gold" => sendMine(),
"shop" => sendShop(),
"inventory" => Inventory::sendContent(),
+ "miners" => sendMiners()
);
echo json_encode($data);
}
diff --git a/inc/guild.inc b/inc/guild.inc
new file mode 100644
index 0000000..c0e8264
--- /dev/null
+++ b/inc/guild.inc
@@ -0,0 +1,31 @@
+<?php
+
+define("GUILD_COST",10);
+define("MINER_COST",5);
+
+function createGuild(){
+ if(!empty($_SESSION["guild"])) {
+ sendError("guild_already_built");
+ }
+ elseif(debitAccount(GUILD_COST)) {
+ $_SESSION["guild"] = true;
+ echo json_encode(array("cost" => GUILD_COST));
+ }
+}
+
+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"]));
+ }
+}
+
+function sendMiners(){
+ return $_SESSION["mine"]["miners"];
+}
+
+
+?>
diff --git a/inc/messages.inc b/inc/messages.inc
index f1ca8b3..d6ea87e 100644
--- a/inc/messages.inc
+++ b/inc/messages.inc
@@ -4,6 +4,8 @@ $messages = array(
"shop_already_built" => "You have already built a shop.",
"gold_insufficient" => "You don't have enough gold.",
"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."
);
function sendError($msg) {
diff --git a/inc/mine.inc b/inc/mine.inc
index 6a04cc4..94a2c66 100644
--- a/inc/mine.inc
+++ b/inc/mine.inc
@@ -1,7 +1,7 @@
<?php
function initCraftMine() {
- $_SESSION["mine"] = array("mine" => 0, "gold" => 0, "miners" => 1);
+ $_SESSION["mine"] = array("mine" => 0, "gold" => 0, "miners" => 0);
}
function withdrawMine() {
diff --git a/inc/mine.inc~ b/inc/mine.inc~
deleted file mode 100644
index a01d768..0000000
--- a/inc/mine.inc~
+++ /dev/null
@@ -1,20 +0,0 @@
-<?php
-
-function initCraftMine() {
- $_SESSION["mine"] = array("mine" => 0, "or" => 0, "miners" => 1);
-}
-
-function withdrawMine() {
- $mine = $_SESSION["mine"];
- $_SESSION["mine"]["gold"] += $mine["mine"];
- $_SESSION["mine"]["mine"] = 0;
-}
-
-function sendMine() {
- if(empty($_SESSION["mine"])) initMine();
- $mine = $_SESSION["mine"];
- echo $mine["gold"];
-}
-
-
-?>