diff options
Diffstat (limited to 'js/craftmine.js')
-rw-r--r-- | js/craftmine.js | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/js/craftmine.js b/js/craftmine.js index 4e6490f..b87f946 100644 --- a/js/craftmine.js +++ b/js/craftmine.js @@ -1,8 +1,12 @@ data = { + name: "You", gold: 0, mine: 0, miners: 0, - level: 1 + level: 3, + hp: 5, + xp: 0, + icon : "H" } function sendRequest(url, params, callback, isFile) { @@ -11,7 +15,10 @@ function sendRequest(url, params, callback, isFile) { if(!isFile) xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xhr.onreadystatechange = function() { if(xhr.readyState == XMLHttpRequest.DONE && xhr.status == "200") { - var data = JSON.parse(xhr.responseText); + var data = ""; + if(xhr.responseText) data = JSON.parse(xhr.responseText); + if(data.info) + showInfo(data.info); if(data.error) { showError(data.error); return; @@ -46,11 +53,22 @@ 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(ret.inventory) displayInventory(ret.inventory); + 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","miners"); + updateData("gold", "mine", "miners"); }) } |