diff options
author | piernov <piernov@piernov.org> | 2016-05-09 22:06:30 +0200 |
---|---|---|
committer | piernov <piernov@piernov.org> | 2016-05-09 22:06:30 +0200 |
commit | f10c51f07a755d75a583f85316efbcd3bd1e4b6d (patch) | |
tree | 87419a11e12f5b7433459fcb5cb9da5211dcbd9e /js/craftmine.js | |
parent | 54635d17eef27eb2546d69599e4107b242509ced (diff) | |
parent | 2f32bc3153b7f2c2561e4603f912573921e6449f (diff) | |
download | candybox-f10c51f07a755d75a583f85316efbcd3bd1e4b6d.tar.gz candybox-f10c51f07a755d75a583f85316efbcd3bd1e4b6d.tar.bz2 candybox-f10c51f07a755d75a583f85316efbcd3bd1e4b6d.tar.xz candybox-f10c51f07a755d75a583f85316efbcd3bd1e4b6d.zip |
Merge branch 'alexichi' of ssh://piernov.org/srv/git/candybox into alexichi
Diffstat (limited to 'js/craftmine.js')
-rw-r--r-- | js/craftmine.js | 44 |
1 files changed, 36 insertions, 8 deletions
diff --git a/js/craftmine.js b/js/craftmine.js index 92fa45a..fa70809 100644 --- a/js/craftmine.js +++ b/js/craftmine.js @@ -1,17 +1,27 @@ data = { + name: "You", gold: 0, mine: 0, miners: 0, - level: 1 + level: 3, + hp: 5, + maxHP: 5, + xp: 0, + power: 3, + bonusPower: 0, + icon : "💪" } -function sendRequest(url, params, callback) { +function sendRequest(url, params, callback, isFile) { var xhr = new XMLHttpRequest(); xhr.open("POST", url); - xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); + 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; @@ -34,6 +44,16 @@ function debitAccount(amount) { updateData("gold"); } +function creditAccount(amount){ + data.gold += amount; + sendRequest("craftmine.php", "op=withdrawMine&amount="+amount, function(xhr) { + var gold = parseInt(xhr); + if(isNaN(gold)) return; + data.gold = gold; + updateData("gold"); + }); +} + function withdrawMine() { sendRequest("craftmine.php", "op=withdrawMine&amount="+data.mine, function(xhr) { var gold = parseInt(xhr); // Server's response is a string @@ -46,11 +66,17 @@ 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) updatePerso(ret.perso); 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"); }) } @@ -62,6 +88,8 @@ function updateMine() { function init() { initCraftMine(); - changeTab(); - window.setInterval(updateMine, 1000); + changeTab(); // Switch to tab specified in URL + listSaves(); // Update save list on page load + window.setInterval(updateMine, 1000); // Increase mine amount every 1 second + window.onhashchange = changeTab; // Hook changeTab from js/gui.js to hashchange event } |