From f171811a44364f605712aff1ca0808bfe570ef6e Mon Sep 17 00:00:00 2001 From: alexichi Date: Thu, 5 May 2016 23:06:29 +0200 Subject: add xp system and perso server side --- js/craftmine.js | 13 +++++++++++-- js/dungeon.js | 38 ++++++++++++++++++++++++++------------ js/perso.js | 5 +++++ 3 files changed, 42 insertions(+), 14 deletions(-) create mode 100644 js/perso.js (limited to 'js') diff --git a/js/craftmine.js b/js/craftmine.js index 9af9b9f..c7a396f 100644 --- a/js/craftmine.js +++ b/js/craftmine.js @@ -5,6 +5,7 @@ data = { miners: 0, level: 4, hp: 5, + xp: 0, icon : "H" } @@ -52,12 +53,20 @@ function withdrawMine() { function initCraftMine() { sendRequest("craftmine.php", "op=getCraftMine", function(ret) { + console.log(ret.perso); data.gold = parseInt(ret.gold); // Server's response is a string data.mine = 0; // Reset mine + if(ret.perso){ + data.hp = ret.perso.hp; + data.xp = ret.perso.xp; + data.level = ret.perso.lv; + displayPerso(ret.perso.hp,ret.perso.xp,ret.perso.lv); + } if(ret.shop) displayShop(ret.shop); displayInventory(ret.inventory); - if(typeof ret.dungeon.mob == "undefined") displayDungeon(0,1,true); - else displayDungeon(ret.dungeon.mob,ret.dungeon.flat,true); + if(ret.dungeon == false){}//if we have left the donjon + else if(typeof ret.dungeon.mob == "undefined") displayDungeon(0,1,true); //if we have reload just after buying the ticket + else displayDungeon(ret.dungeon.mob,ret.dungeon.flat,true);//if we have reload in the middle of the dungeon data.miners = parseInt(ret.miners); updateData("gold", "mine", "miners"); }) diff --git a/js/dungeon.js b/js/dungeon.js index c6ce014..65d1081 100644 --- a/js/dungeon.js +++ b/js/dungeon.js @@ -50,11 +50,12 @@ function strike(ret,nb, f){ var mobLife = document.getElementById("lifeMob").innerHTML; var persoLife = document.getElementById("lifePerso").innerHTML; if(mobLife == 0){ - endBattle("perso",nb,f); + data.hp = persoLife; + endBattle("perso",nb,f,ret); return; } else if(persoLife == 0){ - endBattle("mob",nb); + endBattle("mob",nb,f,ret); return; } if(hitRate<50+10*lvDiff){ @@ -68,19 +69,32 @@ function strike(ret,nb, f){ battle(ret,nb,f); } -function endBattle(v,nb, f){ +function endBattle(v,nb, f, ret){ 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 + //To level up you have to obtain 2 xp to go to lv 3, 3 to go to lv 4, etc + //A mob level 2 , if defeated gives you 2 xp, ...etc + else{ + data.xp += ret[nb].xp; + if(data.xp>=data.level){ + data.xp-=data.level; + data.level++; + //need to send the xp to the server + sendRequest("craftmine.php", "op=updatePerso&hp="+data.hp+"&xp="+data.xp+"&lv="+data.level, function(){ + displayPerso(data.hp,data.xp,data.level); + }); + } + 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); } - var tmphtml = "Le " + v + " a gagné."; - tmphtml += "" - document.getElementById("tab4").innerHTML = tmphtml; - displayExit(); - sendRequest("craftmine.php", "op=sendDungeonProgress&floor="+f+"&mob="+nb); } function displayExit(){ diff --git a/js/perso.js b/js/perso.js new file mode 100644 index 0000000..365cf54 --- /dev/null +++ b/js/perso.js @@ -0,0 +1,5 @@ +function displayPerso(hp,xp,lv){ + document.getElementById("hp").innerHTML = hp; + document.getElementById("lv").innerHTML = lv; + document.getElementById("xp").innerHTML = xp; +} -- cgit v1.2.3-54-g00ecf