aboutsummaryrefslogtreecommitdiffstats
path: root/inc/dungeon.inc
diff options
context:
space:
mode:
Diffstat (limited to 'inc/dungeon.inc')
-rw-r--r--inc/dungeon.inc66
1 files changed, 66 insertions, 0 deletions
diff --git a/inc/dungeon.inc b/inc/dungeon.inc
new file mode 100644
index 0000000..521303e
--- /dev/null
+++ b/inc/dungeon.inc
@@ -0,0 +1,66 @@
+<?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),
+ intval($monster->xp),
+ intval($monster->power),
+ (string)$monster->icon);
+ }
+ }
+ return $dungeon;
+}
+
+function initDungeon() {
+ $_SESSION["dungeon"]["access"] = true;
+}
+
+function sendDungeon() {
+ if(!empty($_SESSION["dungeon"]))
+ return $_SESSION["dungeon"];
+ 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(){
+ $f= $_POST["floor"];
+ $dungeon=generateMonster();
+ $opponent = $dungeon["monsters"]["floor".$f];
+ echo json_encode($opponent);
+}
+
+function sendDungeonProgress(){
+ $f= $_POST["floor"];
+ $nb=$_POST["mob"];
+ $_SESSION["dungeon"]["flat"] = $f;
+ $_SESSION["dungeon"]["mob"] = $nb;
+}
+
+
+function exitDungeon(){
+ $_SESSION["dungeon"] = false;
+}
+
+?>