// Kiss my ass if you're judgin' const CELL_TO_NUMBER_LOOKUP = { 1: 3, 2: 6, 3: 9, 4: 12, 5: 15, 6: 18, 7: 21, 8: 24, 9: 27, 10: 30, 11: 33, 12: 36, 13: 2, 14: 5, 15: 8, 16: 11, 17: 14, 18: 17, 19: 20, 20: 23, 21: 26, 22: 29, 23: 32, 24: 35, 25: 1, 26: 4, 27: 7, 28: 10, 29: 13, 30: 16, 31: 19, 32: 22, 33: 25, 34: 28, 35: 31, 36: 34 }; function initializeGame() { buildRouletteTable(); updateResult("Rolls occur every five minutes", "success"); requestRouletteBets(); } function buildRouletteTable() { const table = document.getElementById('roulette-table'); const reds = [1, 3, 5, 7, 9, 12, 14, 16, 18, 19, 21, 23, 25, 27, 30, 32, 34, 36]; let html = ""; // Lines html += `
Line 1
Line 2
Line 3
Line 4
Line 5
Line 6
`; // First Column html += "
"; html += `
00
` for (let i = 1; i < 13; i++) { const correctNumber = CELL_TO_NUMBER_LOOKUP[i]; const isRed = reds.includes(correctNumber); html += `
${correctNumber}
`; } html += `
Col 3
`; html += "
"; // Second Column html += "
"; html += `
` for (let i = 13; i < 25; i++) { const correctNumber = CELL_TO_NUMBER_LOOKUP[i]; const isRed = reds.includes(correctNumber); html += `
${correctNumber}
`; } html += `
Col 2
`; html += "
"; // Third Column html += "
"; html += `
0
` for (let i = 25; i < 37; i++) { const correctNumber = CELL_TO_NUMBER_LOOKUP[i]; const isRed = reds.includes(correctNumber); html += `
${correctNumber}
`; } html += `
Col 1
`; html += "
"; // Line Bets and 1:1 Bets html += `
1st12
2nd12
3rd12
1:18
EVEN
RED
BLACK
ODD
19:36
`; table.innerHTML = html; } function formatFlatBets(bets) { let flatBets = []; for (const betCollection of Object.values(bets)) { flatBets = flatBets.concat(betCollection) } return flatBets; } function formatNormalizedBets(bets) { const normalizedBets = { gamblers: [], gamblersByName: {} }; const flatBets = formatFlatBets(bets); for (const bet of flatBets) { if (!normalizedBets.gamblers.includes(bet.gambler_username)) { normalizedBets.gamblers.push(bet.gambler_username); } if (!normalizedBets.gamblersByName[bet.gambler_username]) { normalizedBets.gamblersByName[bet.gambler_username] = { name: bet.gambler_username, avatar: bet.gambler_profile_url, profile: `/@${bet.gambler_username}`, wagerTotal: { coins: 0, marseybux: 0 }, wagers: [] } } const entry = normalizedBets.gamblersByName[bet.gambler_username]; entry.wagerTotal[bet.wager.currency] += bet.wager.amount; const existingWager = entry.wagers.find(wager => wager.bet === bet.bet && wager.which === bet.which); if (existingWager) { existingWager.amounts[bet.wager.currency] += bet.wager.amount; } else { const newEntry = { bet: bet.bet, which: bet.which, amounts: { coins: 0, marseybux: 0 }, }; newEntry.amounts[bet.wager.currency] += bet.wager.amount; entry.wagers.push(newEntry); } } return normalizedBets; } function buildPokerChip(avatar) { return `
`; } function buildRouletteBets(bets) { const betArea = document.getElementById("roulette-bets"); const flatBets = formatFlatBets(bets); const normalizedBets = formatNormalizedBets(bets); const coinImgHtml = ` coin `; const marseybuxImgHtml = ` marseybux `; const { participants, coin, marseybux } = flatBets.reduce((prev, next) => { if (!prev.participants.includes(next.gambler_username)) { prev.participants.push(next.gambler_username); } if (next.wager.currency == 'coins') { prev.coin += next.wager.amount; } else { prev.marseybux += next.wager.amount; } return prev; }, { participants: [], coin: 0, marseybux: 0 }); const coinText = `${coin} ${coinImgHtml}`; const marseybuxText = `${marseybux} ${marseybuxImgHtml}`; const playerText = participants.length > 1 ? `${participants.length} players are` : `1 player is`; const totalText = coin && marseybux ? `${coinText} and ${marseybuxText}` : coin ? coinText : marseybuxText; const fullTotalText = participants.length === 0 ? "No one has placed a bet" : `${playerText} betting a total of ${totalText}`; let betHtml = ` ${fullTotalText}
`; for (player of normalizedBets.gamblers) { const { name, avatar, wagerTotal, wagers } = normalizedBets.gamblersByName[player]; betHtml += `
`; // Heading betHtml += `
`; betHtml += buildPokerChip(avatar); const coinText = wagerTotal.coins > 0 ? `${wagerTotal.coins} ${coinImgHtml}` : ""; const procoinText = wagerTotal.marseybux > 0 ? `${wagerTotal.marseybux} ${marseybuxImgHtml}` : ""; const bettingText = coinText && procoinText ? `${coinText} and ${procoinText}` : coinText || procoinText; betHtml += `

