2022-09-04 20:53:34 +00:00
|
|
|
import json
|
2022-02-14 20:29:36 +00:00
|
|
|
import random
|
2022-11-15 09:19:08 +00:00
|
|
|
from json.encoder import INFINITY
|
|
|
|
|
|
|
|
from flask import abort, g
|
|
|
|
|
2022-09-04 20:53:34 +00:00
|
|
|
from files.classes.casino_game import Casino_Game
|
2022-11-01 23:03:39 +00:00
|
|
|
from files.classes.comment import Comment
|
|
|
|
from files.classes.user import User
|
2022-11-15 09:19:08 +00:00
|
|
|
from files.helpers.casino import distribute_wager_badges
|
|
|
|
|
|
|
|
from .const import *
|
2022-02-14 20:29:36 +00:00
|
|
|
|
2022-09-05 07:28:53 +00:00
|
|
|
minimum_bet = 5
|
2022-02-14 20:29:36 +00:00
|
|
|
maximum_bet = INFINITY
|
|
|
|
payout_to_symbols = {
|
2022-09-04 23:15:37 +00:00
|
|
|
2: ["👣", "🍀", "🌈", "⭐️"],
|
|
|
|
3: ["🍎", "🔞", "⚛️", "☢️"],
|
|
|
|
5: ["✡️", "⚔️", "🍆", "🍒"],
|
|
|
|
12: ["🐱"]
|
2022-02-14 20:29:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-04 20:53:34 +00:00
|
|
|
def casino_slot_pull(gambler, wager_value, currency):
|
2022-09-04 23:15:37 +00:00
|
|
|
over_min = wager_value >= minimum_bet
|
|
|
|
under_max = wager_value <= maximum_bet
|
2022-09-15 22:16:35 +00:00
|
|
|
charged = gambler.charge_account(currency, wager_value)
|
2022-09-04 23:15:37 +00:00
|
|
|
|
2022-09-15 22:16:35 +00:00
|
|
|
if (over_min and under_max and charged):
|
2022-09-04 23:15:37 +00:00
|
|
|
payout = determine_payout()
|
|
|
|
reward = wager_value * payout
|
|
|
|
|
2022-09-15 22:30:18 +00:00
|
|
|
gambler.pay_account(currency, reward)
|
2022-09-15 22:16:35 +00:00
|
|
|
|
2022-09-29 04:26:50 +00:00
|
|
|
if currency == 'coins':
|
|
|
|
distribute_wager_badges(gambler, wager_value, won=(payout > 0))
|
|
|
|
|
2022-09-04 23:15:37 +00:00
|
|
|
symbols = build_symbols(payout)
|
|
|
|
text = build_text(wager_value, payout, currency)
|
|
|
|
game_state = {
|
|
|
|
"symbols": symbols,
|
|
|
|
"text": text
|
|
|
|
}
|
|
|
|
casino_game = Casino_Game()
|
|
|
|
casino_game.active = False
|
|
|
|
casino_game.user_id = gambler.id
|
2022-09-10 21:01:34 +00:00
|
|
|
casino_game.currency = currency
|
2022-09-04 23:15:37 +00:00
|
|
|
casino_game.wager = wager_value
|
|
|
|
casino_game.winnings = reward - wager_value
|
|
|
|
casino_game.kind = 'slots'
|
|
|
|
casino_game.game_state = json.dumps(game_state)
|
|
|
|
g.db.add(casino_game)
|
2022-10-30 00:36:23 +00:00
|
|
|
g.db.flush()
|
2022-09-04 23:15:37 +00:00
|
|
|
|
2022-10-30 00:12:32 +00:00
|
|
|
return casino_game.id, casino_game.game_state
|
2022-09-04 23:15:37 +00:00
|
|
|
else:
|
2022-11-07 00:08:50 +00:00
|
|
|
return None, "{}",
|
2022-02-14 20:29:36 +00:00
|
|
|
|
|
|
|
|
2022-09-04 20:53:34 +00:00
|
|
|
def build_symbols(for_payout):
|
2022-09-04 23:15:37 +00:00
|
|
|
all_symbols = []
|
2022-09-04 20:53:34 +00:00
|
|
|
|
2022-09-04 23:15:37 +00:00
|
|
|
for payout in payout_to_symbols:
|
|
|
|
for symbol in payout_to_symbols[payout]:
|
|
|
|
all_symbols.append(symbol)
|
2022-09-04 20:53:34 +00:00
|
|
|
|
2022-09-04 23:15:37 +00:00
|
|
|
shuffle(all_symbols)
|
2022-09-04 20:53:34 +00:00
|
|
|
|
2022-09-04 23:15:37 +00:00
|
|
|
if for_payout == 0:
|
|
|
|
return "".join([all_symbols[0], ",", all_symbols[1], ",", all_symbols[2]])
|
|
|
|
elif for_payout == 1:
|
|
|
|
indices = shuffle([0, 1, 2])
|
|
|
|
symbol_set = ["", "", ""]
|
|
|
|
match_a = indices[0]
|
|
|
|
match_b = indices[1]
|
|
|
|
nonmatch = indices[2]
|
|
|
|
matching_symbol = all_symbols[0]
|
|
|
|
other_symbol = all_symbols[1]
|
|
|
|
symbol_set[match_a] = matching_symbol
|
|
|
|
symbol_set[match_b] = matching_symbol
|
|
|
|
symbol_set[nonmatch] = other_symbol
|
2022-09-04 20:53:34 +00:00
|
|
|
|
2022-09-04 23:15:37 +00:00
|
|
|
return "".join([symbol_set[0], ",", symbol_set[1], ",", symbol_set[2]])
|
|
|
|
else:
|
|
|
|
relevantSymbols = shuffle(payout_to_symbols[for_payout])
|
|
|
|
symbol = relevantSymbols[0]
|
2022-09-04 20:53:34 +00:00
|
|
|
|
2022-09-04 23:15:37 +00:00
|
|
|
return "".join([symbol, ",", symbol, ",", symbol])
|
2022-09-04 20:53:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
def build_text(wager_value, result, currency):
|
2022-09-04 23:15:37 +00:00
|
|
|
if result == 0:
|
|
|
|
return f'Lost {wager_value} {currency}'
|
|
|
|
elif result == 1:
|
|
|
|
return 'Broke Even'
|
|
|
|
elif result == 12:
|
|
|
|
return f'Jackpot! Won {wager_value * (result-1)} {currency}'
|
|
|
|
else:
|
|
|
|
return f'Won {wager_value * (result-1)} {currency}'
|
2022-02-14 20:29:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
def determine_payout():
|
2022-09-04 23:15:37 +00:00
|
|
|
value = random.randint(1, 100)
|
|
|
|
if value == 100:
|
|
|
|
return 12
|
|
|
|
elif value >= 96:
|
|
|
|
return 5
|
|
|
|
elif value >= 88:
|
|
|
|
return 3
|
|
|
|
elif value >= 72:
|
|
|
|
return 2
|
|
|
|
elif value >= 61:
|
|
|
|
return 1
|
|
|
|
else:
|
|
|
|
return 0
|
2022-02-14 20:29:36 +00:00
|
|
|
|
2022-09-04 20:53:34 +00:00
|
|
|
|
|
|
|
def shuffle(stuff):
|
2022-09-04 23:15:37 +00:00
|
|
|
random.shuffle(stuff)
|
|
|
|
return stuff
|
2022-11-01 22:40:22 +00:00
|
|
|
|
|
|
|
|
2022-11-07 00:08:50 +00:00
|
|
|
def check_slots_command(v:User, u:User, c:Comment):
|
2022-11-01 23:03:39 +00:00
|
|
|
if not FEATURES['GAMBLING']: return
|
2022-11-01 22:40:22 +00:00
|
|
|
body = c.body.lower()
|
|
|
|
|
|
|
|
if '!slotsmb' in body:
|
|
|
|
command_word = '!slotsmb'
|
|
|
|
currency = 'procoins'
|
2022-11-01 23:03:39 +00:00
|
|
|
elif '!slots' in body:
|
2022-11-01 22:40:22 +00:00
|
|
|
command_word = '!slots'
|
|
|
|
currency = 'coins'
|
2022-11-01 23:03:39 +00:00
|
|
|
else:
|
|
|
|
return
|
|
|
|
|
|
|
|
if u.rehab:
|
|
|
|
if v.id == u.id:
|
|
|
|
abort(403, "You are under Rehab award effect!")
|
|
|
|
return
|
2022-11-01 22:40:22 +00:00
|
|
|
|
|
|
|
try:
|
2022-11-02 03:23:46 +00:00
|
|
|
wager = body.split(command_word)[1].split()[0]
|
2022-11-01 22:40:22 +00:00
|
|
|
wager = int(wager)
|
|
|
|
except:
|
2022-11-01 23:03:39 +00:00
|
|
|
if v.id == u.id:
|
|
|
|
abort(400, "Invalid wager.")
|
|
|
|
return
|
2022-11-01 22:40:22 +00:00
|
|
|
|
|
|
|
if wager < 100:
|
2022-11-01 23:03:39 +00:00
|
|
|
if v.id == u.id:
|
|
|
|
abort(400, f"Wager must be 100 {currency} or more")
|
|
|
|
return
|
2022-11-01 22:40:22 +00:00
|
|
|
|
|
|
|
if (currency == "coins" and wager > u.coins) or (currency == "procoins" and wager > u.procoins):
|
2022-11-01 23:03:39 +00:00
|
|
|
if v.id == u.id:
|
|
|
|
abort(400, f"Not enough {currency} to make that bet")
|
|
|
|
return
|
2022-11-01 22:40:22 +00:00
|
|
|
|
2022-11-07 00:08:50 +00:00
|
|
|
game_id, game_state = casino_slot_pull(u, wager, currency)
|
2022-11-01 22:40:22 +00:00
|
|
|
c.casino_game_id = game_id
|