def __init__(self, bot): self.time_alive = time.time() self.bot = bot self.bullet_dict = { "basic": "▪️", "money": user_json.get_currency_name(), "boost": "<:boost:907765841771257928>" }
async def rps(self, ctx, user_move: str = None, bid: str = None): try: bid = await user_json.can_do(ctx, ctx.author, bid) except: await ctx.send(embed=discord.Embed( title="", description= "You can start a rock-paper-scissor game with me by typing `{}rps <rock, paper, or scissors> <bet>`, {}." .format(ctx.prefix, ctx.author.mention))) return if user_move not in self.move_list.keys(): await ctx.send(embed=discord.Embed( title="", description= "You can start a rock-paper-scissor game with me by typing `{}rps <rock, paper, or scissors> <bet>`, {}." .format(ctx.prefix, ctx.author.mention))) return # choosing the bot's move bot_move = random.choice(list(self.move_list)) # grabbing initial bet initial_money = user_json.get_balance(ctx.author) # end conditions output = ["", ""] if user_move == bot_move: output[0] = "It's a tie!" output[1] = "Your bet is returned." bid = 0 elif (user_move == "rock" and bot_move == "scissors") or ( user_move == "paper" and bot_move == "rock") or (user_move == "scissors" and bot_move == "paper"): output[0] = "{} won!".format(ctx.author.name) output[1] = "You earned your bet!" else: output[0] = "{} lost!".format(ctx.author.name) output[1] = "You lost your bet!" bid = -bid user_json.add_balance(ctx.author, bid) embed = discord.Embed(title=output[0], description="{} {} :boom: {}".format( ctx.author.mention, self.move_list[user_move], self.move_list[bot_move])) embed.add_field(name="Payout:", value="{}\n{:,} тоХ {:,} {}".format( output[1], initial_money, user_json.get_balance(ctx.author), user_json.get_currency_name()), inline=False) await ctx.send(embed=embed)
def get_registered_user_info(self, user, user_dict): # Gets statistics of registered users. user_key = user_dict[str(user.id)] # Constructing the Embed. embed = discord.Embed( title=f"**{str(user)}** {self.get_nickname(user)}", color=user.color) embed.set_thumbnail(url=user.avatar_url) # Constructing registered user information. currency_name = user_json.get_currency_name() current_exp = user_key["exp"] exp_needed = user_json.get_req_exp(user, user_dict) # Adding additional fields to the Embed. bullet = self.get_bullet("basic") money = self.get_bullet("money") user_info = "\n".join([ f"{bullet} **Text Posts:** {user_key['text_posts']:,}", f"{bullet} **Level:** {user_key['level']:,}", f"{bullet} **EXP:** {current_exp:,}/{exp_needed:,} ({current_exp/exp_needed*100:.2f}\%)", f"{money} **Balance:** {user_key['balance']:,}", f"{money} **Adventure Wages:** {user_key['loot_earnings']:,}", f"{money} **Stolen Wages:** {user_key['stolen_money']:,}", f"{money} **Slot Winnings:** {user_key['slot_winnings']:,}" ]) # Adding additional fields to the Embed. embed.add_field(name="yvona Stats:", value=user_info, inline=False) # Adding user's inventory (if it exists) to the Embed. items = ", ".join(user_key["inventory"]) if items: embed.add_field(name="**Inventory:**", value=items) embed.set_footer(text=f"User ID: {str(user.id)}") return embed
def create_slot_embed(self, user, bet): reel = self.generate_reel() center_row = reel[1] payout_mult = self.get_payout(center_row) payout_total = bet * payout_mult user_money = user_json.get_balance(user) user_money_after = user_money - bet + payout_total embed = discord.Embed(title = "", description = self.beautify_reel(reel), color = user.color) embed.set_author(name = "{}'s Slot Machine".format(user.name), icon_url = user.avatar_url) embed.add_field(name = "**Payout:**", value = "{:,} × **{}** = {:,} {}".format(bet, payout_mult, payout_total, user_json.get_currency_name())) embed.set_footer(text = "Balance: {:,} → {:,} {}".format(user_money, user_money_after, user_json.get_currency_name())) self.slot_payout(user, payout_total - bet) return embed
class Slots(commands.Cog): def __init__(self, bot): self.bot = bot self.payouts = { # Reel.CHERRY: 2 (one cherry), # Reel.CHERRY: 5 (two cherries), Reel.CHERRY: 10, Reel.BELL: 10, Reel.STAR: 20, Reel.SEVEN: 30, Reel.LEMON: 40, Reel.GRAPE: 60, Reel.ORANGE: 100, Reel.EMPTY: 0 } def get_payout(self, center_row): row = set(center_row) if len(row) == 1: return self.payouts[row.pop()] elif Reel.CHERRY in row: if len(row) == 2: return 5 else: return 2 else: return 0 def generate_reel(self): reel = [[0, 0, 0], [0, 0, 0], [0, 0, 0]] for row in range(0, 3): for col in range(0, 3): reel[col][row] = random.choice(list(Reel)) return reel def beautify_reel(self, reel): reel_string = "" for row in range(0, 3): for col in range(0, 3): reel_string += reel[row][col].value + " " if row == 1: reel_string += ":arrow_left:" reel_string += "\n" return reel_string def create_slot_embed(self, user, bet): reel = self.generate_reel() center_row = reel[1] payout_mult = self.get_payout(center_row) payout_total = bet * payout_mult user_money = user_json.get_balance(user) user_money_after = user_money - bet + payout_total embed = discord.Embed(title = "", description = self.beautify_reel(reel), color = user.color) embed.set_author(name = "{}'s Slot Machine".format(user.name), icon_url = user.avatar_url) embed.add_field(name = "**Payout:**", value = "{:,} × **{}** = {:,} {}".format(bet, payout_mult, payout_total, user_json.get_currency_name())) embed.set_footer(text = "Balance: {:,} → {:,} {}".format(user_money, user_money_after, user_json.get_currency_name())) self.slot_payout(user, payout_total - bet) return embed def slot_payout(self, user, value): user_json.add_balance(user, value) user_json.add_slot_winnings(user, value) # plays slots @cog_ext.cog_slash(name = "slots", description = "Play some slots!", options = [create_option( name = "bet", description = "Amount of money to bet (must be at least 100 {}.".format(user_json.get_currency_name()), option_type = 4, required = True)]) async def slots(self, ctx, bet: int = 0): await ctx.defer() if not user_json.is_registered(ctx.author): embed = discord.Embed(title = "", description = ":no_entry: It looks like you aren't reigsted in the system, {}. Try `/register`.").format(ctx.author.mention) elif bet < 100: embed = discord.Embed(title = "", description = ":no_entry: You have to bet at least **100 {}**, {}.".format(user_json.get_currency_name(), ctx.author.mention)) elif bet > user_json.get_balance(ctx.author): embed = discord.Embed(title = "", description = ":no_entry: You don't have that much, {}!".format(ctx.author.mention)) embed.set_footer(text = "You have {:,} {}.".format(user_json.get_balance(ctx.author), user_json.get_currency_name())) else: embed = self.create_slot_embed(ctx.author, bet) buttons = [manage_components.create_button(style = ButtonStyle.green, label = "{:,}".format(bet), emoji = "🔁")] action_row = manage_components.create_actionrow(*buttons) await ctx.send(embed = embed, components = [action_row]) while user_json.get_balance(ctx.author) >= bet: button_ctx: ComponentContext = await wait_for_component(self.bot, components = action_row, check = lambda btn_ctx: btn_ctx.author_id == ctx.author_id) await button_ctx.edit_origin(embed = self.create_slot_embed(ctx.author, bet)) await ctx.send(embed = embed)
async def slots(self, ctx, bet: int = 0): await ctx.defer() if not user_json.is_registered(ctx.author): embed = discord.Embed(title = "", description = ":no_entry: It looks like you aren't reigsted in the system, {}. Try `/register`.").format(ctx.author.mention) elif bet < 100: embed = discord.Embed(title = "", description = ":no_entry: You have to bet at least **100 {}**, {}.".format(user_json.get_currency_name(), ctx.author.mention)) elif bet > user_json.get_balance(ctx.author): embed = discord.Embed(title = "", description = ":no_entry: You don't have that much, {}!".format(ctx.author.mention)) embed.set_footer(text = "You have {:,} {}.".format(user_json.get_balance(ctx.author), user_json.get_currency_name())) else: embed = self.create_slot_embed(ctx.author, bet) buttons = [manage_components.create_button(style = ButtonStyle.green, label = "{:,}".format(bet), emoji = "🔁")] action_row = manage_components.create_actionrow(*buttons) await ctx.send(embed = embed, components = [action_row]) while user_json.get_balance(ctx.author) >= bet: button_ctx: ComponentContext = await wait_for_component(self.bot, components = action_row, check = lambda btn_ctx: btn_ctx.author_id == ctx.author_id) await button_ctx.edit_origin(embed = self.create_slot_embed(ctx.author, bet)) await ctx.send(embed = embed)
async def msg_cannot_afford(self, ctx, user_balance, upgrade_cost): embed = discord.Embed(title = "**Item Upgrading**", description = "Sorry, {}, I don't give credit! Come back when you're a little... hmmm... richer!".format(ctx.author.mention), color = ctx.author.color) embed.add_field(name = "**Your Current Balance:**", value = "{:,} {}".format(user_balance, user_json.get_currency_name())) embed.add_field(name = "**Cost of One Upgrade:**", value = "{:,} {}".format(upgrade_cost, user_json.get_currency_name())) self.set_msg_thumbnail(embed, "upgrade") await ctx.send(embed = embed)
async def raid(self, ctx, *, boss: str = None): if not await self.msg_is_registered(ctx): return user_dict = user_json.get_users() user_level = self.get_user_level(ctx) user_item_level = self.get_user_item_level(ctx) # user level isn't high enough to embark on a raid if user_level < 10: embed = discord.Embed(title = "**Level Too Low!**", description = "You think I'll let a whelp like you embark on a raid, {}? Come back when you're a little stronger - say, **level 10**.".format(ctx.author.mention), color = ctx.author.color) embed.set_footer(text = "(You're currently level {:,})".format(user_level)) self.set_msg_thumbnail(embed, "raid") await ctx.send(embed = embed) ctx.command.reset_cooldown(ctx) return # print help information if no boss specified if boss == None: embed = discord.Embed(title = "**Raid**", description = "So you're interested in embarking on a **raid**, {0}? By embarking on a raid, you'll clash against a monster of tremendous strength and vigor. The damage you deal is based of your **item level**, so the higher your item level, the more damage you'll do and the more money you will receive as compensation for your efforts. Furthermore, once we eventually defeat a boss, we can begin to mobilize against a new threat. Of course, you'll also get EXP and I can only take you on a raid every **12 hours**.\n\nYour current item level is **{1}**, but you can increase that by using `{2}upgrade`. Once you think you're ready, you can use `{2}raid <name of raid zone>` to begin a raid. You can also check the status of all raid bosses with `{2}bosses`.".format(ctx.author.mention, user_item_level, ctx.prefix), color = ctx.author.color) self.set_msg_thumbnail(embed, "raid") await ctx.send(embed = embed) ctx.command.reset_cooldown(ctx) return boss_dict = user_json.get_bosses() boss_name = titlecase(boss) # boss is specified but non-existent if boss_name not in boss_dict.keys(): embed = discord.Embed(title = "**Raid**", description = "Uhh... are you sure you got the name right, {}? You can check the status of all raid bosses with `{}bosses`.".format(ctx.author.mention, ctx.prefix), color = ctx.author.color) self.set_msg_thumbnail(embed, "raid") await ctx.send(embed = embed) ctx.command.reset_cooldown(ctx) return boss = boss_dict[boss_name] # no damage dealt - attack failed if self.get_user_item_level(ctx) < boss_dict[boss_name]["defense"]: embed = discord.Embed(title = "**Raid Results:**", description = "**{}** completely endured {}'s attack! Retreat!".format(boss_name, ctx.author.mention)) embed.add_field(name = "**Notes:**", value = "When performing an attack against a boss, your item level is reduced by their defense. You're going to need to have a higher item level before you can challenge **{}** (your item level was **{:,}** while **{}'s** defense is **{:,}**). Try upgrading your item level with `{}upgrade`, then try again later.".format(boss_name, user_item_level, boss_name, boss["defense"], ctx.prefix)) embed.add_field(name = "**Forgiveness Cooldown:**", value = "Because your attack failed, your cooldown timer has been reset.", inline = False) self.set_msg_thumbnail(embed, "raid") await ctx.send(embed = embed) ctx.command.reset_cooldown(ctx) return damage_dealt = int(self.calculate_damage_dealt(user_level, user_item_level, boss_dict[boss_name]["defense"])) # attack succeeded # contribution score is based on % of boss's health damaged # this score will never go above 1 (10% of HP) or below .01 (.1% of HP) contribution_score = 10*damage_dealt/boss["hp_max"] if contribution_score > 1: contribution_score = 1 elif contribution_score < .01: contribution_score = .01 money_earned = self.calculate_money_earned(contribution_score, boss["multiplier"], boss["hp_max"]) exp_earned = self.calculate_exp_earned(contribution_score, boss["multiplier"], boss["hp_max"]) # if boss was already killed if boss["hp_cur"] == 0: money_earned = int(money_earned * 1.5) exp_earned = int(exp_earned * 1.5) result_msg = "" result_msg += "**Contribution:** {:,} Damage Dealt\n".format(damage_dealt) result_msg += "**Bounty Earned:** {:,} {}\n".format(money_earned, user_json.get_currency_name()) result_msg += "**EXP Earned:** {:,} exp\n".format(exp_earned) embed = discord.Embed(title = "**Raid Results:**", description = "A successful attack against **{}'s minions** was performed by {}!\n\n{}".format(boss_name, ctx.author.mention, result_msg), color = ctx.author.color) embed.add_field(name = "**Notes:**", value = "Although **{}** was slain long ago, their minions are still about. You'll receive a bonus towards your bounty as well as some extra EXP, but you should get ready to challenge the next boss if you can.".format(boss_name)) # if boss hasn't been killed yet else: boss["hp_cur"] = boss["hp_cur"] - damage_dealt # check if boss was killed was_killed = False if boss["hp_cur"] <= 0: boss["hp_cur"] = 0 was_killed = True # creating result message result_msg = "" result_msg += "**Contribution:** {:,} Damage Dealt ({:.2f}% of Boss's Total HP)\n".format(damage_dealt, (damage_dealt/boss["hp_max"])*100) result_msg += "**Remaining HP:** {:,} ({:.2f}% Remaining)\n".format(boss["hp_cur"], boss["hp_cur"]/boss["hp_max"]*100) result_msg += "**Bounty Earned:** {:,} {}\n".format(money_earned, user_json.get_currency_name()) result_msg += "**EXP Earned:** {:,} exp\n".format(exp_earned) embed = discord.Embed(title = "**Raid Results:**", description = "A successful attack against **{}** was performed by {}!\n\n{}".format(boss_name, ctx.author.mention, result_msg), color = ctx.author.color) # adding loot if user dealt the finishing blow if was_killed: embed.add_field(name = "**{}** was slain!".format(boss_name), value = "Hail to the great warrior {}, who landed the killing blow to **{}**! For their efforts, they have received **{}** from its remains! Long live {}!".format(ctx.author.mention, boss_name, boss["loot"], ctx.author.mention)) user_json.add_item(ctx.author, boss["loot"]) self.set_msg_thumbnail(embed, "raid") user_json.add_balance(ctx.author, money_earned) user_json.add_loot_earnings(ctx.author, money_earned) user_json.add_raid(ctx.author) user_json.add_damage_dealt(ctx.author, damage_dealt) await user_json.add_exp(ctx, ctx.author, exp_earned) boss_dict[boss_name] = boss user_json.update_bosses(boss_dict) await ctx.send(embed = embed)
async def upgrade(self, ctx, *, num_of_upgrades: str = None): if not await self.msg_is_registered(ctx): return # getting user's level user_level = self.get_user_level(ctx) # user level isn't high enough to perform upgrades if user_level < 10: embed = discord.Embed(title = "**Level Too Low!**", description = "Hmmm, it doesn't seem like you're strong enough to handle an upgraded weapon. Come back when you're at least **level 10.**", color = ctx.author.color) embed.set_footer(text = "(You're currently level {})".format(user_level)) self.set_msg_thumbnail(embed, "upgrade") await ctx.send(embed = embed) return user_item_level = self.get_user_item_level(ctx) initial_item_level = user_item_level user_balance = self.get_user_balance(ctx) # checks the cost of upgrading if num_of_upgrades == None: embed = discord.Embed(title = "**Item Upgrading**", description = "Are you interested in upgrading your item's level, {}? Right now your item level is **{:,}**, but I can increase it for you, for a small fee of course. If you'd like me to upgrade your item once, use `{}upgrade once`. Or, I can upgrade your item as many times as I can with `{}upgrade max`.".format(ctx.author.mention, user_item_level, ctx.prefix, ctx.prefix), color = ctx.author.color) embed.add_field(name = "**Your Current Balance:**", value = "{:,} {}".format(user_balance, user_json.get_currency_name())) embed.add_field(name = "**Cost of One Upgrade ({} тоХ {}):**".format(user_item_level, user_item_level+1), value = "{:,} {}".format(self.calculate_item_upgrade(user_item_level+1), user_json.get_currency_name())) self.set_msg_thumbnail(embed, "upgrade") await ctx.send(embed = embed) return # calculate cost of upgrades elif num_of_upgrades in ["once", "max"]: upgrade_cost = 0 # checking if the user can afford a single upgrade upgrade_cost = self.calculate_item_upgrade(user_item_level+1) if user_balance < upgrade_cost: # user cannot afford it await self.msg_cannot_afford(ctx, user_balance, upgrade_cost) return # upgrade once if num_of_upgrades == "once": final_item_level = user_item_level + 1 final_balance = user_balance - upgrade_cost # upgrade max else: num_of_upgrades = 1 while True: add_upgrade_cost = self.calculate_item_upgrade(user_item_level + num_of_upgrades) if upgrade_cost + add_upgrade_cost <= user_balance: upgrade_cost += self.calculate_item_upgrade(user_item_level + num_of_upgrades) num_of_upgrades += 1 else: break final_item_level = user_item_level + num_of_upgrades final_balance = user_balance - upgrade_cost # sending the final message user_dict = user_json.get_users() user_dict[str(ctx.author.id)]["item_level"] = final_item_level user_dict[str(ctx.author.id)]["balance"] = final_balance embed = discord.Embed(title = "**Item Upgrading**", description = "There you go, {}! Your level **{}** item is now level **{:,}**.".format(ctx.author.mention, initial_item_level, final_item_level), color = ctx.author.color) embed.add_field(name = "**Your Original Balance:**", value = "{:,} {}".format(user_balance, user_json.get_currency_name())) embed.add_field(name = "**Your Current Balance:**", value = "{:,} {}".format(final_balance, user_json.get_currency_name())) embed.add_field(name = "**Total Upgrade Costs:**", value = "{:,} {}".format(upgrade_cost, user_json.get_currency_name())) self.set_msg_thumbnail(embed, "upgrade") await ctx.send(embed = embed) user_json.update(user_dict) return else: embed = discord.Embed(title = "**Item Upgrading**", description = "I'm not quite sure what you said there, {}. If you'd like me to upgrade your item once, use `{}upgrade once`. Or, I can upgrade your item as many times as I can with `{}upgrade max`.".format(ctx.author.mention, ctx.prefix, ctx.prefix), color = ctx.author.color) self.set_msg_thumbnail(embed, "upgrade") await ctx.send(embed = embed) return
async def adventure(self, ctx, *, dungeon: str = None): if not await self.msg_is_registered(ctx): return # no dungeon specified if dungeon is None: embed = discord.Embed(title = "**Adventuring**", description = "Hello, {0}! Are you interested in exploring dungeons? Dungeons provide a consistent way of earning money and experience, though you can only go exploring every **10 minutes**. The higher your level, the more dungeons you can go to, and higher level dungeons provide more valuable loot! Keep in mind that the lower your level is compared to the recommended level of the dungeon, the lower your odds of performing a successful exploration. If the success rate is 0%, you can immediately go on another exploration.\n\nYou can pull up a list of dungeons that you can reasonably go to with `{1}dungeons` and explore a dungeon by using `{1}adventure <name of dungeon>`. Happy exploring!".format(ctx.author.mention, ctx.prefix), color = ctx.author.color) self.set_msg_thumbnail(embed, "adventure") await ctx.send(embed = embed) ctx.command.reset_cooldown(ctx) return dungeon_dict = user_json.get_dungeons() # if dungeon is specified but not a real dungeon if titlecase(dungeon) not in dungeon_dict["dungeons"]: embed = discord.Embed(title = "**Adventuring**", description = "Hmmm... I don't think that's the name of any dungeon I heard of, {}. You can see which dungeons you can go to by using `{}dungeons`.".format(ctx.author.mention, ctx.prefix), color = ctx.author.color) self.set_msg_thumbnail(embed, "adventure") await ctx.send(embed = embed) ctx.command.reset_cooldown(ctx) return # prepping dicts and keys dungeon = titlecase(dungeon) user_dict = user_json.get_users() user_level = user_dict[str(ctx.author.id)]["level"] dungeon_level = dungeon_dict["dungeons"][dungeon]["level"] # calculating success rate (min is 0%, max is 100%) success_rate = self.get_dungeon_success_rate(user_level, dungeon_level) if success_rate < 0: success_rate = 0 if success_rate > 100: success_rate = 100 random_rate = randint(0,100) # rng to determine success # if the adventure is successful if random_rate <= success_rate: loot_table = dungeon_dict["dungeons"][dungeon]["loot"] loot_list = self.get_loot(loot_table) payout = 0 # calculating value of all loot for loot in loot_list: payout = payout + loot_table[loot] * self.get_user_item_level(ctx) user_json.add_balance(ctx.author, payout) exp = int(dungeon_dict["dungeons"][dungeon]["exp"] * uniform(.95,1.15)) # creating embed embed = discord.Embed(title = "**Adventure successful!**", description = "{} embarked on an adventure to **{}** and succeeded!".format(ctx.author.mention, dungeon), color = ctx.author.color) embed.add_field(name = "**Loot found:**", value = ', '.join(loot_list), inline = False) embed.add_field(name = "**Results:**", value = "Sold **{:,}** piece(s) of loot for **{:,} {}**\nGained **{:,}** exp".format(len(loot_list), payout, user_json.get_currency_name(), exp) , inline = False) user_json.add_loot_earnings(ctx.author, payout) await user_json.add_exp(ctx, ctx.author, exp) # if the adventure failed else: embed = discord.Embed(title = "**Adventure failed...**", description = "{} embarked on an adventure to **{}** and failed!".format(ctx.author.mention, dungeon), color = ctx.author.color) if success_rate == 0: embed.add_field(name = "**Forgiveness Cooldown:**", value = "Because your chance to succeed was 0%, your cooldown timer has been reset.") ctx.command.reset_cooldown(ctx) embed.set_footer(text = "{}% success rate".format(success_rate)) self.set_msg_thumbnail(embed, "adventure") await ctx.send(embed = embed)