forked from rDrama/rDrama
1
0
Fork 0

Add gambling wager badge logic.

This commit touches more files than it ought to because this change
required untangling some circular imports, notably a lingering import
of files.helpers.slots in helpers.actions (presumably from old Snappy
gambling logic) and the User.active_blackjack_game accessor. Otherwise,
the logic is fairly straightforward.
master
Snakes 2022-09-29 00:26:50 -04:00
parent 5416cd09e2
commit f05ec93b95
Signed by: Snakes
GPG Key ID: E745A82778055C7E
8 changed files with 44 additions and 11 deletions

View File

@ -6,7 +6,6 @@ from files.helpers.discord import remove_user
from files.helpers.media import *
from files.helpers.const import *
from files.classes.casino_game import Casino_Game
from files.helpers.twentyone import get_active_twentyone_game_state
from files.helpers.sorting_and_time import *
from .alts import Alt
from .saves import *
@ -930,11 +929,6 @@ class User(Base):
if self.patron: return True
return False
@property
@lazy
def active_blackjack_game(self):
return json.dumps(get_active_twentyone_game_state(self))
@property
@lazy
def winnings(self):

View File

@ -4,7 +4,6 @@ from files.helpers.alerts import send_repeatable_notification
from files.helpers.const import *
from files.helpers.get import *
from files.helpers.sanitize import *
from files.helpers.slots import *
import random
from urllib.parse import quote

View File

@ -1,5 +1,6 @@
from files.__main__ import app, limiter, db_session
from files.helpers.wrappers import *
from files.helpers.actions import badge_grant
from files.helpers.alerts import *
from files.helpers.get import *
from files.helpers.const import *
@ -82,3 +83,25 @@ def get_game_leaderboard(game):
}
}
}
def distribute_wager_badges(user, wager, won):
badges_earned = []
if won:
if wager >= 1000:
badges_earned.append(160)
if wager >= 10000:
badges_earned.append(161)
if wager >= 100000:
badges_earned.append(162)
else:
if wager >= 1000:
badges_earned.append(157)
if wager >= 10000:
badges_earned.append(158)
if wager >= 100000:
badges_earned.append(159)
for badge in badges_earned:
badge_grant(user, badge)

View File

@ -3,6 +3,7 @@ from json.encoder import INFINITY
import random
from .const import *
from files.classes.casino_game import Casino_Game
from files.helpers.casino import distribute_wager_badges
from flask import g
minimum_bet = 5
@ -26,6 +27,9 @@ def casino_slot_pull(gambler, wager_value, currency):
gambler.pay_account(currency, reward)
if currency == 'coins':
distribute_wager_badges(gambler, wager_value, won=(payout > 0))
symbols = build_symbols(payout)
text = build_text(wager_value, payout, currency)
game_state = {

View File

@ -3,6 +3,7 @@ from math import floor
import random
from enum import Enum
from files.classes.casino_game import Casino_Game
from files.helpers.casino import distribute_wager_badges
from flask import g
@ -243,6 +244,12 @@ def handle_payout(gambler, state, game):
gambler.pay_account(game.currency, payout)
if game.currency == 'coins':
if status in (BlackjackStatus.BLACKJACK, BlackjackStatus.WON):
distribute_wager_badges(gambler, game.wager, won=True)
elif status == BlackjackStatus.LOST:
distribute_wager_badges(gambler, game.wager, won=False)
game.active = False
g.db.add(game)

View File

@ -4,11 +4,11 @@ from files.helpers.alerts import *
from files.helpers.get import *
from files.helpers.const import *
from files.helpers.wrappers import *
from files.helpers.slots import *
from files.helpers.lottery import *
from files.helpers.casino import *
from files.helpers.slots import *
from files.helpers.twentyone import *
from files.helpers.roulette import *
from files.helpers.lottery import *
@app.get("/casino")
@ -31,12 +31,17 @@ def casino_game_page(v, game):
feed = json.dumps(get_game_feed(game))
leaderboard = json.dumps(get_game_leaderboard(game))
game_state = None
if game == 'blackjack':
game_state = json.dumps(get_active_twentyone_game_state(gambler))
return render_template(
f"casino/{game}_screen.html",
v=v,
game=game,
feed=feed,
leaderboard=leaderboard
leaderboard=leaderboard,
game_state=game_state
)

View File

@ -11,6 +11,7 @@ from files.classes.badges import BadgeDef
import files.helpers.stats as statshelper
from shutil import move, copyfile
@app.get("/r/drama/comments/<id>/<title>")
@app.get("/r/Drama/comments/<id>/<title>")
def rdrama(id, title):

View File

@ -219,7 +219,7 @@
{% block screen %}
<div id="blackjack-table-deck"></div>
<div id="blackjack-table" data-state="{{v.active_blackjack_game}}" style="position: relative;">
<div id="blackjack-table" data-state="{{game_state}}" style="position: relative;">
</div>
{% endblock %}