coollsd commited on
Commit
43e7998
·
verified ·
1 Parent(s): 5cc1075

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -10
app.py CHANGED
@@ -95,20 +95,16 @@ async def perform_roll(interaction: discord.Interaction):
95
  user_id = interaction.user.id
96
  luck_multiplier = luck_multipliers.get(user_id, 1)
97
 
98
- # Adjust difficulty based on luck
99
- for pet in pets:
100
- pet['configData']['difficulty'] *= luck_multiplier
101
-
102
  # Calculate total difficulty
103
- total_difficulty = sum(1 / pet['configData']['difficulty'] for pet in pets)
104
 
105
  # Generate a random number between 0 and total_difficulty
106
  random_value = random.uniform(0, total_difficulty)
107
 
108
- # Select a pet based on the random value
109
  cumulative_probability = 0
110
- for pet in pets:
111
- cumulative_probability += 1 / pet['configData']['difficulty']
112
  if random_value <= cumulative_probability:
113
  rolled_pet = pet
114
  break
@@ -157,14 +153,14 @@ async def perform_roll(interaction: discord.Interaction):
157
  if result:
158
  await interaction.followup.send(embed=result[0], view=result[1])
159
  else:
160
- await interaction.followup.send("errer.")
161
 
162
  roll_again_button.callback = roll_again_callback
163
 
164
  view = discord.ui.View()
165
  view.add_item(roll_again_button)
166
 
167
- if random.random() < 0.2:
168
  increase_luck_button = discord.ui.Button(style=discord.ButtonStyle.success, label="Increase Luck", custom_id="increase_luck")
169
 
170
  async def increase_luck_callback(interaction: discord.Interaction):
 
95
  user_id = interaction.user.id
96
  luck_multiplier = luck_multipliers.get(user_id, 1)
97
 
 
 
 
 
98
  # Calculate total difficulty
99
+ total_difficulty = sum(pet['configData']['difficulty'] for pet in pets)
100
 
101
  # Generate a random number between 0 and total_difficulty
102
  random_value = random.uniform(0, total_difficulty)
103
 
104
+ # Select a pet based on the random value and luck multiplier
105
  cumulative_probability = 0
106
+ for pet in sorted(pets, key=lambda x: x['configData']['difficulty'], reverse=True):
107
+ cumulative_probability += pet['configData']['difficulty'] * luck_multiplier
108
  if random_value <= cumulative_probability:
109
  rolled_pet = pet
110
  break
 
153
  if result:
154
  await interaction.followup.send(embed=result[0], view=result[1])
155
  else:
156
+ await interaction.followup.send("errer")
157
 
158
  roll_again_button.callback = roll_again_callback
159
 
160
  view = discord.ui.View()
161
  view.add_item(roll_again_button)
162
 
163
+ if random.random() < 0.2:
164
  increase_luck_button = discord.ui.Button(style=discord.ButtonStyle.success, label="Increase Luck", custom_id="increase_luck")
165
 
166
  async def increase_luck_callback(interaction: discord.Interaction):