From af848dbe74d8ef0f22bd6ddff63a67d7af1f2d25 Mon Sep 17 00:00:00 2001 From: Kozejin <2613841+dkoz@users.noreply.github.com> Date: Sat, 28 Sep 2024 00:02:47 -0400 Subject: [PATCH] Pal Game Balance Changes --- cogs/palgame/battle.py | 12 ++++++++---- cogs/palgame/game.py | 8 +++++--- utils/palgame.py | 28 +++++++++++++++++++++++----- 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/cogs/palgame/battle.py b/cogs/palgame/battle.py index 61398d0..ebea67a 100644 --- a/cogs/palgame/battle.py +++ b/cogs/palgame/battle.py @@ -23,8 +23,9 @@ def load_pals(self): async def pal_autocomplete(self, interaction: nextcord.Interaction, current: str): user_pals = await get_pals(str(interaction.user.id)) - choices = [pal[0] for pal in user_pals if current.lower() in pal[0].lower()] - await interaction.response.send_autocomplete(choices) + top_pals = sorted(user_pals, key=lambda pal: pal[1], reverse=True)[:5] + choices = [pal[0] for pal in top_pals if current.lower() in pal[0].lower()] + await interaction.response.send_autocomplete(choices=choices) @nextcord.slash_command( name="battle", @@ -96,7 +97,9 @@ async def skill_callback(self, interaction, user, opponent_pal, skill, pal_data, if opponent_hp <= 0: result_text += f"\n{opponent_pal['Name']} has been defeated!" - experience_gained = 50 + base_experience = 50 + rarity_multiplier = opponent_pal.get('Rarity', 1) + experience_gained = base_experience * rarity_multiplier new_experience = experience + experience_gained result_text += f"\n{pal_data['Name']} gained {experience_gained} experience points." @@ -109,7 +112,8 @@ async def skill_callback(self, interaction, user, opponent_pal, skill, pal_data, await add_experience(str(interaction.user.id), pal_data['Name'], experience_gained) - points_awarded = random.randint(10, 20) + base_points = random.randint(10, 20) + points_awarded = int(base_points * rarity_multiplier) await add_points(str(interaction.user.id), user.name, points_awarded) result_text += f"\nYou earned {points_awarded} points for winning the battle!" diff --git a/cogs/palgame/game.py b/cogs/palgame/game.py index 9253c59..3c57c4a 100644 --- a/cogs/palgame/game.py +++ b/cogs/palgame/game.py @@ -115,12 +115,14 @@ async def butcher_callback(interaction: Interaction): async def mypals(self, interaction: Interaction): user_pals = await get_pals(str(interaction.user.id)) if not user_pals: - await interaction.response.send_message("You don't have any Pals yet! Use /catch to get some.") + await interaction.response.send_message("You don't have any Pals yet! Use `/catch` to get some.") return - embed = nextcord.Embed(title="Your Pals", description="Here are all the Pals you've caught:") + user_pals = sorted(user_pals, key=lambda pal: pal[1], reverse=True) + + embed = nextcord.Embed(title="Your Pals", description="Here are all the Pals you've caught!") for pal in user_pals: - embed.add_field(name=pal[0], value=f"Level: {pal[1]}, Experience: {pal[2]}", inline=False) + embed.add_field(name=f"{pal[0]} (Level {pal[1]})", value=f"Experience: {pal[2]}", inline=False) await interaction.response.send_message(embed=embed) def setup(bot): diff --git a/utils/palgame.py b/utils/palgame.py index 16fbc5b..0feb94d 100644 --- a/utils/palgame.py +++ b/utils/palgame.py @@ -27,13 +27,31 @@ async def get_pals(user_id): return pals async def level_up(user_id, pal_name): + # reworked leveling system... async with aiosqlite.connect(DATABASE_PATH) as db: - await db.execute(''' - UPDATE user_pals - SET level = level + 1, experience = 0 - WHERE user_id = ? AND pal_name = ? AND experience >= 1000; + cursor = await db.execute(''' + SELECT level, experience FROM user_pals + WHERE user_id = ? AND pal_name = ?; ''', (user_id, pal_name)) - await db.commit() + pal = await cursor.fetchone() + + if pal: + level = pal[0] + experience = pal[1] + + required_experience = 1000 + (level - 1) * 200 + + while experience >= required_experience: + level += 1 + experience -= required_experience + required_experience = 1000 + (level - 1) * 200 + + await db.execute(''' + UPDATE user_pals + SET level = ?, experience = ? + WHERE user_id = ? AND pal_name = ?; + ''', (level, experience, user_id, pal_name)) + await db.commit() async def get_stats(user_id, pal_name): async with aiosqlite.connect(DATABASE_PATH) as db: