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/dungeon.js | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) (limited to 'js/dungeon.js') 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(){ -- cgit v1.2.3-54-g00ecf