Fix gym battle completion error handling
- Fixed tuple index out of range error in end_gym_battle() - Added proper row factory and named column access in database queries - Added exception handling and bounds checking in gym battle completion - Added debug logging to track gym battle state issues - Improved error messages for gym battle failures Fixes: "tuple index out of range" error when gym battles complete 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
710ff5ac9c
commit
6053161b6e
2 changed files with 28 additions and 11 deletions
|
|
@ -128,6 +128,7 @@ class BattleSystem(BaseModule):
|
|||
gym_battle = await self.database.get_active_gym_battle(player["id"])
|
||||
|
||||
if gym_battle:
|
||||
print(f"DEBUG: Gym battle completion - player: {player['id']}, result: {result.get('winner')}")
|
||||
await self.handle_gym_battle_completion(channel, nickname, player, result, gym_battle)
|
||||
else:
|
||||
# Regular wild battle
|
||||
|
|
@ -208,11 +209,18 @@ class BattleSystem(BaseModule):
|
|||
|
||||
async def handle_gym_battle_completion(self, channel, nickname, player, battle_result, gym_battle):
|
||||
"""Handle completion of a gym battle turn"""
|
||||
if battle_result["winner"] == "player":
|
||||
# Player won this individual battle
|
||||
current_pet_index = gym_battle["current_pet_index"]
|
||||
gym_team = gym_battle["gym_team"]
|
||||
defeated_pet = gym_team[current_pet_index]
|
||||
try:
|
||||
if battle_result["winner"] == "player":
|
||||
# Player won this individual battle
|
||||
current_pet_index = gym_battle["current_pet_index"]
|
||||
gym_team = gym_battle["gym_team"]
|
||||
|
||||
# Safety check for index bounds
|
||||
if current_pet_index >= len(gym_team):
|
||||
self.send_message(channel, f"❌ {nickname}: Gym battle state error - please !forfeit and try again")
|
||||
return
|
||||
|
||||
defeated_pet = gym_team[current_pet_index]
|
||||
|
||||
self.send_message(channel, f"🎉 {nickname}: You defeated {defeated_pet['species_name']}!")
|
||||
|
||||
|
|
@ -277,4 +285,10 @@ class BattleSystem(BaseModule):
|
|||
self.send_message(channel,
|
||||
f"{gym_battle['badge_icon']} {gym_battle['leader_name']}: \"Good battle! Train more and come back stronger!\"")
|
||||
self.send_message(channel,
|
||||
f"💡 {nickname}: Try leveling up your pets or bringing items to heal during battle!")
|
||||
f"💡 {nickname}: Try leveling up your pets or bringing items to heal during battle!")
|
||||
|
||||
except Exception as e:
|
||||
self.send_message(channel, f"❌ {nickname}: Gym battle error occurred - please !forfeit and try again")
|
||||
print(f"Gym battle completion error: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
Loading…
Add table
Add a link
Reference in a new issue