From 1efc4a15c8ab913bf8bdb1aef9f3b5720b3b7762 Mon Sep 17 00:00:00 2001 From: alexichi Date: Thu, 5 May 2016 20:28:26 +0200 Subject: add dungeon server side and improve some details like the difference between floors --- craftmine.php | 1 + data/items.xml | 4 +-- data/monsters.xml | 2 +- inc/dungeon.inc | 16 ++++++++--- inc/messages.inc | 3 +- js/craftmine.js | 7 +++-- js/dungeon.js | 82 ++++++++++++++++++++++++++++++++++++++++++++++--------- 7 files changed, 90 insertions(+), 25 deletions(-) diff --git a/craftmine.php b/craftmine.php index 242e1fd..43fdc66 100644 --- a/craftmine.php +++ b/craftmine.php @@ -51,6 +51,7 @@ switch($op) { case "buildDungeon" : buildDungeon(); break; case "launchDungeon" : launchDungeon(); break; case "exitDungeon" : exitDungeon(); break; + case "sendDungeonProgress" : sendDungeonProgress(); break; case "saveGame": saveGame(); break; case "downSave": downSave(); break; case "listSaves": listSaves(); break; diff --git a/data/items.xml b/data/items.xml index 8888796..6c19b84 100644 --- a/data/items.xml +++ b/data/items.xml @@ -25,7 +25,7 @@ Life Bottle 5 - 💧 + 🍶 A bottle which can heal you by regaining hp @@ -34,7 +34,7 @@ 20 - 💧 + 🍶 If used, you have 20% more chance to hit your enemy during the battle diff --git a/data/monsters.xml b/data/monsters.xml index 86cf422..630e83a 100644 --- a/data/monsters.xml +++ b/data/monsters.xml @@ -4,7 +4,7 @@ monster1 1 - 2 + 3 m diff --git a/inc/dungeon.inc b/inc/dungeon.inc index 81e2ba7..ebe74b7 100644 --- a/inc/dungeon.inc +++ b/inc/dungeon.inc @@ -21,12 +21,12 @@ function generateMonster(){ } function initDungeon() { - $_SESSION["dungeon"] = true; + $_SESSION["dungeon"]["access"] = true; } function sendDungeon() { if(!empty($_SESSION["dungeon"])) - return generateMonster(); + return $_SESSION["dungeon"]; else return false; } @@ -43,14 +43,22 @@ function buildDungeon() { } function launchDungeon(){ + $f= $_POST["floor"]; $dungeon=generateMonster(); - $opponent = $dungeon["monsters"]["floor1"]; + $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; - echo json_encode(array("a" => 7));//Cette ligne ne sert qu'à contourner l'erreur créé à cause de sendRequest. A revoir. } ?> diff --git a/inc/messages.inc b/inc/messages.inc index c51adba..1f25ed3 100644 --- a/inc/messages.inc +++ b/inc/messages.inc @@ -6,8 +6,7 @@ $messages = array( "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.", - "dungeon_already_available" => "You can already access the dungeon" - + "dungeon_already_available" => "You can already access the dungeon", "gamesave_ok" => "Game saved.", "gamesave_error" => "An error occured when trying to save the game.", "gamesave_not_found" => "Couldn't find the specified save file.", diff --git a/js/craftmine.js b/js/craftmine.js index ffc9b5e..9af9b9f 100644 --- a/js/craftmine.js +++ b/js/craftmine.js @@ -3,8 +3,8 @@ data = { gold: 0, mine: 0, miners: 0, - level: 1, - hp: 1, + level: 4, + hp: 5, icon : "H" } @@ -56,7 +56,8 @@ function initCraftMine() { data.mine = 0; // Reset mine if(ret.shop) displayShop(ret.shop); displayInventory(ret.inventory); - if(ret.dungeon) displayDungeon(); + if(typeof ret.dungeon.mob == "undefined") displayDungeon(0,1,true); + else displayDungeon(ret.dungeon.mob,ret.dungeon.flat,true); data.miners = parseInt(ret.miners); updateData("gold", "mine", "miners"); }) diff --git a/js/dungeon.js b/js/dungeon.js index d20a3cf..c6ce014 100644 --- a/js/dungeon.js +++ b/js/dungeon.js @@ -1,41 +1,97 @@ +var timeout; + function buildDungeon(){ sendRequest("craftmine.php", "op=buildDungeon", function(ret) { - displayDungeon(); + displayDungeon(0,1,true);//mob 0 in the floor 1 and I access the dungeon for the first dungeon debitAccount(ret.cost); showInfo("You can acces the dungeon now. Good Luck."); }); } -function displayDungeon(){ +function displayDungeon(nb,f,firstTime){ var tmphtml = "
"; - tmphtml += ""; + tmphtml += ""; document.getElementById("tab4").innerHTML = tmphtml; } -function launchDungeon(){ - sendRequest("craftmine.php", "op=launchDungeon", function(ret) { - document.getElementById("launch").style.display = "none"; - displayBattle(ret); +function launchDungeon(nb,f,firstTime){ + sendRequest("craftmine.php", "op=launchDungeon&floor="+f, function(ret) { + if(nb==0 && firstTime){ + document.getElementById("launch").style.display = "none"; + } + displayBattle(ret,nb,f); }); } -function displayBattle(ret){ +function displayBattle(ret,nb,f){ var tmphtml = "
"; - tmphtml += "

Battle

"; + tmphtml += "

Battle floor "+ f +"

"; tmphtml += "
    "; tmphtml += "
  • "; - tmphtml += ""; - tmphtml += ""; + tmphtml += ""; + tmphtml += ""; tmphtml += "
  • "; tmphtml += "
"; tmphtml += "
"; - tmphtml += "

"; - tmphtml += ""; document.getElementById("tab4").innerHTML = tmphtml; + displayExit(); + battle(ret,nb,f); +} + +function battle(ret,nb,f){ + timeout=window.setTimeout(strike, 1000, ret, nb, f); +} + +function strike(ret,nb, f){ + var lvDiff = data.level-parseInt(ret[0].level); + var hitRate = Math.floor((Math.random() * 100) + 1); + var mobLife = document.getElementById("lifeMob").innerHTML; + var persoLife = document.getElementById("lifePerso").innerHTML; + if(mobLife == 0){ + endBattle("perso",nb,f); + return; + } + else if(persoLife == 0){ + endBattle("mob",nb); + return; + } + if(hitRate<50+10*lvDiff){ + mobLife--; + document.getElementById("lifeMob").innerHTML = parseInt(mobLife); + } + else{ + persoLife--; + document.getElementById("lifePerso").innerHTML = parseInt(persoLife); + } + battle(ret,nb,f); +} + +function endBattle(v,nb, f){ + window.clearTimeout(timeout); + if(v=="mob")exitDungeon();//if you die in the dungeon, you are immediately sent out of the dungeon + nb++;//go to the next mob in the same floor + if(nb>=3){//floor changing + nb=0;//reset the number of the mob + f++;//increment the number of the floor + } + var tmphtml = "Le " + v + " a gagné."; + tmphtml += "" + document.getElementById("tab4").innerHTML = tmphtml; + displayExit(); + sendRequest("craftmine.php", "op=sendDungeonProgress&floor="+f+"&mob="+nb); +} + +function displayExit(){ + var tmphtml = "

"; + tmphtml += ""; + document.getElementById("tab4").innerHTML += tmphtml; } function exitDungeon(){ sendRequest("craftmine.php", "op=exitDungeon", function() { + window.clearTimeout(timeout); document.getElementById("tab4").innerHTML = "

Look at how poor you are! You can't access the dungeon, it is only for the elite.

"; showInfo("You have left the dungeon"); }); -- cgit v1.2.3-54-g00ecf