aboutsummaryrefslogtreecommitdiffstats
path: root/js/shop.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/shop.js')
-rw-r--r--js/shop.js18
1 files changed, 17 insertions, 1 deletions
diff --git a/js/shop.js b/js/shop.js
index bda3885..efb347a 100644
--- a/js/shop.js
+++ b/js/shop.js
@@ -37,7 +37,7 @@ function addItem(ret) {
var itemtag = document.querySelector("[data-name=\""+ret[0].name+"\"]");
if(!itemtag){ //si c'est la première itération de l'objet
itemhtml += "<li>";
- itemhtml += "<button type=\"button\" class=\"btn btn-primary\" onclick=\"useItem('" + ret[0].name + "')\"><span class=\"item-icon\">" + ret[0].icon + "</span><br />" + ret[0].name + "(<span data-name=\""+ ret[0].name + "\">"+ret[1]+"</span>)</button>";
+ itemhtml += "<button type=\"button\" class=\"btn btn-primary\" onclick=\"useItem('" + ret[0].name + "')\"><span class=\"item-icon\">" + ret[0].icon + "</span><br />" + ret[0].name + "(<span id=\"nbItem\" data-name=\""+ ret[0].name + "\">"+ret[1]+"</span>)</button>";
itemhtml += "</li>";
}
else{ // si c'est une n-ième itération
@@ -68,6 +68,22 @@ 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);
+ });
+ }
});
}