Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent catching modes from starting when no Pokeballs available #497

Merged
merged 2 commits into from
Nov 11, 2024

Conversation

ThibaultLassiaz
Copy link
Contributor

@ThibaultLassiaz ThibaultLassiaz commented Nov 10, 2024

Description

Fixed an issue where you could start shiny hunting modes without any Poké Balls... because who doesn’t love spotting a shiny you can’t catch ?

I updated these modes so the bot doesn't start if you don't have any Pokéballs or stop if you're out of Pokéballs at the end of an encounter (i.e you captured a Shiny and you're out of Pokéballs)

The Master Ball isn't counted as a valid Pokéball, it will never be used

Changes

  • Update every "catching" modes run function to stop if you have no Pokéballs
  • Update some modes on_battle_ended functions to stop after catching a Shiny and running out of Pokéballs
  • Added an util property function to item bag to check your Pokéball counter

Notes

I tested all the modes manually to check for bugs who would prevent the mode to start and it seems fine

Checklist

  • Black Linter has been ran, using --line-length 120 argument
  • Wiki has been updated (if relevant)

Copy link
Collaborator

@hanzi hanzi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In principle I'm happy with this, buuut...

This adds a whole lot of identical code blocks, which screams to just be its own utility function.

For these sort of cases we already have a few functions in modules/modes/_asserts.py, so perhaps we could just add assert_player_has_poke_balls() function that does the check? It could even include the Safari Zone check, I suppose. Even if that might not be necessary for every mode.

That way, there's only one place to modify if we decide to change thresholds etc.

And less of a risk of someone changing some but not all instances of this check...

@hanzi
Copy link
Collaborator

hanzi commented Nov 11, 2024

Oh, also: You can just use raise BotModeError("No balls :(") instead of manually setting context.message followed by a context.set_manual_mode(). This has the same effect (BotModeError is caught in modules/main.py)

@hanzi hanzi merged commit 2320700 into 40Cakes:main Nov 11, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants