diff --git a/files/classes/blackjack.py b/files/classes/blackjack.py index 1f18c62d9..9774e3e3b 100644 --- a/files/classes/blackjack.py +++ b/files/classes/blackjack.py @@ -1,6 +1,6 @@ from functools import reduce from json.encoder import INFINITY -from random import shuffle +import random from math import floor deck_count = 4 @@ -8,6 +8,9 @@ ranks = ["2", "3", "4", "5", "6", "7", "8", "9", "X", "J", "Q", "K", "A"] suits = ["♠️", "♥️", "♣️", "♦️"] +def shuffle(x): + random.shuffle(x) + return x def deal_initial_cards(): deck = shuffle([rank + suit for rank in ranks for suit in suits for _ in range(deck_count)]) @@ -86,7 +89,7 @@ class Blackjack: self.apply_game_result(from_comment, wager, status, 1) from_comment.blackjack_result = format_all(player_hand, dealer_hand, rest_of_deck, status, wager) - + if self.casino_word in in_text: for word in in_text.split(): if self.casino_word in word: @@ -103,7 +106,7 @@ class Blackjack: from_user.winnings -= wager_value player_hand, dealer_hand, rest_of_deck = deal_initial_cards() - status = 'activemb' + status = 'mbactive' player_value = get_hand_value(player_hand) dealer_value = get_hand_value(dealer_hand) @@ -111,15 +114,14 @@ class Blackjack: status = 'push' self.apply_game_result(from_comment, wager, status, 2) elif player_value == 21: - status = 'blackjack' + status = 'mbblackjack' self.apply_game_result(from_comment, wager, status, 2) elif dealer_value == 21: - status = 'lost' + status = 'mblost' self.apply_game_result(from_comment, wager, status, 2) from_comment.blackjack_result = format_all(player_hand, dealer_hand, rest_of_deck, status, wager) - def player_hit(self, from_comment, currency): player_hand, dealer_hand, deck, status, wager = from_comment.blackjack_result.split("_") player_hand = player_hand.split("/") @@ -129,13 +131,13 @@ class Blackjack: player_value = get_hand_value(player_hand) if player_value == -1: - status = 'bust' + if currency == 1: status = 'bust' + else: status = 'mbbust' self.apply_game_result(from_comment, wager, status, currency) from_comment.blackjack_result = format_all(player_hand, dealer_hand, deck, status, wager) - if (player_value == 21): self.player_stayed(from_comment) - + if (player_value == 21): self.player_stayed(from_comment, currency) def player_stayed(self, from_comment, currency): player_hand, dealer_hand, deck, status, wager = from_comment.blackjack_result.split("_") @@ -150,21 +152,25 @@ class Blackjack: dealer_hand.append(next) dealer_value = get_hand_value(dealer_hand) - if player_value > dealer_value or dealer_value == -1: status = 'won' - elif dealer_value > player_value: status = 'lost' - else: status = 'push' + + if player_value > dealer_value or dealer_value == -1: + if currency == 1: status = 'won' + else: status = 'mbwon' + elif dealer_value > player_value: + if currency == 1: status = 'lost' + else: status = 'mblost' + else: status += 'push' from_comment.blackjack_result = format_all(player_hand, dealer_hand, deck, status, wager) self.apply_game_result(from_comment, wager, status, currency) - def apply_game_result(self, from_comment, wager, result, currency): reward = 0 - if result == 'push': reward = int(wager) - elif result == 'won': reward = int(wager) * 2 - elif result == 'blackjack': reward = floor(int(wager) * (5/2)) + if result.endswith('push'): reward = int(wager) + elif result.endswith('won'): reward = int(wager) * 2 + elif result.endswith('blackjack'): reward = floor(int(wager) * (5/2)) if (reward > 0): user = from_comment.author diff --git a/files/routes/comments.py b/files/routes/comments.py index f306f8104..843b653d6 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -282,7 +282,7 @@ def api_comment(v): is_bot = bool(request.headers.get("Authorization")) - if parent_post.id not in (37696,37697,37749,37833,37838) and not is_bot and not v.marseyawarded and AGENDAPOSTER_PHRASE not in body.lower() and len(body) > 10: + if '!slots' not in body.lower() and '!blackjack' not in body.lower() and parent_post.id not in (37696,37697,37749,37833,37838) and not is_bot and not v.marseyawarded and AGENDAPOSTER_PHRASE not in body.lower() and len(body) > 10: now = int(time.time()) cutoff = now - 60 * 60 * 24 @@ -700,7 +700,7 @@ def edit_comment(cid, v): if ban.reason: reason += f" {ban.reason}" return {'error': reason}, 400 - if AGENDAPOSTER_PHRASE not in body.lower(): + if '!slots' not in body.lower() and '!blackjack' not in body.lower() and AGENDAPOSTER_PHRASE not in body.lower(): now = int(time.time()) cutoff = now - 60 * 60 * 24 @@ -964,8 +964,9 @@ def handle_blackjack_action(cid, v): blackjack = Blackjack(g) blackjack_status = comment.blackjack_result.split('_')[3] - if blackjack_status == 'activemb': currency = 2 - else: currency = 1 + if blackjack_status == 'mbactive': currency = 2 + elif blackjack_status == 'active': currency = 1 + else: abort(400) if action == 'hit': blackjack.player_hit(comment, currency) elif action == 'stay': blackjack.player_stayed(comment, currency) diff --git a/files/templates/comments.html b/files/templates/comments.html index 595c9635f..5518a67bc 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -182,7 +182,7 @@ {% set split_result = c.blackjack_result.split('_') %} {% set blackjack_status = split_result[3] %} {% set player_hand = split_result[0].replace('X', '10') %} - {% set dealer_hand = split_result[1].split('/')[0] if 'active' in blackjack_status else split_result[1] %} + {% set dealer_hand = split_result[1].split('/')[0] if blackjack_status.endswith('active') else split_result[1] %} {% set dealer_hand = dealer_hand.replace('X', '10') %} {% set wager = split_result[4] %} {% endif %} @@ -255,20 +255,25 @@ {% endif %} {% if c.blackjack_result %} - {{player_hand}} vs. {{dealer_hand}} + {{player_hand}} vs. {{dealer_hand}} + {% if blackjack_status.startswith('mb') %} + {% set currency = 'Marseybux' %} + {% else %} + {% set currency = 'Coins' %} + {% endif %} {% if 'active' in blackjack_status and v.id == c.author_id %} - - + + {% elif blackjack_status == 'push' %} - Pushed. - {% elif blackjack_status == 'bust' %} - Bust. Lost {{wager}} Coins. - {% elif blackjack_status == 'lost' %} - Lost {{wager}} Coins. - {% elif blackjack_status == 'won' %} - Won {{wager}} Coins. - {% elif blackjack_status == 'blackjack' %} - Blackjack! Won {{(wager|int * 3/2)|round(0, 'floor')|int}} Coins. + Pushed. + {% elif blackjack_status.endswith('bust') %} + Bust. Lost {{wager}} {{currency}}. + {% elif blackjack_status.endswith('lost') %} + Lost {{wager}} {{currency}}. + {% elif blackjack_status.endswith('won') %} + Won {{wager}} {{currency}}. + {% elif blackjack_status.endswith('blackjack') %} + Blackjack! Won {{(wager|int * 3/2)|round(0, 'floor')|int}} {{currency}}. {% endif %} {% endif %}