Skip to content

Commit

Permalink
Pal Game Balance Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dkoz committed Sep 28, 2024
1 parent afe0812 commit af848db
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
12 changes: 8 additions & 4 deletions cogs/palgame/battle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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."

Expand All @@ -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!"

Expand Down
8 changes: 5 additions & 3 deletions cogs/palgame/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
28 changes: 23 additions & 5 deletions utils/palgame.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit af848db

Please sign in to comment.