|
|
|
@ -4,24 +4,37 @@
|
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
var inventoryloadedfromplacepopup = false;
|
|
|
|
|
|
|
|
|
|
function loadInventory(reload) {
|
|
|
|
|
function loadInventory(reload, target) {
|
|
|
|
|
if (typeof target != "string") {
|
|
|
|
|
target = "#inventory-page";
|
|
|
|
|
}
|
|
|
|
|
inventoryloadedfromplacepopup = false;
|
|
|
|
|
if ($("#place-popup").hasClass("modal-in")) {
|
|
|
|
|
inventoryloadedfromplacepopup = true;
|
|
|
|
|
}
|
|
|
|
|
if (typeof reload != "boolean") {
|
|
|
|
|
reload = false;
|
|
|
|
|
// Make it reload if there's already stuff there,
|
|
|
|
|
// to keep the items from disappearing and coming back
|
|
|
|
|
if ($("#item-bin .item-col").length > 0) {
|
|
|
|
|
if ($(target + " .item-bin .item-col").length > 0) {
|
|
|
|
|
reload = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (reload == false) {
|
|
|
|
|
$("#item-bin .item-col").remove();
|
|
|
|
|
$("#item-bin #bag-preloader").removeClass("display-none");
|
|
|
|
|
$(target + " .item-bin .item-col").remove();
|
|
|
|
|
$(target + " .item-bin .bag-preloader").removeClass("display-none");
|
|
|
|
|
}
|
|
|
|
|
callAPI("inventory", {
|
|
|
|
|
username: localStorage.getItem("username"),
|
|
|
|
|
password: localStorage.getItem("password")
|
|
|
|
|
}, function (resp) {
|
|
|
|
|
if (resp.items.length == 0) {
|
|
|
|
|
$(target + " .bag-empty").removeClass("display-none");
|
|
|
|
|
} else {
|
|
|
|
|
$(target + " .bag-empty").addClass("display-none");
|
|
|
|
|
}
|
|
|
|
|
var items = [];
|
|
|
|
|
for (var i = 0; i < resp.items.length; i++) {
|
|
|
|
|
var item = resp.items[i];
|
|
|
|
@ -41,49 +54,57 @@ function loadInventory(reload) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$("#item-bin .item-col").remove();
|
|
|
|
|
$(target + " .item-bin .item-col").remove();
|
|
|
|
|
if (reload == false) {
|
|
|
|
|
$("#item-bin #bag-preloader").addClass("display-none");
|
|
|
|
|
$(target + " .item-bin .bag-preloader").addClass("display-none");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
items.forEach(function (item) {
|
|
|
|
|
$("#item-bin").append('<div class="col-100 tablet-33 desktop-25 item-col">'
|
|
|
|
|
var usebtn = "";
|
|
|
|
|
if (item.classname == "healmagic" || (inventoryloadedfromplacepopup && item.classname == "artifact")) {
|
|
|
|
|
usebtn = '<button class="button button-fill margin-top useitem-button">Use</button>';
|
|
|
|
|
}
|
|
|
|
|
$(target + " .item-bin").append('<div class="col-100 tablet-33 ' + (target == "#inventory-page" ? "desktop-25 " : "") + 'item-col">'
|
|
|
|
|
+ '<div class="card padding-half">'
|
|
|
|
|
+ (item.qty > 1 ? '<span class="badge color-green text-color-black padding">x' + item.qty + '</span>' : "")
|
|
|
|
|
+ '<div class="item card-content" data-uuids="' + item.uuids.join("|") + '" data-qty="' + item.qty + '">'
|
|
|
|
|
+ '<i class="item-icon ' + item.icon + ' text-color-' + item.color + '"></i><br />'
|
|
|
|
|
+ '<h3>' + item.name + '</h3>'
|
|
|
|
|
+ item.description
|
|
|
|
|
+ (item.classname == "healmagic" ? '<button class="button button-fill margin-top useitem-button">Use</button>' : '')
|
|
|
|
|
+ usebtn
|
|
|
|
|
+ '</div>'
|
|
|
|
|
+ '</div>'
|
|
|
|
|
+ '</div>');
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
}, function (msg) {
|
|
|
|
|
app.dialog.alert(msg, "Error");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$("body").on("click", ".useitem-button", function () {
|
|
|
|
|
var itemdom = $(this).parent(".item");
|
|
|
|
|
var uuids = itemdom.data("uuids") + "";
|
|
|
|
|
console.log(uuids);
|
|
|
|
|
console.log(uuids.split("|")[0]);
|
|
|
|
|
var qty = itemdom.data("qty");
|
|
|
|
|
var uuid = uuids.split("|")[0];
|
|
|
|
|
callAPI("useitem", {
|
|
|
|
|
username: localStorage.getItem("username"),
|
|
|
|
|
password: localStorage.getItem("password"),
|
|
|
|
|
uuid: uuid
|
|
|
|
|
}, function (success) {
|
|
|
|
|
app.toast.show({
|
|
|
|
|
text: '<i class="game-icon game-icon-school-bag"></i> ' + success.msg,
|
|
|
|
|
position: "center",
|
|
|
|
|
destroyOnClose: true,
|
|
|
|
|
closeTimeout: 5000
|
|
|
|
|
// Prevent multiple events from firing
|
|
|
|
|
$(target).unbind("click");
|
|
|
|
|
|
|
|
|
|
$(target).on("click", ".useitem-button", function () {
|
|
|
|
|
var itemdom = $(this).parent(".item");
|
|
|
|
|
var uuids = itemdom.data("uuids") + "";
|
|
|
|
|
console.log(uuids);
|
|
|
|
|
console.log(uuids.split("|")[0]);
|
|
|
|
|
var qty = itemdom.data("qty");
|
|
|
|
|
var uuid = uuids.split("|")[0];
|
|
|
|
|
callAPI("useitem", {
|
|
|
|
|
username: localStorage.getItem("username"),
|
|
|
|
|
password: localStorage.getItem("password"),
|
|
|
|
|
uuid: uuid,
|
|
|
|
|
placeid: (inventoryloadedfromplacepopup ? $("#place-popup").data("placeid") : null)
|
|
|
|
|
}, function (success) {
|
|
|
|
|
app.toast.show({
|
|
|
|
|
text: '<i class="game-icon game-icon-school-bag"></i> ' + success.msg,
|
|
|
|
|
position: "center",
|
|
|
|
|
destroyOnClose: true,
|
|
|
|
|
closeTimeout: 5000
|
|
|
|
|
});
|
|
|
|
|
loadInventory(true, target);
|
|
|
|
|
}, function (error) {
|
|
|
|
|
//app.dialog.alert(error, "Error");
|
|
|
|
|
});
|
|
|
|
|
loadInventory(true);
|
|
|
|
|
}, function (error) {
|
|
|
|
|
app.dialog.alert(error, "Error");
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|