aboutsummaryrefslogtreecommitdiffstats
path: root/inc/dungeon.inc
diff options
context:
space:
mode:
Diffstat (limited to 'inc/dungeon.inc')
-rw-r--r--inc/dungeon.inc56
1 files changed, 56 insertions, 0 deletions
diff --git a/inc/dungeon.inc b/inc/dungeon.inc
new file mode 100644
index 0000000..81e2ba7
--- /dev/null
+++ b/inc/dungeon.inc
@@ -0,0 +1,56 @@
+<?php
+require_once("messages.inc");
+require_once("account.inc");
+require_once("Monster.inc");
+
+
+function generateMonster(){
+ $monsters = simplexml_load_file('data/monsters.xml');
+ $dungeon = array("cost"=>(string)$monsters["cost"],"monsters"=>array());
+ foreach($monsters as $f){
+ $floor = (string)$f["name"];
+ $dungeon["monsters"][$floor] = array();
+ foreach($f as $monster){
+ $dungeon["monsters"][$floor][] = new Monster((string)$monster->name,
+ intval($monster->level),
+ intval($monster->hp),
+ (string)$monster->icon);
+ }
+ }
+ return $dungeon;
+}
+
+function initDungeon() {
+ $_SESSION["dungeon"] = true;
+}
+
+function sendDungeon() {
+ if(!empty($_SESSION["dungeon"]))
+ return generateMonster();
+ else return false;
+}
+
+function buildDungeon() {
+ $dungeon=generateMonster();
+ if(!empty($_SESSION["dungeon"])) {
+ sendError("dungeon_already_available");
+ }
+ elseif(debitAccount($dungeon["cost"])) {
+ initDungeon();
+ $_SESSION["mine"]["gold"] -= $dungeon["cost"];
+ echo json_encode($dungeon);
+ }
+}
+
+function launchDungeon(){
+ $dungeon=generateMonster();
+ $opponent = $dungeon["monsters"]["floor1"];
+ echo json_encode($opponent);
+}
+
+function exitDungeon(){
+ $_SESSION["dungeon"] = false;
+ echo json_encode(array("a" => 7));//Cette ligne ne sert qu'à contourner l'erreur créé à cause de sendRequest. A revoir.
+}
+
+?>