aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--js/shop.js28
1 files changed, 11 insertions, 17 deletions
diff --git a/js/shop.js b/js/shop.js
index ce0ecd8..4c04572 100644
--- a/js/shop.js
+++ b/js/shop.js
@@ -41,7 +41,7 @@ function addItem(ret) {
else{ // si c'est une n-ième itération
itemtag.innerHTML=ret[1];
}
-
+
var invcontent = document.getElementById("tab3");
if(invcontent.children.length <= 1)
@@ -66,22 +66,16 @@ function buyItem(name) {
function useItem(name) {
sendRequest("craftmine.php", "op=useItem&item="+name, function(ret) {
- if(parseInt(ret[1])>=0){
- var nb = parseInt(document.getElementById("nbItem").innerHTML);
- if(nb>0){
- nb--;
- switch(ret[0].name){
- case "Life Bottle": data.hp = parseInt(data.hp) + 3; break;
- case "Strength Bottle" : break; // to do
- case "Wooden Sword" : break; //to do
- case "Metal Sword" : break; //to do
- }
- }
- document.getElementById("nbItem").innerHTML = nb;
- sendRequest("craftmine.php", "op=updatePerso&hp="+data.hp+"&xp="+data.xp+"&lv="+data.level, function(){
- displayPerso(data.hp,data.xp,data.level);
- });
- }
+ if(!ret.item) return;
+ if(ret.perso) updatePerso(ret.perso);
+
+ var item = document.querySelector("[data-name=\""+ret.item[0].name+"\"]");
+ var nb = ret.item[1];
+
+ if(nb>=1)
+ item.innerHTML = nb;
+ else
+ item.parentNode.parentNode.parentNode.removeChild(item.parentNode.parentNode); // Remove <li> item from the <ul> list
});
}