2022-12-29 10:58:51 +00:00
|
|
|
function pullSlots() {
|
|
|
|
const { amount, currency } = getWager();
|
|
|
|
|
|
|
|
console.log({amount, currency})
|
|
|
|
|
|
|
|
disableWager();
|
|
|
|
clearResult();
|
|
|
|
document.getElementById("casinoSlotsPull").disabled = true;
|
|
|
|
|
|
|
|
const xhr = new XMLHttpRequest();
|
|
|
|
xhr.open("post", "/casino/slots");
|
|
|
|
xhr.setRequestHeader('xhr', 'xhr');
|
|
|
|
xhr.onload = handleSlotsResponse.bind(null, xhr);
|
|
|
|
|
|
|
|
const form = new FormData();
|
|
|
|
form.append("formkey", formkey());
|
|
|
|
form.append("wager", amount);
|
|
|
|
form.append("currency", currency);
|
|
|
|
|
|
|
|
xhr.send(form);
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleSlotsResponse(xhr) {
|
|
|
|
let response;
|
|
|
|
|
|
|
|
try {
|
|
|
|
response = JSON.parse(xhr.response);
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
const succeeded =
|
2023-08-08 17:06:03 +00:00
|
|
|
xhr.status >= 200 && xhr.status < 300 && response && !response.details;
|
2022-12-29 10:58:51 +00:00
|
|
|
|
|
|
|
if (succeeded) {
|
|
|
|
const { game_state, gambler } = response;
|
|
|
|
const state = JSON.parse(game_state);
|
|
|
|
const reels = Array.from(document.querySelectorAll(".slots_reel"));
|
|
|
|
const symbols = state.symbols.split(",");
|
|
|
|
|
|
|
|
for (let i = 0; i < 3; i++) {
|
|
|
|
reels[i].innerHTML = symbols[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
let className;
|
|
|
|
|
|
|
|
if (state.text.includes("Jackpot")) {
|
|
|
|
className = "warning";
|
|
|
|
} else if (state.text.includes("Won")) {
|
|
|
|
className = "success";
|
|
|
|
} else if (state.text.includes("Lost")) {
|
|
|
|
className = "danger";
|
|
|
|
} else {
|
|
|
|
className = "success";
|
|
|
|
}
|
|
|
|
|
|
|
|
updateResult(state.text, className);
|
|
|
|
updatePlayerCurrencies(gambler);
|
|
|
|
reloadFeed()
|
|
|
|
} else {
|
2023-08-08 17:06:03 +00:00
|
|
|
updateResult(response.details, "danger");
|
|
|
|
console.error(response.details);
|
2022-12-29 10:58:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
enableWager();
|
|
|
|
document.getElementById("casinoSlotsPull").disabled = false;
|
|
|
|
}
|