Skip to content

Commit

Permalink
Update doc for catching revive modes
Browse files Browse the repository at this point in the history
  • Loading branch information
ThibaultLassiaz committed Oct 3, 2024
1 parent f460a6f commit 507f39a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 37 deletions.
54 changes: 21 additions & 33 deletions modules/battle_strategies/catch.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
get_not_eggs_in_party,
)


class CatchStrategy(DefaultBattleStrategy):
def __init__(self):
super().__init__()
Expand All @@ -29,17 +28,29 @@ def should_flee_after_faint(self, battle_state: BattleState) -> bool:
return False

def decide_turn(self, battle_state: BattleState) -> tuple["TurnAction", any]:
ball_to_throw = self._get_best_poke_ball(battle_state)
if ball_to_throw is None:
context.message = "Player does not have any Poké Balls, cannot catch."
"""Determines the next action depending on the mode and current battle state."""
party = get_party()
lead_pokemon_index = self._first_pokemon_sent_index
lead_pokemon = party[lead_pokemon_index]

# 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:
context.message = "Last pokemon alive, switching to manual mode."
return TurnAction.switch_to_manual()

if battle_state.opponent.active_battler.status_permanent == StatusCondition.Healthy:
status_move = self._get_best_status_changing_move(battle_state)
if status_move is not None:
return TurnAction.use_move(status_move)
if lead_pokemon.current_hp == 0:
match self._revive_mode:
case "always_revive_lead":
return self.revive_fainted_lead(lead_pokemon_index)

return TurnAction.use_item(ball_to_throw)
case "no_revive":
self.handle_catch_logic(battle_state)

case _:
# Unrecognized revive mode. Switching to manual mode.
return TurnAction.switch_to_manual()
return self.handle_catch_logic(battle_state)

def decide_turn_in_double_battle(self, battle_state: BattleState, battler_index: int) -> tuple["TurnAction", any]:
return self.decide_turn(battle_state)
Expand Down Expand Up @@ -133,30 +144,6 @@ def choose_new_lead_after_faint(self, battle_state: BattleState) -> int:
if not pokemon.is_egg and pokemon.current_hp > 0: # Ignore eggs and fainted Pokémon
return index

def decide_turn(self, battle_state: BattleState) -> tuple["TurnAction", any]:
"""Determines the next action depending on the mode and current battle state."""
party = get_party()
lead_pokemon_index = self._first_pokemon_sent_index
lead_pokemon = party[lead_pokemon_index]

# 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:
match self._revive_mode:
case "always_revive_lead":
return self.revive_fainted_lead(lead_pokemon_index)

case "no_revive":
self.handle_catch_logic(battle_state)

case _:
# Unrecognized revive mode. Switching to manual mode.
return TurnAction.switch_to_manual()
return self.handle_catch_logic(battle_state)

def get_first_valid_pokemon_index(self) -> int | None:
"""Returns the index of the first valid Pokémon that is not an egg."""
party = get_party()
Expand Down Expand Up @@ -203,6 +190,7 @@ def revive_fainted_lead(self, fainted_lead):
elif revive_count > 0:
return TurnAction.use_item_on(get_item_by_name("Revive"), fainted_lead)

context.message = "Player doesn't have any revive items left."
return TurnAction.switch_to_manual()

def handle_catch_logic(self, battle_state: BattleState):
Expand Down
4 changes: 2 additions & 2 deletions modules/config/schemas_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ class Battle(BaseConfig):

filename: ClassVar = "battle.yml"
auto_catch: bool = True
catch_revive_mode: Literal["always_revive_lead", "no_revive"] = "always_revive_lead"
revive_item: Literal["revive", "max_revive", "both"] = "revive"
save_after_catching: bool = False
pickup: bool = True
pickup_threshold: Annotated[int, Field(gt=0, lt=7)] = 1
pickup_check_frequency: Annotated[int, Field(gt=0)] = 5
hp_threshold: Annotated[float, Field(ge=0, le=100)] = 20
lead_cannot_battle_action: Literal["stop", "flee", "rotate"] = "flee"
faint_action: Literal["stop", "flee", "rotate"] = "flee"
catch_revive_mode: Literal["always_revive_lead", "no_revive"] = "always_revive_lead"
revive_item: Literal["revive", "max_revive", "both"] = "both"
new_move: Literal["stop", "cancel", "learn_best"] = "stop"
stop_evolution: bool = True
switch_strategy: Literal["first_available", "lowest_level"] = "first_available"
Expand Down
4 changes: 2 additions & 2 deletions modules/config/templates/battle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

# Auto Catching
auto_catch: true
catch_revive_mode: always_revive_lead # `always_revive_lead`, `no_revive`
revive_item: both # `revive`, `max_revive`, `both`

# Whether to create an in-game save after catching a Pokémon
save_after_catching: false
Expand All @@ -15,8 +17,6 @@ pickup_check_frequency: 5
hp_threshold: 20
lead_cannot_battle_action: flee # `stop`, `flee`, `rotate`
faint_action: flee # `stop`, `flee`, `rotate`
catch_revive_mode: always_revive_lead # `always_revive_lead`, `no_revive`
revive_item: both # `revive`, `max_revive`, `both`
new_move: stop # `stop`, `cancel`, `learn_best`
stop_evolution: true
switch_strategy: first_available # `first_available`, `lowest_level`
Expand Down
16 changes: 16 additions & 0 deletions wiki/pages/Configuration - Battling and Pickup.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@ The bot can automatically battle Pokémon that don't meet any catch criteria.

`auto_catch` - enable automatic catching of encounters-of-interest (shinies and those that match your custom catch filters.)

`catch_revive_mode` - What to do if the lead Pokémon fainted during trying to attempt to catch the Pokémon

- `always_revive_lead` - send the next available Pokémon, revive the lead Pokémon and try to catch it.
If it faints, the leader will be sent again.
_Switch to manual mode if there's only one Pokémon available in your party_

- `no_revive` - will send every Pokémon available one by one and try to catch
_Switch to manual mode if there's only one Pokémon available left in your party_

`revive_item` - The item the bot should use to revive your leader.
_Switch to manual mode when no revive items remain available._

- `max_revive` - use max revive to revive the lead Pokémon
- `revive` - use revive to revive the lead Pokémon
- `both` - will use max revive if available, otherwise use revive

If your lead Pokémon knows False Swipe, the bot may use that. It will also try to use sleep-inducing or paralysing moves
where it makes sense.

Expand Down

0 comments on commit 507f39a

Please sign in to comment.