forked from rDrama/rDrama
dgf
parent
416e0e4c49
commit
52a50796a0
|
@ -1,6 +1,6 @@
|
||||||
from functools import reduce
|
from functools import reduce
|
||||||
from json.encoder import INFINITY
|
from json.encoder import INFINITY
|
||||||
from random import shuffle
|
import random
|
||||||
from math import floor
|
from math import floor
|
||||||
|
|
||||||
deck_count = 4
|
deck_count = 4
|
||||||
|
@ -8,6 +8,9 @@ ranks = ["2", "3", "4", "5", "6", "7", "8", "9", "X", "J", "Q", "K", "A"]
|
||||||
suits = ["♠️", "♥️", "♣️", "♦️"]
|
suits = ["♠️", "♥️", "♣️", "♦️"]
|
||||||
|
|
||||||
|
|
||||||
|
def shuffle(x):
|
||||||
|
random.shuffle(x)
|
||||||
|
return x
|
||||||
|
|
||||||
def deal_initial_cards():
|
def deal_initial_cards():
|
||||||
deck = shuffle([rank + suit for rank in ranks for suit in suits for _ in range(deck_count)])
|
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)
|
self.apply_game_result(from_comment, wager, status, 1)
|
||||||
|
|
||||||
from_comment.blackjack_result = format_all(player_hand, dealer_hand, rest_of_deck, status, wager)
|
from_comment.blackjack_result = format_all(player_hand, dealer_hand, rest_of_deck, status, wager)
|
||||||
|
|
||||||
if self.casino_word in in_text:
|
if self.casino_word in in_text:
|
||||||
for word in in_text.split():
|
for word in in_text.split():
|
||||||
if self.casino_word in word:
|
if self.casino_word in word:
|
||||||
|
@ -103,7 +106,7 @@ class Blackjack:
|
||||||
from_user.winnings -= wager_value
|
from_user.winnings -= wager_value
|
||||||
|
|
||||||
player_hand, dealer_hand, rest_of_deck = deal_initial_cards()
|
player_hand, dealer_hand, rest_of_deck = deal_initial_cards()
|
||||||
status = 'activemb'
|
status = 'mbactive'
|
||||||
player_value = get_hand_value(player_hand)
|
player_value = get_hand_value(player_hand)
|
||||||
dealer_value = get_hand_value(dealer_hand)
|
dealer_value = get_hand_value(dealer_hand)
|
||||||
|
|
||||||
|
@ -111,15 +114,14 @@ class Blackjack:
|
||||||
status = 'push'
|
status = 'push'
|
||||||
self.apply_game_result(from_comment, wager, status, 2)
|
self.apply_game_result(from_comment, wager, status, 2)
|
||||||
elif player_value == 21:
|
elif player_value == 21:
|
||||||
status = 'blackjack'
|
status = 'mbblackjack'
|
||||||
self.apply_game_result(from_comment, wager, status, 2)
|
self.apply_game_result(from_comment, wager, status, 2)
|
||||||
elif dealer_value == 21:
|
elif dealer_value == 21:
|
||||||
status = 'lost'
|
status = 'mblost'
|
||||||
self.apply_game_result(from_comment, wager, status, 2)
|
self.apply_game_result(from_comment, wager, status, 2)
|
||||||
|
|
||||||
from_comment.blackjack_result = format_all(player_hand, dealer_hand, rest_of_deck, status, wager)
|
from_comment.blackjack_result = format_all(player_hand, dealer_hand, rest_of_deck, status, wager)
|
||||||
|
|
||||||
|
|
||||||
def player_hit(self, from_comment, currency):
|
def player_hit(self, from_comment, currency):
|
||||||
player_hand, dealer_hand, deck, status, wager = from_comment.blackjack_result.split("_")
|
player_hand, dealer_hand, deck, status, wager = from_comment.blackjack_result.split("_")
|
||||||
player_hand = player_hand.split("/")
|
player_hand = player_hand.split("/")
|
||||||
|
@ -129,13 +131,13 @@ class Blackjack:
|
||||||
player_value = get_hand_value(player_hand)
|
player_value = get_hand_value(player_hand)
|
||||||
|
|
||||||
if player_value == -1:
|
if player_value == -1:
|
||||||
status = 'bust'
|
if currency == 1: status = 'bust'
|
||||||
|
else: status = 'mbbust'
|
||||||
self.apply_game_result(from_comment, wager, status, currency)
|
self.apply_game_result(from_comment, wager, status, currency)
|
||||||
|
|
||||||
from_comment.blackjack_result = format_all(player_hand, dealer_hand, deck, status, wager)
|
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):
|
def player_stayed(self, from_comment, currency):
|
||||||
player_hand, dealer_hand, deck, status, wager = from_comment.blackjack_result.split("_")
|
player_hand, dealer_hand, deck, status, wager = from_comment.blackjack_result.split("_")
|
||||||
|
@ -150,21 +152,25 @@ class Blackjack:
|
||||||
dealer_hand.append(next)
|
dealer_hand.append(next)
|
||||||
dealer_value = get_hand_value(dealer_hand)
|
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'
|
if player_value > dealer_value or dealer_value == -1:
|
||||||
else: status = 'push'
|
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)
|
from_comment.blackjack_result = format_all(player_hand, dealer_hand, deck, status, wager)
|
||||||
|
|
||||||
self.apply_game_result(from_comment, wager, status, currency)
|
self.apply_game_result(from_comment, wager, status, currency)
|
||||||
|
|
||||||
|
|
||||||
def apply_game_result(self, from_comment, wager, result, currency):
|
def apply_game_result(self, from_comment, wager, result, currency):
|
||||||
reward = 0
|
reward = 0
|
||||||
|
|
||||||
if result == 'push': reward = int(wager)
|
if result.endswith('push'): reward = int(wager)
|
||||||
elif result == 'won': reward = int(wager) * 2
|
elif result.endswith('won'): reward = int(wager) * 2
|
||||||
elif result == 'blackjack': reward = floor(int(wager) * (5/2))
|
elif result.endswith('blackjack'): reward = floor(int(wager) * (5/2))
|
||||||
|
|
||||||
if (reward > 0):
|
if (reward > 0):
|
||||||
user = from_comment.author
|
user = from_comment.author
|
||||||
|
|
|
@ -282,7 +282,7 @@ def api_comment(v):
|
||||||
|
|
||||||
is_bot = bool(request.headers.get("Authorization"))
|
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())
|
now = int(time.time())
|
||||||
cutoff = now - 60 * 60 * 24
|
cutoff = now - 60 * 60 * 24
|
||||||
|
|
||||||
|
@ -700,7 +700,7 @@ def edit_comment(cid, v):
|
||||||
if ban.reason: reason += f" {ban.reason}"
|
if ban.reason: reason += f" {ban.reason}"
|
||||||
|
|
||||||
return {'error': reason}, 400
|
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())
|
now = int(time.time())
|
||||||
cutoff = now - 60 * 60 * 24
|
cutoff = now - 60 * 60 * 24
|
||||||
|
|
||||||
|
@ -964,8 +964,9 @@ def handle_blackjack_action(cid, v):
|
||||||
blackjack = Blackjack(g)
|
blackjack = Blackjack(g)
|
||||||
|
|
||||||
blackjack_status = comment.blackjack_result.split('_')[3]
|
blackjack_status = comment.blackjack_result.split('_')[3]
|
||||||
if blackjack_status == 'activemb': currency = 2
|
if blackjack_status == 'mbactive': currency = 2
|
||||||
else: currency = 1
|
elif blackjack_status == 'active': currency = 1
|
||||||
|
else: abort(400)
|
||||||
|
|
||||||
if action == 'hit': blackjack.player_hit(comment, currency)
|
if action == 'hit': blackjack.player_hit(comment, currency)
|
||||||
elif action == 'stay': blackjack.player_stayed(comment, currency)
|
elif action == 'stay': blackjack.player_stayed(comment, currency)
|
||||||
|
|
|
@ -182,7 +182,7 @@
|
||||||
{% set split_result = c.blackjack_result.split('_') %}
|
{% set split_result = c.blackjack_result.split('_') %}
|
||||||
{% set blackjack_status = split_result[3] %}
|
{% set blackjack_status = split_result[3] %}
|
||||||
{% set player_hand = split_result[0].replace('X', '10') %}
|
{% 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 dealer_hand = dealer_hand.replace('X', '10') %}
|
||||||
{% set wager = split_result[4] %}
|
{% set wager = split_result[4] %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -255,20 +255,25 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if c.blackjack_result %}
|
{% if c.blackjack_result %}
|
||||||
<em>{{player_hand}} vs. {{dealer_hand}}</em>
|
<em>{{player_hand}} vs. {{dealer_hand}}</em>
|
||||||
|
{% if blackjack_status.startswith('mb') %}
|
||||||
|
{% set currency = 'Marseybux' %}
|
||||||
|
{% else %}
|
||||||
|
{% set currency = 'Coins' %}
|
||||||
|
{% endif %}
|
||||||
{% if 'active' in blackjack_status and v.id == c.author_id %}
|
{% if 'active' in blackjack_status and v.id == c.author_id %}
|
||||||
<button class="btn btn-success small" style="text-transform: uppercase; padding: 2px;" onclick="handle_blackjack_action('{{c.id}}', 'hit')">Hit</button>
|
<button class="btn btn-success small" style="text-transform: uppercase; padding: 2px;" onclick="handle_blackjack_action('{{c.id}}', 'hit')">Hit</button>
|
||||||
<button class="btn btn-danger small" style="text-transform: uppercase; padding: 2px;" onclick="handle_blackjack_action('{{c.id}}', 'stay')">Stay</button>
|
<button class="btn btn-danger small" style="text-transform: uppercase; padding: 2px;" onclick="handle_blackjack_action('{{c.id}}', 'stay')">Stay</button>
|
||||||
{% elif blackjack_status == 'push' %}
|
{% elif blackjack_status == 'push' %}
|
||||||
<strong>Pushed.</strong>
|
<strong>Pushed.</strong>
|
||||||
{% elif blackjack_status == 'bust' %}
|
{% elif blackjack_status.endswith('bust') %}
|
||||||
<strong>Bust. Lost {{wager}} Coins.</strong>
|
<strong>Bust. Lost {{wager}} {{currency}}.</strong>
|
||||||
{% elif blackjack_status == 'lost' %}
|
{% elif blackjack_status.endswith('lost') %}
|
||||||
<strong>Lost {{wager}} Coins.</strong>
|
<strong>Lost {{wager}} {{currency}}.</strong>
|
||||||
{% elif blackjack_status == 'won' %}
|
{% elif blackjack_status.endswith('won') %}
|
||||||
<strong>Won {{wager}} Coins.</strong>
|
<strong>Won {{wager}} {{currency}}.</strong>
|
||||||
{% elif blackjack_status == 'blackjack' %}
|
{% elif blackjack_status.endswith('blackjack') %}
|
||||||
<strong>Blackjack! Won <span id="blackjack-result-{{c.id}}">{{(wager|int * 3/2)|round(0, 'floor')|int}}</span> Coins.</strong>
|
<strong>Blackjack! Won <span id="blackjack-result-{{c.id}}">{{(wager|int * 3/2)|round(0, 'floor')|int}}</span> {{currency}}.</strong>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue