From 9f51259ee6ad0945544c39649197e7f61445e548 Mon Sep 17 00:00:00 2001 From: justcool393 Date: Mon, 21 Nov 2022 06:44:16 -0800 Subject: [PATCH] [DO NOT MERGE] roulette 0 and 00 bets redux (#470) * backend support for roulette betting on 0 and 00 * casino: roulette: add 0 and 00 frontend * add spacer * roulette: fix the thing * don't payout where needful not to * sanity check * roulette: validate requests properly * roulette actions from API make more sane --- files/helpers/roulette.py | 34 +++++++++++++-------- files/routes/casino.py | 27 ++++++++++------ files/templates/casino/roulette_screen.html | 13 +++++++- 3 files changed, 50 insertions(+), 24 deletions(-) diff --git a/files/helpers/roulette.py b/files/helpers/roulette.py index 2db069f41..df80a4eaa 100644 --- a/files/helpers/roulette.py +++ b/files/helpers/roulette.py @@ -10,13 +10,13 @@ from files.helpers.alerts import * from files.helpers.get import get_account class RouletteAction(str, Enum): - STRAIGHT_UP_BET = "STRAIGHT_UP_BET" - LINE_BET = "LINE_BET" - COLUMN_BET = "COLUMN_BET" - DOZEN_BET = "DOZEN_BET" - EVEN_ODD_BET = "EVEN_ODD_BET" - RED_BLACK_BET = "RED_BLACK_BET" - HIGH_LOW_BET = "HIGH_LOW_BET" + STRAIGHT_UP_BET = "STRAIGHT_UP_BET", lambda x:x and x >= 0 and x <= 37 + LINE_BET = "LINE_BET", lambda x:x in LINES + COLUMN_BET = "COLUMN_BET", lambda x:x in COLUMNS + DOZEN_BET = "DOZEN_BET", lambda x:x in DOZENS + EVEN_ODD_BET = "EVEN_ODD_BET", lambda x:x in [y.value for y in RouletteEvenOdd] + RED_BLACK_BET = "RED_BLACK_BET", lambda x:x in [y.value for y in RouletteRedBlack] + HIGH_LOW_BET = "HIGH_LOW_BET", lambda x:x in [y.value for y in RouletteHighLow] class RouletteEvenOdd(str, Enum): @@ -156,12 +156,7 @@ def spin_roulette_wheel(): if len(participants) > 0: number = randint(0, 37) # 37 is 00 - if number > 0 and number < 37: # 0 and 00 do not pay anything - winners, payouts, rewards_by_game_id = determine_roulette_winners(number, bets) - else: - winners = [] - payouts = {} - rewards_by_game_id = {} + winners, payouts, rewards_by_game_id = determine_roulette_winners(number, bets) if number == 37: number = '00' @@ -243,6 +238,13 @@ def determine_roulette_winners(number, bets): if int(bet['which']) == number: add_to_winnings(bet) + if number == 0 or number == 37: + return winners, payouts, rewards_by_game_id + + def is_green(bet): + val = int(bet['which']) + return val == 0 or val == 37 + # Line Bet line = -1 for i in range(1, 7): @@ -250,6 +252,7 @@ def determine_roulette_winners(number, bets): line = i for bet in bets[RouletteAction.LINE_BET]: + if is_green(bet): continue if int(bet['which']) == line: add_to_winnings(bet) @@ -260,6 +263,7 @@ def determine_roulette_winners(number, bets): column = i for bet in bets[RouletteAction.COLUMN_BET]: + if is_green(bet): continue if int(bet['which']) == column: add_to_winnings(bet) @@ -270,6 +274,7 @@ def determine_roulette_winners(number, bets): dozen = i for bet in bets[RouletteAction.DOZEN_BET]: + if is_green(bet): continue if int(bet['which']) == dozen: add_to_winnings(bet) @@ -277,6 +282,7 @@ def determine_roulette_winners(number, bets): even_odd = RouletteEvenOdd.EVEN if number % 2 == 0 else RouletteEvenOdd.ODD for bet in bets[RouletteAction.EVEN_ODD_BET]: + if is_green(bet): continue if bet['which'] == even_odd: add_to_winnings(bet) @@ -284,6 +290,7 @@ def determine_roulette_winners(number, bets): red_black = RouletteRedBlack.RED if number in REDS else RouletteRedBlack.BLACK for bet in bets[RouletteAction.RED_BLACK_BET]: + if is_green(bet): continue if bet['which'] == red_black: add_to_winnings(bet) @@ -291,6 +298,7 @@ def determine_roulette_winners(number, bets): high_low = RouletteHighLow.HIGH if number > 18 else RouletteHighLow.LOW for bet in bets[RouletteAction.HIGH_LOW_BET]: + if is_green(bet): continue if bet['which'] == high_low: add_to_winnings(bet) diff --git a/files/routes/casino.py b/files/routes/casino.py index ac72f5c0f..d4fe963e4 100644 --- a/files/routes/casino.py +++ b/files/routes/casino.py @@ -204,19 +204,26 @@ def roulette_player_placed_bet(v): if v.rehab: abort(403, "You are under Rehab award effect!") + bet = request.values.get("bet") + which = request.values.get("which", None) + amount = request.values.get("wager", None, int) + currency = request.values.get("currency") + + try: bet_type = RouletteAction(bet) + except: abort(400, "Not a valid roulette bet type") + + if not amount or amount < 5: abort(400, f"Minimum bet is 5 {currency}.") + if not which: abort(400, "Not a valid roulette bet") + + try: which_int = int(which) + except: which_int = None + + if not bet_type.value[1](which_int or which): + abort(400, f"Not a valid roulette bet for bet type {bet_type.value[0]}") + try: - bet = request.values.get("bet") - which = request.values.get("which") - amount = int(request.values.get("wager")) - currency = request.values.get("currency") - - if amount < 5: - abort(400, f"Minimum bet is 5 {currency}.") - gambler_placed_roulette_bet(v, bet, which, amount, currency) - bets = get_roulette_bets() - return {"success": True, "bets": bets, "gambler": {"coins": v.coins, "procoins": v.procoins}} except: abort(400, "Unable to place a bet.") diff --git a/files/templates/casino/roulette_screen.html b/files/templates/casino/roulette_screen.html index a8f15a58f..91c5f6df4 100644 --- a/files/templates/casino/roulette_screen.html +++ b/files/templates/casino/roulette_screen.html @@ -66,6 +66,7 @@ // Lines html += `
+
Line 1
Line 2
Line 3
@@ -78,6 +79,7 @@ // First Column html += "
"; + html += `
00
` for (let i = 1; i < 13; i++) { const correctNumber = CELL_TO_NUMBER_LOOKUP[i]; const isRed = reds.includes(correctNumber); @@ -95,6 +97,7 @@ // Second Column html += "
"; + html += `
` for (let i = 13; i < 25; i++) { const correctNumber = CELL_TO_NUMBER_LOOKUP[i]; const isRed = reds.includes(correctNumber); @@ -112,6 +115,7 @@ // Third Column html += "
"; + html += `
0
` for (let i = 25; i < 37; i++) { const correctNumber = CELL_TO_NUMBER_LOOKUP[i]; const isRed = reds.includes(correctNumber); @@ -130,12 +134,14 @@ // Line Bets and 1:1 Bets html += `
+
1st12
2nd12
3rd12
+
1:18
EVEN
RED
@@ -309,8 +315,9 @@ 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 ${which}?\nYou could win ${amount * 35} ${currency}.`, + 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}.`, @@ -406,6 +413,10 @@ background: red; } + .roulette-table-number__green { + background: green; + } + .roulette-table-row { display: flex; align-items: center;