Skip to content

Commit

Permalink
Don't switch to manual mode when party is only one pokemon
Browse files Browse the repository at this point in the history
  • Loading branch information
ThibaultLassiaz committed Oct 3, 2024
1 parent 01080e5 commit f460a6f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 11 additions & 2 deletions modules/battle_strategies/catch.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@
from modules.items import Item, get_item_bag, get_item_by_name
from modules.map import get_map_data_for_current_position
from modules.pokedex import get_pokedex
from modules.pokemon import Pokemon, get_type_by_name, StatusCondition, get_party, get_party_alive
from modules.pokemon import (
Pokemon,
get_type_by_name,
StatusCondition,
get_party,
get_party_alive,
get_not_eggs_in_party,
)


class CatchStrategy(DefaultBattleStrategy):
Expand Down Expand Up @@ -132,7 +139,9 @@ def decide_turn(self, battle_state: BattleState) -> tuple["TurnAction", any]:
lead_pokemon_index = self._first_pokemon_sent_index
lead_pokemon = party[lead_pokemon_index]

if get_party_alive() == 1:
# If only one pokemon in party, we don't switch to manual
# Switching only if several available Pokemons but only one left alive
if get_party_alive() == 1 and get_not_eggs_in_party > 1:
return TurnAction.switch_to_manual()

if lead_pokemon.current_hp == 0:
Expand Down
4 changes: 4 additions & 0 deletions modules/pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -1364,6 +1364,10 @@ def get_eggs_in_party() -> int:
return sum(bool(pokemon.is_egg) for pokemon in get_party())


def get_not_eggs_in_party() -> int:
return sum(not pokemon.is_egg for pokemon in get_party())


def get_party() -> list[Pokemon]:
"""
Checks how many Pokémon are in the trainer's party, decodes and returns them all.
Expand Down

0 comments on commit f460a6f

Please sign in to comment.