let img; let update; let playerID; let lastPowerID = 0; async function useInv(id, type) { try { const resp = await $.ajax({ url: `${window.api}player/inv/${type}/${id}`, type: "GET", xhrFields: { withCredentials: true }, }); msg(resp.Status, resp.Message); } catch (err) { msg( err.responseJSON?.Status || "Erro", err.responseJSON?.Message || "Algo deu errado.", ); } } function invpower() { $.ajax({ url: `${window.api}player/inv/ph`, type: "GET", xhrFields: { withCredentials: true }, success(resp) { const $invpower = $("#powers ul"); let latestId = lastPowerID; resp.InvPws.forEach((item) => { if (item.id > lastPowerID) { const $li = $("
  • "); $li.append($("").text(item.name)); const $del = $("") .attr("id", "DelBTN") .append( $("").addClass("material-symbols-outlined").text("close"), ); $li.on("click", () => alert(item.desc)); $del.on("click", (e) => { e.stopPropagation(); useInv(item.id, "ph/del"); $del.closest("li").remove(); }); $li.append($del); $invpower.append($li); if (item.id > latestId) latestId = item.id; } }); lastPowerID = latestId; }, }); } function invPlayer() { $.ajax({ url: `${window.api}player/inv`, type: "GET", xhrFields: { withCredentials: true }, success(resp) { const $invList = $("#inv ul").empty(); resp.InvItems.forEach((item) => { const $li = $("
  • "); $li.append($("") .attr("id", "DelBTN") .append( $("").addClass("material-symbols-outlined").text("close"), ); $li.on("click", () => useInv(item.id, "use")); $delBtn.on("click", (e) => { e.stopPropagation(); useInv(item.id, "del"); }); $li.append($delBtn); $invList.append($li); }); $("#invPA").text(resp.invPeso); }, error() { $("#inv ul").empty(); $("#invPA").text(0); }, }); } function invPowerAdd() { const habilidade = $("input[name='habilidade']").val(); const desc = $("textarea[name='desc']").val(); $.ajax({ url: `${window.api}player/inv/ph`, type: "POST", data: { nameph: habilidade, descph: desc }, xhrFields: { withCredentials: true }, success(resp) { msg(resp.Status, resp.Message); $("input[name='habilidade'], textarea[name='desc']").val(""); }, error(resp) { msg( resp.responseJSON?.Status || "Erro", resp.responseJSON?.Message || "Algo deu errado.", ); }, }); } function invAdd() { const nome = $("input[name='item_name']").val(); const durabilidade = $("select[name='durabilite']").val(); const peso = $("input[name='peso']").val(); const quantidade = $("input[name='quantidade']").val(); $.ajax({ url: `${window.api}player/inv`, type: "POST", data: { item_name: nome, durabilite: durabilidade, peso, quantidade }, xhrFields: { withCredentials: true }, success(resp) { msg(resp.Status, resp.Message); $( "input[name='peso'], input[name='quantidade'], input[name='item_name'], select", ).val(""); $("select[name='durabilite']").val("duravel?"); }, error(resp) { msg( resp.responseJSON?.Status || "Erro", resp.responseJSON?.Message || "Algo deu errado.", ); }, }); } function loadFicha() { $.ajax({ url: `${window.api}player`, type: "GET", xhrFields: { withCredentials: true }, success(resp) { if (!img) { img = resp.Foto; $("#hero").attr("src", `data:image/*;base64,${resp.Foto}`); } if (!playerID) playerID = resp.PlayerID; $("#vdp").text(resp.Vida); $("#nmp").text(resp.PlayerName); $("#lvp").text(resp.Level); $("#idp").text(resp.Idade); $("#alp").text(resp.Altura); $("#conhecimento").text(resp.Conhecimento); $("#força").text(resp.Força); $("#destresa").text(resp.Destresa); $("#constitution").text(resp.Constituição); $("#inteligencia").text(resp.Inteligencia); $("#cárisma").text(resp.Cárisma); $("#mip").text(resp.Inventario); $("#lore").text(resp.Descrição); if ($("#lore_edit").attr("placeholder") !== resp.Descrição) { $("#lore_edit").attr("placeholder", resp.Descrição); $("#lore_edit").val(resp.Descrição); } const statusMap = [ { limit: 0, text: "Status: morto(a)" }, { limit: 5, text: "Status: morrendo" }, { limit: 50, text: "Status: muito ferido(a)" }, { limit: 70, text: "Status: ferido(a)" }, { limit: 100, text: "Status: normal" }, ]; const status = statusMap.find((s) => resp.VidaPorcentagem <= s.limit); $("#statusPlayer").text(status?.text || "Status: desconhecido"); }, error() { window.location.href = "login.html"; }, }); } function rollLoad() { $.ajax({ url: `${window.api}roll`, type: "GET", xhrFields: { withCredentials: true }, success(resp) { let latestId = update || 0; resp.Logs.forEach((item) => { if (item.id > (update || 0)) { const $li = $("
  • "); $li.append($("