Spaces:
Building
Building
Update app.py
Browse files
app.py
CHANGED
@@ -88,7 +88,20 @@ async def perform_roll(interaction: discord.Interaction):
|
|
88 |
if not pets:
|
89 |
return None
|
90 |
|
91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
pet_rap = next((pet for pet in rap_data['data'] if pet['configData']['id'] == rolled_pet['configName']), None)
|
93 |
|
94 |
if not pet_rap:
|
|
|
88 |
if not pets:
|
89 |
return None
|
90 |
|
91 |
+
# Calculate total difficulty
|
92 |
+
total_difficulty = sum(1 / pet['configData']['difficulty'] for pet in pets)
|
93 |
+
|
94 |
+
# Generate a random number between 0 and total_difficulty
|
95 |
+
random_value = random.uniform(0, total_difficulty)
|
96 |
+
|
97 |
+
# Select a pet based on the random value
|
98 |
+
cumulative_probability = 0
|
99 |
+
for pet in pets:
|
100 |
+
cumulative_probability += 1 / pet['configData']['difficulty']
|
101 |
+
if random_value <= cumulative_probability:
|
102 |
+
rolled_pet = pet
|
103 |
+
break
|
104 |
+
|
105 |
pet_rap = next((pet for pet in rap_data['data'] if pet['configData']['id'] == rolled_pet['configName']), None)
|
106 |
|
107 |
if not pet_rap:
|