${name} is betting ${bettingText}:

`; betHtml += `
`; // Individual bets betHtml += ``; betHtml += `
`; } betArea.innerHTML = betHtml; } function placeChip(bet, which) { const { amount, currency: safeCurrency, localCurrency: currency } = getWager(); const whichNice = which == 37 ? "00" : which; const texts = { STRAIGHT_UP_BET: `Bet ${amount} ${currency} on ${whichNice}?\nYou could win ${amount * 35} ${currency}.`, LINE_BET: `Bet ${amount} ${currency} on line ${which}?\nYou could win ${amount * 5} ${currency}.`, COLUMN_BET: `Bet ${amount} ${currency} column ${which}?\nYou could win ${amount * 2} ${currency}.`, DOZEN_BET: `Bet ${amount} ${currency} dozen ${which}?\nYou could win ${amount * 2} ${currency}.`, EVEN_ODD_BET: `Bet ${amount} ${currency} that the number will be ${which.toLowerCase()}?\nYou could win ${amount} ${currency}.`, RED_BLACK_BET: `Bet ${amount} ${currency} that the number will be ${which.toLowerCase()}?\nYou could win ${amount} ${currency}.`, HIGH_LOW_BET: `Bet ${amount} ${currency} that the number will be ${which === "HIGH" ? "higher than 18" : "lower than 19"}?\nYou could win ${amount} ${currency}.`, } const text = texts[bet] || ""; const confirmed = window.confirm(text); if (confirmed) { const xhr = new XMLHttpRequest(); xhr.open("post", "/casino/roulette/place_bet"); xhr.setRequestHeader('xhr', 'xhr'); xhr.onload = handleRouletteResponse.bind(null, xhr); const form = new FormData(); form.append("formkey", formkey()); form.append("bet", bet); form.append("which", which); form.append("wager", amount); form.append("currency", safeCurrency); xhr.send(form); } } function addChipsToTable(bets) { const flatBets = formatFlatBets(bets); for (const bet of flatBets) { const tableElement = document.getElementById(`${bet.bet}#${bet.which}`); tableElement.style.position = 'relative'; const count = tableElement.dataset.count ? parseInt(tableElement.dataset.count) + 1 : 1; tableElement.dataset.count = count; const chip = buildPokerChip(bet.gambler_profile_url) tableElement.innerHTML = `${tableElement.innerHTML}
${chip}
`; } } function requestRouletteBets() { const xhr = new XMLHttpRequest(); xhr.open("get", "/casino/roulette/bets"); xhr.setRequestHeader('xhr', 'xhr'); xhr.onload = handleRouletteResponse.bind(null, xhr); xhr.send(); } function handleRouletteResponse(xhr) { let response; try { response = JSON.parse(xhr.response); } catch (error) { console.error(error); } const succeeded = xhr.status >= 200 && xhr.status < 300 && response && !response.details; if (succeeded) { buildRouletteBets(response.bets); addChipsToTable(response.bets); updatePlayerCurrencies(response.gambler); updateResult("Rolls occur every five minutes", "success"); } else { updateResult("Unable to place that bet.", "danger"); } } initializeGame();