forked from rDrama/rDrama
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
parent
5416cd09e2
commit
f05ec93b95
|
@ -6,7 +6,6 @@ from files.helpers.discord import remove_user
|
||||||
from files.helpers.media import *
|
from files.helpers.media import *
|
||||||
from files.helpers.const import *
|
from files.helpers.const import *
|
||||||
from files.classes.casino_game import Casino_Game
|
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 files.helpers.sorting_and_time import *
|
||||||
from .alts import Alt
|
from .alts import Alt
|
||||||
from .saves import *
|
from .saves import *
|
||||||
|
@ -930,11 +929,6 @@ class User(Base):
|
||||||
if self.patron: return True
|
if self.patron: return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@property
|
|
||||||
@lazy
|
|
||||||
def active_blackjack_game(self):
|
|
||||||
return json.dumps(get_active_twentyone_game_state(self))
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@lazy
|
@lazy
|
||||||
def winnings(self):
|
def winnings(self):
|
||||||
|
|
|
@ -4,7 +4,6 @@ from files.helpers.alerts import send_repeatable_notification
|
||||||
from files.helpers.const import *
|
from files.helpers.const import *
|
||||||
from files.helpers.get import *
|
from files.helpers.get import *
|
||||||
from files.helpers.sanitize import *
|
from files.helpers.sanitize import *
|
||||||
from files.helpers.slots import *
|
|
||||||
import random
|
import random
|
||||||
from urllib.parse import quote
|
from urllib.parse import quote
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
from files.__main__ import app, limiter, db_session
|
from files.__main__ import app, limiter, db_session
|
||||||
from files.helpers.wrappers import *
|
from files.helpers.wrappers import *
|
||||||
|
from files.helpers.actions import badge_grant
|
||||||
from files.helpers.alerts import *
|
from files.helpers.alerts import *
|
||||||
from files.helpers.get import *
|
from files.helpers.get import *
|
||||||
from files.helpers.const 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)
|
||||||
|
|
|
@ -3,6 +3,7 @@ from json.encoder import INFINITY
|
||||||
import random
|
import random
|
||||||
from .const import *
|
from .const import *
|
||||||
from files.classes.casino_game import Casino_Game
|
from files.classes.casino_game import Casino_Game
|
||||||
|
from files.helpers.casino import distribute_wager_badges
|
||||||
from flask import g
|
from flask import g
|
||||||
|
|
||||||
minimum_bet = 5
|
minimum_bet = 5
|
||||||
|
@ -26,6 +27,9 @@ def casino_slot_pull(gambler, wager_value, currency):
|
||||||
|
|
||||||
gambler.pay_account(currency, reward)
|
gambler.pay_account(currency, reward)
|
||||||
|
|
||||||
|
if currency == 'coins':
|
||||||
|
distribute_wager_badges(gambler, wager_value, won=(payout > 0))
|
||||||
|
|
||||||
symbols = build_symbols(payout)
|
symbols = build_symbols(payout)
|
||||||
text = build_text(wager_value, payout, currency)
|
text = build_text(wager_value, payout, currency)
|
||||||
game_state = {
|
game_state = {
|
||||||
|
|
|
@ -3,6 +3,7 @@ from math import floor
|
||||||
import random
|
import random
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from files.classes.casino_game import Casino_Game
|
from files.classes.casino_game import Casino_Game
|
||||||
|
from files.helpers.casino import distribute_wager_badges
|
||||||
from flask import g
|
from flask import g
|
||||||
|
|
||||||
|
|
||||||
|
@ -243,6 +244,12 @@ def handle_payout(gambler, state, game):
|
||||||
|
|
||||||
gambler.pay_account(game.currency, payout)
|
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
|
game.active = False
|
||||||
g.db.add(game)
|
g.db.add(game)
|
||||||
|
|
||||||
|
|
|
@ -4,11 +4,11 @@ from files.helpers.alerts import *
|
||||||
from files.helpers.get import *
|
from files.helpers.get import *
|
||||||
from files.helpers.const import *
|
from files.helpers.const import *
|
||||||
from files.helpers.wrappers import *
|
from files.helpers.wrappers import *
|
||||||
from files.helpers.slots import *
|
|
||||||
from files.helpers.lottery import *
|
|
||||||
from files.helpers.casino import *
|
from files.helpers.casino import *
|
||||||
|
from files.helpers.slots import *
|
||||||
from files.helpers.twentyone import *
|
from files.helpers.twentyone import *
|
||||||
from files.helpers.roulette import *
|
from files.helpers.roulette import *
|
||||||
|
from files.helpers.lottery import *
|
||||||
|
|
||||||
|
|
||||||
@app.get("/casino")
|
@app.get("/casino")
|
||||||
|
@ -31,12 +31,17 @@ def casino_game_page(v, game):
|
||||||
feed = json.dumps(get_game_feed(game))
|
feed = json.dumps(get_game_feed(game))
|
||||||
leaderboard = json.dumps(get_game_leaderboard(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(
|
return render_template(
|
||||||
f"casino/{game}_screen.html",
|
f"casino/{game}_screen.html",
|
||||||
v=v,
|
v=v,
|
||||||
game=game,
|
game=game,
|
||||||
feed=feed,
|
feed=feed,
|
||||||
leaderboard=leaderboard
|
leaderboard=leaderboard,
|
||||||
|
game_state=game_state
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ from files.classes.badges import BadgeDef
|
||||||
import files.helpers.stats as statshelper
|
import files.helpers.stats as statshelper
|
||||||
from shutil import move, copyfile
|
from shutil import move, copyfile
|
||||||
|
|
||||||
|
|
||||||
@app.get("/r/drama/comments/<id>/<title>")
|
@app.get("/r/drama/comments/<id>/<title>")
|
||||||
@app.get("/r/Drama/comments/<id>/<title>")
|
@app.get("/r/Drama/comments/<id>/<title>")
|
||||||
def rdrama(id, title):
|
def rdrama(id, title):
|
||||||
|
|
|
@ -219,7 +219,7 @@
|
||||||
|
|
||||||
{% block screen %}
|
{% block screen %}
|
||||||
<div id="blackjack-table-deck"></div>
|
<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>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue