diff --git a/configs/config.json.cluster.example b/configs/config.json.cluster.example index 5cbd8540d9..b71d1b34ff 100644 --- a/configs/config.json.cluster.example +++ b/configs/config.json.cluster.example @@ -154,6 +154,11 @@ "berry_threshold": 0.35, "vip_berry_threshold": 0.9, "daily_catch_limit": 800, + "vanish_settings": { + "consecutive_vanish_limit": 10, + "rest_duration_min": "02:00:00", + "rest_duration_max": "04:00:00" + }, "catch_throw_parameters": { "excellent_rate": 0.1, "great_rate": 0.5, diff --git a/configs/config.json.example b/configs/config.json.example index e05e9a67ad..95a998a938 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -192,6 +192,11 @@ "vip_berry_threshold": 0.9, "treat_unseen_as_vip": true, "daily_catch_limit": 800, + "vanish_settings": { + "consecutive_vanish_limit": 10, + "rest_duration_min": "02:00:00", + "rest_duration_max": "04:00:00" + }, "catch_throw_parameters": { "excellent_rate": 0.1, "great_rate": 0.5, diff --git a/configs/config.json.map.example b/configs/config.json.map.example index 935d509e13..1f54e4d870 100644 --- a/configs/config.json.map.example +++ b/configs/config.json.map.example @@ -154,6 +154,11 @@ "berry_threshold": 0.35, "vip_berry_threshold": 0.9, "daily_catch_limit": 800, + "vanish_settings": { + "consecutive_vanish_limit": 10, + "rest_duration_min": "02:00:00", + "rest_duration_max": "04:00:00" + }, "catch_throw_parameters": { "excellent_rate": 0.1, "great_rate": 0.5, diff --git a/configs/config.json.path.example b/configs/config.json.path.example index cd6c920520..4c3193a61f 100644 --- a/configs/config.json.path.example +++ b/configs/config.json.path.example @@ -155,6 +155,11 @@ "vip_berry_threshold": 0.9, "treat_unseen_as_vip": true, "daily_catch_limit": 800, + "vanish_settings": { + "consecutive_vanish_limit": 10, + "rest_duration_min": "02:00:00", + "rest_duration_max": "04:00:00" + }, "catch_throw_parameters": { "excellent_rate": 0.1, "great_rate": 0.5, diff --git a/configs/config.json.pokemon.example b/configs/config.json.pokemon.example index 8825aa0441..6edb29cccb 100644 --- a/configs/config.json.pokemon.example +++ b/configs/config.json.pokemon.example @@ -154,6 +154,11 @@ "vip_berry_threshold": 0.9, "treat_unseen_as_vip": true, "daily_catch_limit": 800, + "vanish_settings": { + "consecutive_vanish_limit": 10, + "rest_duration_min": "02:00:00", + "rest_duration_max": "04:00:00" + }, "catch_throw_parameters": { "excellent_rate": 0.1, "great_rate": 0.5, diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index 0b34daec7e..65de43807f 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -418,6 +418,13 @@ def _register_events(self): 'pokemon_id' ) ) + self.event_manager.register_event( + 'vanish_limit_reached', + parameters=( + 'duration', + 'resume' + ) + ) self.event_manager.register_event('pokemon_not_in_range') self.event_manager.register_event('pokemon_inventory_full') self.event_manager.register_event( @@ -619,6 +626,7 @@ def _register_events(self): ) # database shit self.event_manager.register_event('catch_log') + self.event_manager.register_event('vanish_log') self.event_manager.register_event('evolve_log') self.event_manager.register_event('login_log') self.event_manager.register_event('transfer_log') diff --git a/pokemongo_bot/cell_workers/migrations/vanish_log.py b/pokemongo_bot/cell_workers/migrations/vanish_log.py new file mode 100644 index 0000000000..6fb7d61fa4 --- /dev/null +++ b/pokemongo_bot/cell_workers/migrations/vanish_log.py @@ -0,0 +1,5 @@ +from yoyo import step + +step( + "CREATE TABLE IF NOT EXISTS vanish_log (pokemon text, cp real, iv real, encounter_id text, pokemon_id real, dated datetime DEFAULT CURRENT_TIMESTAMP)" +) diff --git a/pokemongo_bot/cell_workers/pokemon_catch_worker.py b/pokemongo_bot/cell_workers/pokemon_catch_worker.py index a22f3a2c1e..8775846cbc 100644 --- a/pokemongo_bot/cell_workers/pokemon_catch_worker.py +++ b/pokemongo_bot/cell_workers/pokemon_catch_worker.py @@ -7,7 +7,7 @@ import time import sys -from random import random, randrange +from random import random, randrange, uniform from pokemongo_bot import inventory from pokemongo_bot.base_task import BaseTask from pokemongo_bot.human_behaviour import sleep, action_delay @@ -16,6 +16,7 @@ from pokemongo_bot.datastore import Datastore from pokemongo_bot.base_dir import _base_dir from datetime import datetime, timedelta +from utils import getSeconds CATCH_STATUS_SUCCESS = 1 CATCH_STATUS_FAILED = 2 @@ -56,6 +57,7 @@ def initialize(self): self.spawn_point_guid = '' self.response_key = '' self.response_status_key = '' + self.rest_completed = False #Config self.min_ultraball_to_keep = self.config.get('min_ultraball_to_keep', 10) @@ -64,6 +66,11 @@ def initialize(self): self.treat_unseen_as_vip = self.config.get('treat_unseen_as_vip', DEFAULT_UNSEEN_AS_VIP) self.daily_catch_limit = self.config.get('daily_catch_limit', 800) + self.vanish_settings = self.config.get('vanish_settings', {}) + self.consecutive_vanish_limit = self.vanish_settings.get('consecutive_vanish_limit', 10) + self.rest_duration_min = getSeconds(self.vanish_settings.get('rest_duration_min', "02:00:00")) + self.rest_duration_max = getSeconds(self.vanish_settings.get('rest_duration_max', "04:00:00")) + self.catch_throw_parameters = self.config.get('catch_throw_parameters', {}) self.catch_throw_parameters_spin_success_rate = self.catch_throw_parameters.get('spin_success_rate', 0.6) self.catch_throw_parameters_excellent_rate = self.catch_throw_parameters.get('excellent_rate', 0.1) @@ -505,6 +512,25 @@ def _do_catch(self, pokemon, encounter_id, catch_rate_by_ball, is_vip=False): # abandon if pokemon vanished elif catch_pokemon_status == CATCH_STATUS_VANISHED: + #insert into DB + with self.bot.database as conn: + c = conn.cursor() + c.execute("SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='vanish_log'") + result = c.fetchone() + + while True: + if result[0] == 1: + conn.execute('''INSERT INTO vanish_log (pokemon, cp, iv, encounter_id, pokemon_id) VALUES (?, ?, ?, ?, ?)''', (pokemon.name, pokemon.cp, pokemon.iv, str(encounter_id), pokemon.pokemon_id)) + break + else: + self.emit_event( + 'vanish_log', + sender=self, + level='info', + formatted="vanish_log table not found, skipping log" + ) + break + self.emit_event( 'pokemon_vanished', formatted='{pokemon} vanished!', @@ -516,11 +542,24 @@ def _do_catch(self, pokemon, encounter_id, catch_rate_by_ball, is_vip=False): 'pokemon_id': pokemon.pokemon_id } ) + + with self.bot.database as conn: + c = conn.cursor() + c.execute("SELECT DISTINCT COUNT(encounter_id) FROM vanish_log WHERE dated > (SELECT dated FROM catch_log WHERE dated IN (SELECT MAX(dated) FROM catch_log))") + + result = c.fetchone() + self.consecutive_vanishes_so_far = result[0] + + if self.rest_completed == False and self.consecutive_vanishes_so_far >= self.consecutive_vanish_limit: + self.start_rest() + if self._pct(catch_rate_by_ball[current_ball]) == 100: self.bot.softban = True # pokemon caught! elif catch_pokemon_status == CATCH_STATUS_SUCCESS: + if self.rest_completed == True: + self.rest_completed = False pokemon.unique_id = response_dict['responses']['CATCH_POKEMON']['captured_pokemon_id'] self.bot.metrics.captured_pokemon(pokemon.name, pokemon.cp, pokemon.iv_display, pokemon.iv) @@ -663,3 +702,20 @@ def generate_throw_quality_parameters(self, throw_parameters): throw_parameters['normalized_reticle_size'] = 1.25 + 0.70 * random() throw_parameters['normalized_hit_position'] = 0.0 throw_parameters['throw_type_label'] = 'OK' + + def start_rest(self): + duration = int(uniform(self.rest_duration_min, self.rest_duration_max)) + resume = datetime.now() + timedelta(seconds=duration) + + self.emit_event( + 'vanish_limit_reached', + formatted="Vanish limit reached! Taking a rest now for {duration}, will resume at {resume}.", + data={ + 'duration': str(timedelta(seconds=duration)), + 'resume': resume.strftime("%H:%M:%S") + } + ) + + sleep(duration) + self.rest_completed = True + self.bot.login() diff --git a/pokemongo_bot/event_handlers/colored_logging_handler.py b/pokemongo_bot/event_handlers/colored_logging_handler.py index 7b499c0a3a..079329f9b2 100644 --- a/pokemongo_bot/event_handlers/colored_logging_handler.py +++ b/pokemongo_bot/event_handlers/colored_logging_handler.py @@ -71,6 +71,7 @@ class ColoredLoggingHandler(EventHandler): 'unset_pokemon_nickname': 'red', 'vip_pokemon': 'red', 'use_incense': 'blue', + 'vanish_limit_reached': 'red', 'arrived_at_cluster': 'none', 'arrived_at_fort': 'none',