forked from rDrama/rDrama
1
0
Fork 0
rDrama/files/classes/treasure.py

43 lines
962 B
Python
Raw Normal View History

import random
class Treasure:
2022-01-29 05:06:08 +00:00
special_min = 100
special_max = 1000
standard_min = 10
standard_max = 100
2022-01-29 05:06:08 +00:00
def __init__(self, g):
self.db = g.db
2022-01-29 05:06:08 +00:00
def check_for_treasure(self, in_text, from_comment):
2022-01-31 01:41:04 +00:00
has_gamble_command = '!slots' in in_text or '!casino' in in_text or '!blackjack' in in_text
2022-01-29 05:06:08 +00:00
if not has_gamble_command:
seed = random.randint(1, 1000)
is_special = seed == 1000 # 0.1% chance
is_standard = seed >= 990 # 1.0% chance
amount = 0
2022-01-29 05:06:08 +00:00
if is_special:
amount = random.randint(self.special_min, self.special_max)
elif is_standard:
amount = random.randint(self.standard_min, self.standard_max)
2022-01-29 05:06:08 +00:00
# Mimic: 25% chance
if random.randint(1, 100) > 75:
amount = -amount
2022-01-29 05:06:08 +00:00
if amount != 0:
user = from_comment.author
user.coins += amount
2022-01-29 05:06:08 +00:00
if user.coins < 0:
user.coins = 0
2022-01-29 05:06:08 +00:00
from_comment.treasure_amount = str(amount)
2022-01-29 05:06:08 +00:00
self.db.add(user)
self.db.add(from_comment)
self.db.commit()