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

Updated Catch Limiter #6128

Merged
merged 3 commits into from
Jul 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,8 @@
"never_place": ["Machamp"],
"leave_at_least_spots": 1,
"take_at_most": 10,
"pick_random_pokemon": true
"pick_random_pokemon": true,
"can_be_disabled_by_catch_limter": false
}
},
{
Expand Down
12 changes: 9 additions & 3 deletions pokemongo_bot/cell_workers/catch_limiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,21 @@ def __init__(self, bot, config):
self.min_balls = self.config.get("min_balls", 20)
self.resume_at_balls = self.config.get("resume_at_balls", 100)
self.duration = self.config.get("duration",15)
self.min_ultraball_to_keep = 0
for subVal in self.bot.config.raw_tasks:
if "type" in subVal:
if subVal["type"] == "CatchPokemon":
self.min_ultraball_to_keep = subVal["config"]["min_ultraball_to_keep"]

if not hasattr(self.bot, "catch_resume_at"): self.bot.catch_resume_at = None

def work(self):
if not self.enabled:
return WorkerResult.SUCCESS

now = datetime.now()
balls_on_hand = self.get_pokeball_count()

balls_on_hand = self.get_pokeball_count() - self.min_ultraball_to_keep
# If resume time has passed, resume catching tasks
if self.bot.catch_disabled and now >= self.bot.catch_resume_at:
if balls_on_hand > self.min_balls:
Expand All @@ -42,7 +48,7 @@ def work(self):
if self.bot.catch_disabled and balls_on_hand >= self.resume_at_balls:
self.emit_event(
'catch_limit_off',
formatted="Resume time hasn't passed yet, bu balls on hand ({}) exceeds threshold {}. Re-enabling catch tasks.".
formatted="Resume time hasn't passed yet, but balls on hand ({}) exceeds threshold {}. Re-enabling catch tasks.".
format(balls_on_hand, self.resume_at_balls)
)
self.bot.catch_disabled = False
Expand Down
18 changes: 18 additions & 0 deletions pokemongo_bot/cell_workers/gym_pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ def initialize(self):
self.never_place = self.config.get('never_place', [])

self.pick_random_pokemon = self.config.get('pick_random_pokemon', True)

self.can_be_disabled_by_catch_limter = self.config.get("can_be_disabled_by_catch_limter", False)

self.recheck = datetime.now()
self.walker = self.config.get('walker', 'StepWalker')
Expand Down Expand Up @@ -121,6 +123,22 @@ def display_fort_pokemon(self):
self.logger.info("%s (%s CP)" % (pokemon.name, pokemon.cp))

def work(self):
if not self.enabled:
return WorkerResult.SUCCESS

if self.bot.catch_disabled and self.can_be_disabled_by_catch_limter:
# When catching is disabled, drop the target.
if self.destination is not None:
self.destination = None

if not hasattr(self.bot, "gym_pokemon_disabled_global_warning") or \
(hasattr(self.bot, "gym_pokemon_disabled_global_warning") and not self.bot.gym_pokemon_disabled_global_warning):
self.logger.info("All gym tasks are currently disabled until {}. Gym function will resume when catching tasks are re-enabled".format(self.bot.catch_resume_at.strftime("%H:%M:%S")))
self.bot.gym_pokemon_disabled_global_warning = True
return WorkerResult.SUCCESS
else:
self.bot.gym_pokemon_disabled_global_warning = False

self.pokemons = inventory.pokemons().all()
self.fort_pokemons = [p for p in self.pokemons if p.in_fort]
self.pokemons = [p for p in self.pokemons if not p.in_fort]
Expand Down