Have tickets show up in treasure chests

remotes/1693045480750635534/spooky-22
Outrun Colors, LLC 2022-05-29 21:59:22 -05:00
parent b9dc28e6d1
commit db13e0976c
3 changed files with 53 additions and 15 deletions

View File

@ -85,8 +85,7 @@ def purchase_lottery_ticket(v):
most_recent_lottery.prize += net_ticket_value
most_recent_lottery.tickets_sold += 1
manager = g.db.query(User).get(LOTTERY_MANAGER_ACCOUNT_ID)
manager.coins += net_ticket_value
grant_lottery_proceeds_to_manager(net_ticket_value)
beneficiary = g.db.query(User).get(LOTTERY_ROYALTY_ACCOUNT_ID)
beneficiary.coins += LOTTERY_ROYALTY_RATE
@ -94,3 +93,22 @@ def purchase_lottery_ticket(v):
g.db.commit()
return True, 'Successfully purchased a lottery ticket!'
def grant_lottery_proceeds_to_manager(amount):
manager = g.db.query(User).get(LOTTERY_MANAGER_ACCOUNT_ID)
manager.coins += amount
def grant_lottery_tickets_to_user(v, amount):
active_lottery = get_active_lottery()
prize_value = amount * LOTTERY_TICKET_COST
if active_lottery:
v.currently_held_lottery_tickets += amount
v.total_held_lottery_tickets += amount
active_lottery.prize += prize_value
active_lottery.tickets_sold += amount
grant_lottery_proceeds_to_manager(amount)
g.db.commit()

View File

@ -1,22 +1,26 @@
import random
from random import randint
from math import floor
from files.helpers.const import *
from files.helpers.lottery import *
special_min = 100
special_max = 200
standard_min = 10
standard_max = 100
lotterizer_rate = 33
def check_for_treasure(in_text, from_comment):
if '!slots' not in in_text and '!blackjack' not in in_text and '!wordle' not in in_text:
seed = random.randint(1, 1000)
seed = randint(1, 1000)
is_special = seed == 1000
is_standard = seed >= 990
amount = 0
if is_special:
amount = random.randint(special_min, special_max)
amount = randint(special_min, special_max)
elif is_standard:
amount = random.randint(standard_min, standard_max)
if random.randint(1, 100) > 90:
amount = randint(standard_min, standard_max)
if randint(1, 100) > 90:
user = from_comment.author
if amount > user.coins: amount = user.coins
amount = -amount
@ -24,6 +28,18 @@ def check_for_treasure(in_text, from_comment):
if amount != 0:
user = from_comment.author
user.coins += amount
if amount > 0:
active_lottery = get_active_lottery()
lottery_tickets_seed = randint(1, 100)
lottery_tickets_instead = lottery_tickets_seed <= lotterizer_rate
if active_lottery and lottery_tickets_instead:
ticket_count = floor(amount / LOTTERY_TICKET_COST)
grant_lottery_tickets_to_user(user, ticket_count)
from_comment.treasure_amount = f'l{ticket_count}'
return
user.coins += amount
from_comment.treasure_amount = str(amount)

View File

@ -225,14 +225,18 @@
{% endif %}
{% if c.treasure_amount and c.treasure_amount != '0' %}
<img class="treasure" alt="treasure" src="/assets/images/chest.webp" width="20" />
{% if '-' in c.treasure_amount %}
<em>A Mimic Ate {{c.treasure_amount.replace('-', '')}} Coins!</em>
{% else %}
<em>Found {{c.treasure_amount}} Coins!</em>
{% endif %}
{% if c.treasure_amount.startswith('l') %}
<img class="treasure" alt="treasure" src="/assets/images/rDrama/treasure_tickets.gif" width="20" />
<em>Found {{c.treasure_amount.replace('l', '')}} Lottershe Tickets!</em>
{% elif '-' in c.treasure_amount %}
<img class="treasure" alt="treasure" src="/assets/images/rDrama/treasure_mimic.gif" width="20" />
<em>A Mimic Ate {{c.treasure_amount.replace('-', '')}} Coins!</em>
{% else %}
<img class="treasure" alt="treasure" src="/assets/images/rDrama/treasure_coins.gif" width="20" />
<em>Found {{c.treasure_amount}} Coins!</em>
{% endif %}
{% endif %}
{% if c.slots_result %}
<em style="position: relative; top: 2px; margin-left: 0.5rem">{{c.slots_result}}</em>
{% endif %}