forked from MarseyWorld/MarseyWorld
Add treasure boxes (#188)
* Filter out slots from the body. (#181) * Slots changes (#182) * Switch slots result to title and fix snappy * These two guys again * These two guys again * Fix breaking-even * ...?? * Initial commit * Finalize initial blackjack attempt * Fix blackjack issue * Add treasure functionality * Remove obsolete file * Add blackjack winnings to user winnings * Minor changes to treasure functionality * 25 percent chance of mimicmaster
parent
546feec88d
commit
c7de23c51a
|
@ -11,6 +11,7 @@ from .votes import *
|
|||
from .domains import *
|
||||
from .slots import *
|
||||
from .blackjack import *
|
||||
from .treasure import *
|
||||
from .subscriptions import *
|
||||
from files.__main__ import app
|
||||
from .mod_logs import *
|
||||
|
|
|
@ -64,10 +64,8 @@ class Blackjack:
|
|||
if self.command_word in in_text:
|
||||
for word in in_text.split():
|
||||
if self.command_word in word:
|
||||
try:
|
||||
wager = word[len(self.command_word):]
|
||||
wager_value = int(wager)
|
||||
except: break
|
||||
|
||||
if (wager_value < self.minimum_bet):
|
||||
break
|
||||
|
@ -158,11 +156,12 @@ class Blackjack:
|
|||
elif result == 'won':
|
||||
reward = int(wager) * 2
|
||||
elif result == 'blackjack':
|
||||
reward = floor(int(wager) * (3/2))
|
||||
reward = int(wager) + floor(int(wager) * (3/2))
|
||||
|
||||
if (reward > 0):
|
||||
user = from_comment.author
|
||||
user.coins += reward
|
||||
user.winnings += reward - int(wager)
|
||||
|
||||
self.db.add(user)
|
||||
self.db.commit()
|
|
@ -45,6 +45,7 @@ class Comment(Base):
|
|||
ban_reason = Column(String)
|
||||
slots_result = Column(String)
|
||||
blackjack_result = Column(String)
|
||||
treasure_amount = Column(String)
|
||||
|
||||
post = relationship("Submission", viewonly=True)
|
||||
author = relationship("User", primaryjoin="User.id==Comment.author_id")
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
import random
|
||||
|
||||
|
||||
class Treasure:
|
||||
special_min = 100
|
||||
special_max = 1000
|
||||
standard_min = 10
|
||||
standard_max = 100
|
||||
|
||||
def __init__(self, g):
|
||||
self.db = g.db
|
||||
|
||||
def check_for_treasure(self, in_text, from_comment):
|
||||
has_gamble_command = '!slots' in in_text or '!blackjack' in in_text
|
||||
|
||||
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
|
||||
|
||||
if is_special:
|
||||
amount = random.randint(self.special_min, self.special_max)
|
||||
elif is_standard:
|
||||
amount = random.randint(self.standard_min, self.standard_max)
|
||||
|
||||
# Mimic: 25% chance
|
||||
if random.randint(1, 100) > 75:
|
||||
amount = -amount
|
||||
|
||||
if amount != 0:
|
||||
user = from_comment.author
|
||||
user.coins += amount
|
||||
|
||||
if user.coins < 0:
|
||||
user.coins = 0
|
||||
|
||||
from_comment.treasure_amount = str(amount)
|
||||
|
||||
self.db.add(user)
|
||||
self.db.add(from_comment)
|
||||
self.db.commit()
|
|
@ -595,6 +595,9 @@ def api_comment(v):
|
|||
blackjack = Blackjack(g)
|
||||
blackjack.check_for_blackjack_command(body, v, c)
|
||||
|
||||
treasure = Treasure(g)
|
||||
treasure.check_for_treasure(body, c)
|
||||
|
||||
g.db.commit()
|
||||
|
||||
if request.headers.get("Authorization"): return c.json
|
||||
|
|
|
@ -181,6 +181,7 @@
|
|||
{% set blackjack_status = split_result[3] %}
|
||||
{% set player_hand = split_result[0].replace('X', '10') %}
|
||||
{% set dealer_hand = split_result[1].split('/')[0] if blackjack_status == 'active' else split_result[1] %}
|
||||
{% set dealer_hand = dealer_hand.replace('X', '10') %}
|
||||
{% set wager = split_result[4] %}
|
||||
{% endif %}
|
||||
|
||||
|
@ -238,6 +239,15 @@
|
|||
<span class="time-edited" id="time-edit-{{c.id}}" onmouseover="timestamp('time-edit-{{c.id}}','{{c.edited_utc}}')"><span>·</span> <span class="font-italic">Edited {{c.edited_string}}</span></span>
|
||||
{% endif %}
|
||||
|
||||
{% if c.treasure_amount and c.treasure_amount != '0' %}
|
||||
<img alt="treasure" src="/static/assets/images/chest.png" 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 %}
|
||||
{% endif %}
|
||||
|
||||
{% if c.slots_result %}
|
||||
<em style="position: relative; top: 2px; margin-left: 0.5rem">{{c.slots_result}}</em>
|
||||
{% endif %}
|
||||
|
|
|
@ -301,7 +301,8 @@ CREATE TABLE public.comments (
|
|||
is_pinned_utc integer,
|
||||
ghost boolean,
|
||||
slots_result character varying(50),
|
||||
blackjack_result character varying(3000)
|
||||
blackjack_result character varying(3000),
|
||||
treasure_amount character varying(10)
|
||||
);
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue