From ca991f81f78711a73f3ad09a2ed512fdfcbf4ae1 Mon Sep 17 00:00:00 2001 From: wlinator Date: Fri, 14 Jul 2023 12:32:48 -0400 Subject: [PATCH] Economy balancing --- config/economy.json | 10 +- modules/gambling.py | 71 +--------- modules/slots.py | 251 ++++++++++++++++++++++++++++++++++ sb_tools/economy_embeds.py | 132 +----------------- sb_tools/economy_functions.py | 34 ----- 5 files changed, 259 insertions(+), 239 deletions(-) create mode 100644 modules/slots.py diff --git a/config/economy.json b/config/economy.json index 3a25d08..263a319 100644 --- a/config/economy.json +++ b/config/economy.json @@ -7,7 +7,7 @@ "hit": "<:hit:1119262723285467156>", "stand": "<:stand:1118923298298929154>" }, - "reward_multiplier": 1.5, + "reward_multiplier": 1.2, "deck_suits": [ "♠", "♡", @@ -62,10 +62,10 @@ "lost": 1119288454212243607 }, "reward_multipliers": { - "pair": 1, - "three_of_a_kind": 3, - "three_diamonds": 4, - "jackpot": 5 + "pair": 1.5, + "three_of_a_kind": 4, + "three_diamonds": 6, + "jackpot": 15 } }, "duel": { diff --git a/modules/gambling.py b/modules/gambling.py index 6982548..f3d4141 100644 --- a/modules/gambling.py +++ b/modules/gambling.py @@ -1,4 +1,3 @@ -import asyncio import os import random @@ -8,7 +7,6 @@ from dotenv import load_dotenv from data.BlackJackStats import BlackJackStats from data.Currency import Currency -from data.SlotsStats import SlotsStats from handlers.ItemHandler import ItemHandler from main import economy_config from sb_tools import economy_embeds, economy_functions, universal, interaction, embeds @@ -53,6 +51,7 @@ class GamblingCog(commands.Cog): player_hand = [] dealer_hand = [] deck = economy_functions.blackjack_get_new_deck() + multiplier = float(economy_config["blackjack"]["reward_multiplier"]) # deal initial cards (player draws two & dealer one) player_hand.append(economy_functions.blackjack_deal_card(deck)) @@ -133,7 +132,7 @@ class GamblingCog(commands.Cog): else: # bet multiplier - payout = bet * float(economy_config["blackjack"]["reward_multiplier"]) + payout = bet * multiplier if not status == "player_blackjack" else bet * 2 ctx_currency.add_cash(payout) ctx_currency.push() @@ -160,72 +159,6 @@ class GamblingCog(commands.Cog): # remove player from active games list del active_blackjack_games[ctx.author.id] - @commands.slash_command( - name="slots", - descriptions="Spin the slots for a chance to win the jackpot!", - guild_only=True - ) - @commands.check(universal.channel_check) - async def slots(self, ctx, *, bet: discord.Option(int)): - - # Currency handler - ctx_currency = Currency(ctx.author.id) - - # check if the user has enough cash - player_cash_balance = ctx_currency.cash - if bet > player_cash_balance or bet <= 0: - await ctx.respond(embed=economy_embeds.not_enough_cash()) - return - - # calculate the results before the command is shown - results = [random.randint(0, 6) for i in range(3)] - calculated_results = economy_functions.calculate_slots_results(bet, results) - - type = calculated_results[0] - payout = calculated_results[1] - multiplier = calculated_results[2] - is_won = True - - if type == "lost": - is_won = False - - # start with default "spinning" embed - await ctx.respond(embed=economy_embeds.slots_spinning(ctx, 3, bet, results, self.bot)) - await asyncio.sleep(1) - await ctx.edit(embed=economy_embeds.slots_spinning(ctx, 2, bet, results, self.bot), - allowed_mentions=discord.AllowedMentions.none()) - await asyncio.sleep(1) - await ctx.edit(embed=economy_embeds.slots_spinning(ctx, 1, bet, results, self.bot), - allowed_mentions=discord.AllowedMentions.none()) - await asyncio.sleep(1) - await ctx.edit(embed=economy_embeds.slots_finished(ctx, type, multiplier, bet, results, self.bot), - allowed_mentions=discord.AllowedMentions.none()) - - # user payout - if payout >= 0: - ctx_currency.add_cash(payout) - else: - ctx_currency.take_cash(payout) - - # push stats (low priority) - if payout <= 0: - payout = 0 - - item_reward = ItemHandler(ctx) - await item_reward.rave_coin(is_won=is_won, bet=bet) - - stats = SlotsStats( - user_id=ctx.author.id, - is_won=is_won, - bet=bet, - payout=payout, - spin_type=type, - icons=results - ) - - ctx_currency.push() - stats.push() - @commands.slash_command( name="duel", description="Challenge another player to a fight.", diff --git a/modules/slots.py b/modules/slots.py new file mode 100644 index 0000000..4e60b9e --- /dev/null +++ b/modules/slots.py @@ -0,0 +1,251 @@ +import asyncio +import datetime +import random +from collections import Counter + +import discord +import pytz +from discord.ext import commands + +from data.Currency import Currency +from data.SlotsStats import SlotsStats +from handlers.ItemHandler import ItemHandler +from main import economy_config +from sb_tools import economy_embeds, universal + +est = pytz.timezone('US/Eastern') + + +def calculate_slots_results(bet, results): + type = None + multiplier = None + rewards = economy_config["slots"]["reward_multipliers"] + + # count occurrences of each item in the list + counts = Counter(results) + + # no icons match + if len(counts) == 3: + type = "lost" + multiplier = 0 + + # pairs + elif len(counts) == 2: + type = "pair" + multiplier = rewards[type] + + # 3 of a kind + elif len(counts) == 1: + + if results[0] == 5: + type = "three_diamonds" + multiplier = rewards[type] + + elif results[0] == 6: + type = "jackpot" + multiplier = rewards[type] + + else: + type = "three_of_a_kind" + multiplier = rewards[type] + + payout = bet * multiplier + return type, int(payout), multiplier + + +def slots_spinning(ctx, spinning_icons_amount, bet, results, sbbot): + first_slots_emote = sbbot.get_emoji(economy_config["slots"]["emotes"][f"slots_{results[0]}_id"]) + second_slots_emote = sbbot.get_emoji(economy_config["slots"]["emotes"][f"slots_{results[1]}_id"]) + slots_animated_emote = sbbot.get_emoji(economy_config["slots"]["emotes"][f"slots_animated_id"]) + + decoration = economy_config["slots"]["emotes"] + S_Wide = sbbot.get_emoji(decoration["S_Wide"]) + L_Wide = sbbot.get_emoji(decoration["L_Wide"]) + O_Wide = sbbot.get_emoji(decoration["O_Wide"]) + T_Wide = sbbot.get_emoji(decoration["T_Wide"]) + + CBorderBLeft = sbbot.get_emoji(decoration["CBorderBLeft"]) + CBorderBRight = sbbot.get_emoji(decoration["CBorderBRight"]) + CBorderTLeft = sbbot.get_emoji(decoration["CBorderTLeft"]) + CBorderTRight = sbbot.get_emoji(decoration["CBorderTRight"]) + HBorderB = sbbot.get_emoji(decoration["HBorderB"]) + HBorderT = sbbot.get_emoji(decoration["HBorderT"]) + VBorder = sbbot.get_emoji(decoration["VBorder"]) + + Blank = sbbot.get_emoji(decoration["Blank"]) + + current_time = datetime.datetime.now(est).strftime("%I:%M %p") + one = slots_animated_emote + two = slots_animated_emote + three = slots_animated_emote + + if spinning_icons_amount == 3: + pass + elif spinning_icons_amount == 2: + one = first_slots_emote + elif spinning_icons_amount == 1: + one = first_slots_emote + two = second_slots_emote + + description = f"🎰{S_Wide}{L_Wide}{O_Wide}{T_Wide}{S_Wide}🎰\n" \ + f"{CBorderTLeft}{HBorderT}{HBorderT}{HBorderT}{HBorderT}{HBorderT}{CBorderTRight}\n" \ + f"{VBorder}{one}{VBorder}{two}{VBorder}{three}{VBorder}\n" \ + f"{CBorderBLeft}{HBorderB}{HBorderB}{HBorderB}{HBorderB}{HBorderB}{CBorderBRight}\n" \ + f"{Blank}{Blank}❓❓❓{Blank}{Blank}{Blank}" + + embed = discord.Embed( + description=description + ) + embed.set_author(name=ctx.author.name, icon_url=ctx.author.avatar.url) + embed.set_footer(text=f"Bet ${bet} • jackpot = x15 • {current_time}", + icon_url="https://i.imgur.com/wFsgSnr.png") + + return embed + + +def slots_finished(ctx, payout_type, multiplier, bet, results, sbbot): + first_slots_emote = sbbot.get_emoji(economy_config["slots"]["emotes"][f"slots_{results[0]}_id"]) + second_slots_emote = sbbot.get_emoji(economy_config["slots"]["emotes"][f"slots_{results[1]}_id"]) + third_slots_emote = sbbot.get_emoji(economy_config["slots"]["emotes"][f"slots_{results[2]}_id"]) + current_time = datetime.datetime.now(est).strftime("%I:%M %p") + + decoration = economy_config["slots"]["emotes"] + S_Wide = sbbot.get_emoji(decoration["S_Wide"]) + L_Wide = sbbot.get_emoji(decoration["L_Wide"]) + O_Wide = sbbot.get_emoji(decoration["O_Wide"]) + T_Wide = sbbot.get_emoji(decoration["T_Wide"]) + + CBorderBLeft = sbbot.get_emoji(decoration["CBorderBLeft"]) + CBorderBRight = sbbot.get_emoji(decoration["CBorderBRight"]) + CBorderTLeft = sbbot.get_emoji(decoration["CBorderTLeft"]) + CBorderTRight = sbbot.get_emoji(decoration["CBorderTRight"]) + HBorderB = sbbot.get_emoji(decoration["HBorderB"]) + HBorderT = sbbot.get_emoji(decoration["HBorderT"]) + VBorder = sbbot.get_emoji(decoration["VBorder"]) + + WSmall = sbbot.get_emoji(decoration["WSmall"]) + ISmall = sbbot.get_emoji(decoration["ISmall"]) + NSmall = sbbot.get_emoji(decoration["NSmall"]) + + LCentered = sbbot.get_emoji(decoration["LCentered"]) + OCentered = sbbot.get_emoji(decoration["OCentered"]) + SCentered = sbbot.get_emoji(decoration["SCentered"]) + ECentered = sbbot.get_emoji(decoration["ECentered"]) + + Blank = sbbot.get_emoji(decoration["Blank"]) + lost_emoji = sbbot.get_emoji(decoration["lost"]) + + field_name = "You lost." + field_value = f"You lost **${bet}**." + color = discord.Color.red() + is_lost = True + + if payout_type == "pair": + field_name = "Pair" + field_value = f"You won **${bet * multiplier}**." + is_lost = False + discord.Color.dark_green() + elif payout_type == "three_of_a_kind": + field_name = "3 of a kind" + field_value = f"You won **${bet * multiplier}**." + is_lost = False + discord.Color.dark_green() + elif payout_type == "three_diamonds": + field_name = "Triple Diamonds!" + field_value = f"You won **${bet * multiplier}**." + is_lost = False + discord.Color.green() + elif payout_type == "jackpot": + field_name = "JACKPOT!!" + field_value = f"You won **${bet * multiplier}**." + is_lost = False + discord.Color.green() + + description = f"🎰{S_Wide}{L_Wide}{O_Wide}{T_Wide}{S_Wide}🎰\n" \ + f"{CBorderTLeft}{HBorderT}{HBorderT}{HBorderT}{HBorderT}{HBorderT}{CBorderTRight}\n" \ + f"{VBorder}{first_slots_emote}{VBorder}{second_slots_emote}{VBorder}{third_slots_emote}{VBorder}\n" \ + f"{CBorderBLeft}{HBorderB}{HBorderB}{HBorderB}{HBorderB}{HBorderB}{CBorderBRight}" + + if is_lost: + description += f"\n{Blank}{LCentered}{OCentered}{SCentered}{ECentered}{lost_emoji}{Blank}" + else: + description += f"\n{Blank}🎉{WSmall}{ISmall}{NSmall}🎉{Blank}" + + embed = discord.Embed( + color=color, + description=description + ) + embed.add_field(name=field_name, value=field_value) + embed.set_author(name=ctx.author.name, icon_url=ctx.author.avatar.url) + embed.set_footer(text=f"Bet ${bet} • jackpot = x15 • {current_time}", + icon_url="https://i.imgur.com/wFsgSnr.png") + + return embed + + +class SlotsCog(commands.Cog): + def __init__(self, sbbot): + self.bot = sbbot + + @commands.slash_command( + name="slots", + descriptions="Spin the slots for a chance to win the jackpot!", + guild_only=True + ) + @commands.check(universal.channel_check) + async def slots(self, ctx, *, bet: discord.Option(int)): + + # Currency handler + ctx_currency = Currency(ctx.author.id) + + # check if the user has enough cash + player_cash_balance = ctx_currency.cash + if bet > player_cash_balance or bet <= 0: + await ctx.respond(embed=economy_embeds.not_enough_cash()) + return + + # calculate the results before the command is shown + results = [random.randint(0, 6) for _ in range(3)] + calculated_results = calculate_slots_results(bet, results) + + (type, payout, multiplier) = calculated_results + is_won = True + + if type == "lost": + is_won = False + + # start with default "spinning" embed + await ctx.respond(embed=slots_spinning(ctx, 3, bet, results, self.bot)) + await asyncio.sleep(1) + + for i in range(2, 0, -1): + await ctx.edit(embed=slots_spinning(ctx, i, bet, results, self.bot)) + await asyncio.sleep(1) + + # output final result + await ctx.edit(embed=slots_finished(ctx, type, multiplier, bet, results, self.bot)) + + # user payout + if payout > 0: + ctx_currency.add_cash(payout) + else: + ctx_currency.take_cash(bet) + + item_reward = ItemHandler(ctx) + await item_reward.rave_coin(is_won=is_won, bet=bet) + + stats = SlotsStats( + user_id=ctx.author.id, + is_won=is_won, + bet=bet, + payout=payout, + spin_type=type, + icons=results + ) + + ctx_currency.push() + stats.push() + + +def setup(sbbot): + sbbot.add_cog(SlotsCog(sbbot)) diff --git a/sb_tools/economy_embeds.py b/sb_tools/economy_embeds.py index d3ebd3c..0ddb203 100644 --- a/sb_tools/economy_embeds.py +++ b/sb_tools/economy_embeds.py @@ -164,7 +164,7 @@ def blackjack_show(ctx, bet, player_hand, dealer_hand, player_hand_value, dealer title_text = "YOU LOST!" thumbnail_url = "https://i.imgur.com/rc68c43.png" color = discord.Color.red() - + elif status == "player_won_21": title_text = "YOU WON!" thumbnail_url = "https://i.imgur.com/dvIIr2G.png" @@ -200,136 +200,6 @@ def blackjack_show(ctx, bet, player_hand, dealer_hand, player_hand_value, dealer return embed -def slots_spinning(ctx, spinning_icons_amount, bet, results, sbbot): - first_slots_emote = sbbot.get_emoji(json_data["slots"]["emotes"][f"slots_{results[0]}_id"]) - second_slots_emote = sbbot.get_emoji(json_data["slots"]["emotes"][f"slots_{results[1]}_id"]) - slots_animated_emote = sbbot.get_emoji(json_data["slots"]["emotes"][f"slots_animated_id"]) - - decoration = json_data["slots"]["emotes"] - S_Wide = sbbot.get_emoji(decoration["S_Wide"]) - L_Wide = sbbot.get_emoji(decoration["L_Wide"]) - O_Wide = sbbot.get_emoji(decoration["O_Wide"]) - T_Wide = sbbot.get_emoji(decoration["T_Wide"]) - - CBorderBLeft = sbbot.get_emoji(decoration["CBorderBLeft"]) - CBorderBRight = sbbot.get_emoji(decoration["CBorderBRight"]) - CBorderTLeft = sbbot.get_emoji(decoration["CBorderTLeft"]) - CBorderTRight = sbbot.get_emoji(decoration["CBorderTRight"]) - HBorderB = sbbot.get_emoji(decoration["HBorderB"]) - HBorderT = sbbot.get_emoji(decoration["HBorderT"]) - VBorder = sbbot.get_emoji(decoration["VBorder"]) - - Blank = sbbot.get_emoji(decoration["Blank"]) - - current_time = datetime.datetime.now(est).strftime("%I:%M %p") - one = slots_animated_emote - two = slots_animated_emote - three = slots_animated_emote - - if spinning_icons_amount == 3: - pass - elif spinning_icons_amount == 2: - one = first_slots_emote - elif spinning_icons_amount == 1: - one = first_slots_emote - two = second_slots_emote - - description = f"🎰{S_Wide}{L_Wide}{O_Wide}{T_Wide}{S_Wide}🎰\n" \ - f"{CBorderTLeft}{HBorderT}{HBorderT}{HBorderT}{HBorderT}{HBorderT}{CBorderTRight}\n" \ - f"{VBorder}{one}{VBorder}{two}{VBorder}{three}{VBorder}\n" \ - f"{CBorderBLeft}{HBorderB}{HBorderB}{HBorderB}{HBorderB}{HBorderB}{CBorderBRight}\n" \ - f"{Blank}{Blank}❓❓❓{Blank}{Blank}{Blank}" - - embed = discord.Embed( - description=description - ) - embed.set_author(name=ctx.author.name, icon_url=ctx.author.avatar.url) - embed.set_footer(text=f"Bet {cash_balance_name}{bet} • jackpot = x5 • {current_time}", - icon_url="https://i.imgur.com/wFsgSnr.png") - - return embed - - -def slots_finished(ctx, payout_type, multiplier, bet, results, sbbot): - first_slots_emote = sbbot.get_emoji(json_data["slots"]["emotes"][f"slots_{results[0]}_id"]) - second_slots_emote = sbbot.get_emoji(json_data["slots"]["emotes"][f"slots_{results[1]}_id"]) - third_slots_emote = sbbot.get_emoji(json_data["slots"]["emotes"][f"slots_{results[2]}_id"]) - current_time = datetime.datetime.now(est).strftime("%I:%M %p") - - decoration = json_data["slots"]["emotes"] - S_Wide = sbbot.get_emoji(decoration["S_Wide"]) - L_Wide = sbbot.get_emoji(decoration["L_Wide"]) - O_Wide = sbbot.get_emoji(decoration["O_Wide"]) - T_Wide = sbbot.get_emoji(decoration["T_Wide"]) - - CBorderBLeft = sbbot.get_emoji(decoration["CBorderBLeft"]) - CBorderBRight = sbbot.get_emoji(decoration["CBorderBRight"]) - CBorderTLeft = sbbot.get_emoji(decoration["CBorderTLeft"]) - CBorderTRight = sbbot.get_emoji(decoration["CBorderTRight"]) - HBorderB = sbbot.get_emoji(decoration["HBorderB"]) - HBorderT = sbbot.get_emoji(decoration["HBorderT"]) - VBorder = sbbot.get_emoji(decoration["VBorder"]) - - WSmall = sbbot.get_emoji(decoration["WSmall"]) - ISmall = sbbot.get_emoji(decoration["ISmall"]) - NSmall = sbbot.get_emoji(decoration["NSmall"]) - - LCentered = sbbot.get_emoji(decoration["LCentered"]) - OCentered = sbbot.get_emoji(decoration["OCentered"]) - SCentered = sbbot.get_emoji(decoration["SCentered"]) - ECentered = sbbot.get_emoji(decoration["ECentered"]) - - Blank = sbbot.get_emoji(decoration["Blank"]) - lost_emoji = sbbot.get_emoji(decoration["lost"]) - - field_name = "You lost." - field_value = f"You lost **{cash_balance_name}{bet}**." - color = discord.Color.red() - is_lost = True - - if payout_type == "pair": - field_name = "Pair" - field_value = f"You won **{cash_balance_name}{bet * multiplier}**." - is_lost = False - discord.Color.dark_green() - elif payout_type == "three_of_a_kind": - field_name = "3 of a kind" - field_value = f"You won **{cash_balance_name}{bet * multiplier}**." - is_lost = False - discord.Color.dark_green() - elif payout_type == "three_diamonds": - field_name = "Triple Diamonds!" - field_value = f"You won **{cash_balance_name}{bet * multiplier}**." - is_lost = False - discord.Color.green() - elif payout_type == "jackpot": - field_name = "JACKPOT!!" - field_value = f"You won **{cash_balance_name}{bet * multiplier}**." - is_lost = False - discord.Color.green() - - description = f"🎰{S_Wide}{L_Wide}{O_Wide}{T_Wide}{S_Wide}🎰\n" \ - f"{CBorderTLeft}{HBorderT}{HBorderT}{HBorderT}{HBorderT}{HBorderT}{CBorderTRight}\n" \ - f"{VBorder}{first_slots_emote}{VBorder}{second_slots_emote}{VBorder}{third_slots_emote}{VBorder}\n" \ - f"{CBorderBLeft}{HBorderB}{HBorderB}{HBorderB}{HBorderB}{HBorderB}{CBorderBRight}" - - if is_lost: - description += f"\n{Blank}{LCentered}{OCentered}{SCentered}{ECentered}{lost_emoji}{Blank}" - else: - description += f"\n{Blank}🎉{WSmall}{ISmall}{NSmall}🎉{Blank}" - - embed = discord.Embed( - color=color, - description=description - ) - embed.add_field(name=field_name, value=field_value) - embed.set_author(name=ctx.author.name, icon_url=ctx.author.avatar.url) - embed.set_footer(text=f"Bet {cash_balance_name}{bet} • jackpot = x5 • {current_time}", - icon_url="https://i.imgur.com/wFsgSnr.png") - - return embed - - def daily_claim(amount, streak): embed = discord.Embed( color=discord.Color.green(), diff --git a/sb_tools/economy_functions.py b/sb_tools/economy_functions.py index dfe72b8..73320db 100644 --- a/sb_tools/economy_functions.py +++ b/sb_tools/economy_functions.py @@ -1,5 +1,4 @@ import random -from collections import Counter from main import economy_config @@ -49,36 +48,3 @@ def blackjack_calculate_hand_value(hand): value -= 10 * aces_count return value - - -def calculate_slots_results(bet, results): - type = None - multiplier = None - - # count occurrences of each item in the list - counts = Counter(results) - - # no icons match - if len(counts) == 3: - type = "lost" - multiplier = -1 - - # pairs - elif len(counts) == 2: - type = "pair" - multiplier = 1 - - # 3 of a kind - elif len(counts) == 1: - if results[0] == 5: - type = "three_diamonds" - multiplier = 4 - elif results[0] == 6: - type = "jackpot" - multiplier = 5 - else: - type = "three_of_a_kind" - multiplier = 3 - - payout = bet * multiplier - return type, payout, multiplier