Skip to content

Commit

Permalink
Fix some level grind issues (#646)
Browse files Browse the repository at this point in the history
* Fix level grind mode when lead cannot battle

* Fix an issue where we are trying to switch the leader while not needed
  • Loading branch information
ThibaultLassiaz authored Feb 3, 2025
1 parent 32271d1 commit c24e977
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
20 changes: 17 additions & 3 deletions modules/battle_strategies/level_up.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,23 @@ def party_can_battle(self) -> bool:
return False

def pokemon_can_battle(self, pokemon: Pokemon) -> bool:
return any(
move is not None and move.move.base_power > 0 and move.move.name not in context.config.battle.banned_moves
for move in pokemon.moves
return self._can_battle(pokemon)

def party_can_battle(self) -> bool:
return any(self._can_battle(pokemon) for pokemon in get_party().non_fainted_pokemon)

def _can_battle(self, pokemon: Pokemon) -> bool:
return (
pokemon is not None
and super()._pokemon_has_enough_hp(pokemon)
and pokemon.status_condition is StatusCondition.Healthy
and any(
move is not None
and move.move.base_power > 0
and move.pp > 0
and move.move.name not in context.config.battle.banned_moves
for move in pokemon.moves
)
)

def _escape(self, battle_state: BattleState):
Expand Down
3 changes: 2 additions & 1 deletion modules/modes/level_grind.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@ def run(self) -> Generator:
if level_mode_choice.startswith("Level-balance"):
self._controller.battle_strategy = LevelBalancingBattleStrategy
party_lead_index = LevelBalancingBattleStrategy().choose_new_lead_after_battle()
if party_lead_index != 0:
if party_lead_index != None:
yield from change_lead_party_pokemon(party_lead_index)
else:
self._controller.battle_strategy = LevelUpLeadBattleStrategy
self._controller._focus_on_lead_pokemon = True
assert_party_has_damaging_move("No Pokémon in the party has a usable attacking move!")

if not LevelUpLeadBattleStrategy().pokemon_can_battle(party_lead_pokemon):
Expand Down

0 comments on commit c24e977

Please sign in to comment.