From 5c95239186aec0085063fd3e339f6a7ad236d1cf Mon Sep 17 00:00:00 2001 From: mhdasding Date: Sun, 31 Jul 2016 06:04:28 +0200 Subject: [PATCH 01/48] Feature: Use PokemonGo-Map sqlite db to catch pokemon near you --- CONTRIBUTORS.md | 1 + pokecli.py | 43 +++++- pokemongo_bot/cell_workers/__init__.py | 1 + .../cell_workers/move_to_map_pokemon.py | 129 ++++++++++++++++++ 4 files changed, 173 insertions(+), 1 deletion(-) create mode 100644 pokemongo_bot/cell_workers/move_to_map_pokemon.py diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index d23ba72805..be6bc75ec1 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -43,3 +43,4 @@ * klingan * reddivision * kbinani + * mhdasding \ No newline at end of file diff --git a/pokecli.py b/pokecli.py index 9dc635aabb..81c932f273 100755 --- a/pokecli.py +++ b/pokecli.py @@ -388,6 +388,46 @@ def init_config(): type=float, default=1.0 ) + add_config( + parser, + load, + long_flag="--map.db_file", + help="PokemonGo-Map db file", + type=str, + default=None + ) + add_config( + parser, + load, + long_flag="--map.max_distance", + help="Max distance to move for a pokemon in meters", + type=int, + default=100 + ) + add_config( + parser, + load, + long_flag="--map.min_time", + help="Min time for the monster until despawn in seconds", + type=int, + default=30 + ) + add_config( + parser, + load, + long_flag="--map.prioritize_vips", + help="Catch VIP Pokemon from the map first", + type=bool, + default=True + ) + add_config( + parser, + load, + long_flag="--map.mode", + help="Score pokemon either by distance or priority", + type=str, + default="distance" + ) # Start to parse other attrs config = parser.parse_args() @@ -406,7 +446,8 @@ def init_config(): config.longer_eggs_first = load.get("longer_eggs_first", True) - config.vips = load.get('vips',{}) + config.vips = load.get('vips', {}) + config.map_priority = load.get('map', {}).get('priority', {}) if len(config.raw_tasks) == 0: logging.error("No tasks are configured. Did you mean to configure some behaviors? Read https://github.com/PokemonGoF/PokemonGo-Bot/wiki/Configuration-files#configuring-tasks for more information") diff --git a/pokemongo_bot/cell_workers/__init__.py b/pokemongo_bot/cell_workers/__init__.py index 8a700ef5ba..6e62b97b1d 100644 --- a/pokemongo_bot/cell_workers/__init__.py +++ b/pokemongo_bot/cell_workers/__init__.py @@ -5,6 +5,7 @@ from evolve_all import EvolveAll from incubate_eggs import IncubateEggs from move_to_fort import MoveToFort +from move_to_map_pokemon import MoveToMapPokemon from pokemon_catch_worker import PokemonCatchWorker from transfer_pokemon import TransferPokemon from recycle_items import RecycleItems diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py new file mode 100644 index 0000000000..9d4cc22b94 --- /dev/null +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -0,0 +1,129 @@ +# -*- coding: utf-8 -*- + +import json +import time +import sqlite3 +from pokemongo_bot import logger +from pokemongo_bot.cell_workers.utils import distance, i2f, format_dist +from pokemongo_bot.human_behaviour import sleep +from pokemongo_bot.step_walker import StepWalker +from pokemongo_bot.worker_result import WorkerResult + + +class MoveToMapPokemon(object): + + def __init__(self, bot): + self.bot = bot + self.ptr = 0 + self.db = self.load_db() + self.pokemon_data = bot.pokemon_list + self.caught = [] + + def load_db(self): + if self.bot.config.map_db_file == None: + raise RuntimeError('You need to specify a db file (sqlite)') + + try: + conn = sqlite3.connect(self.bot.config.map_db_file) + except: + raise RuntimeError('Could not open db file "{}"'.format(self.bot.config.map.db_file)) + return conn + + def get_pokemon_from_map(self): + cursor = self.db.cursor() + + pokemon_list = [] + + now = int(time.time() + self.bot.config.map_min_time) + for row in cursor.execute('SELECT * FROM pokemon WHERE datetime(disappear_time) > datetime(?, "unixepoch");', (now, )): + encounter_id = row[1] + pokemon_id = row[2] + lat = row[3] + lon = row[4] + + dist = distance( + self.bot.position[0], + self.bot.position[1], + lat, + lon + ) + + if dist > self.bot.config.map_max_distance: + continue + + if encounter_id in self.caught: + continue + + pokemon_list.append({ + 'encounter_id': encounter_id, + 'pokemon_id': pokemon_id, + 'lat': lat, + 'lon': lon, + 'dist': dist + }) + + cursor.close() + return pokemon_list + + def get_name_from_id(self, pokemon_id): + return self.pokemon_data[pokemon_id - 1]['Name'] + + def is_in_vip(self, pokemon_id): + return self.get_name_from_id(pokemon_id) in self.bot.config.vips + + def get_config_priority(self, pokemon_id): + if (self.get_name_from_id(pokemon_id) in self.bot.config.map_priority): + return self.bot.config.map_priority[self.get_name_from_id(pokemon_id)] + else: + return 0 + + def addCaught(self, pokemon): + if len(self.caught) >= 200: + self.caught.pop(0) + self.caught.append(pokemon['encounter_id']) + + def score_pokemon(self, pokemon_list): + new_list = [] + for pokemon in pokemon_list: + score = 0 + if self.bot.config.map_prioritize_vips and self.is_in_vip(pokemon['pokemon_id']): + score += 1000 + if self.bot.config.map_mode == 'distance': + score -= pokemon['dist'] + elif self.bot.config.map_mode == 'priority': + score += self.get_config_priority(pokemon['pokemon_id']) + + pokemon['name'] = self.get_name_from_id(pokemon['pokemon_id']) + pokemon['score'] = score + + if self.bot.config.map_mode == 'priority' and pokemon['score'] < 1: + continue + new_list.append(pokemon) + return new_list + + def work(self): + unit = self.bot.config.distance_unit + pokemon_on_map = self.get_pokemon_from_map() + pokemon_on_map = self.score_pokemon(pokemon_on_map) + pokemon_on_map.sort(key=lambda x: x['score'], reverse=True) + + if (len(pokemon_on_map) < 1): + return + + pokemon = pokemon_on_map[0] + logger.log('Moving towards {}, {} left'.format(pokemon['name'], format_dist(pokemon['dist'], unit))) + + step_walker = StepWalker( + self.bot, + self.bot.config.walk, + pokemon['lat'], + pokemon['lon'] + ) + + if not step_walker.step(): + return WorkerResult.RUNNING + + logger.log('Arrived at {}'.format(pokemon['name'])) + self.addCaught(pokemon) + + return WorkerResult.SUCCESS \ No newline at end of file From b74b8fee62a3ddb12aa7067676e2282446012ccc Mon Sep 17 00:00:00 2001 From: mhdasding Date: Sun, 31 Jul 2016 06:06:43 +0200 Subject: [PATCH 02/48] added example config for move_to_map_pokemon --- configs/config.json.example | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/configs/config.json.example b/configs/config.json.example index 94817b4ec5..cbc12724e7 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -29,6 +29,9 @@ { "type": "SpinFort" }, + { + "type": "MoveToMapPokemon" + }, { "type": "MoveToFort" }, @@ -43,6 +46,18 @@ "avoid_circles": true, "max_circle_size": 50 }, + "map": { + "db_file": "../PokemonGo-Map/pogom.db", + "max_distance": 300, + "min_time": 60, + "prioritize_vips": true, + "mode": "distance", + "priority": { + "Bulbasaur": 1, + "Squirtle": 3, + "Mewtwo": 100 + } + }, "websocket_server": false, "walk": 4.16, "action_wait_min": 1, From e56dc287095477510643bbc2bc132eb3b048862f Mon Sep 17 00:00:00 2001 From: mhdasding Date: Sun, 31 Jul 2016 06:40:33 +0200 Subject: [PATCH 03/48] adapted new config format --- pokecli.py | 41 ------------------- .../cell_workers/move_to_map_pokemon.py | 25 +++++------ 2 files changed, 13 insertions(+), 53 deletions(-) diff --git a/pokecli.py b/pokecli.py index a23c8c90df..6a5add3514 100755 --- a/pokecli.py +++ b/pokecli.py @@ -361,46 +361,6 @@ def init_config(): type=float, default=1.0 ) - add_config( - parser, - load, - long_flag="--map.db_file", - help="PokemonGo-Map db file", - type=str, - default=None - ) - add_config( - parser, - load, - long_flag="--map.max_distance", - help="Max distance to move for a pokemon in meters", - type=int, - default=100 - ) - add_config( - parser, - load, - long_flag="--map.min_time", - help="Min time for the monster until despawn in seconds", - type=int, - default=30 - ) - add_config( - parser, - load, - long_flag="--map.prioritize_vips", - help="Catch VIP Pokemon from the map first", - type=bool, - default=True - ) - add_config( - parser, - load, - long_flag="--map.mode", - help="Score pokemon either by distance or priority", - type=str, - default="distance" - ) # Start to parse other attrs config = parser.parse_args() @@ -418,7 +378,6 @@ def init_config(): config.raw_tasks = load.get('tasks', []) config.vips = load.get('vips', {}) - config.map_priority = load.get('map', {}).get('priority', {}) if len(config.raw_tasks) == 0: logging.error("No tasks are configured. Did you mean to configure some behaviors? Read https://github.com/PokemonGoF/PokemonGo-Bot/wiki/Configuration-files#configuring-tasks for more information") diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py index 9d4cc22b94..fab4ae7a01 100644 --- a/pokemongo_bot/cell_workers/move_to_map_pokemon.py +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -12,21 +12,22 @@ class MoveToMapPokemon(object): - def __init__(self, bot): + def __init__(self, bot, config): self.bot = bot + self.config = config self.ptr = 0 self.db = self.load_db() self.pokemon_data = bot.pokemon_list self.caught = [] def load_db(self): - if self.bot.config.map_db_file == None: + if self.config['db_file'] == None: raise RuntimeError('You need to specify a db file (sqlite)') try: - conn = sqlite3.connect(self.bot.config.map_db_file) + conn = sqlite3.connect(self.config['db_file']) except: - raise RuntimeError('Could not open db file "{}"'.format(self.bot.config.map.db_file)) + raise RuntimeError('Could not open db file "{}"'.format(self.config['db_file'])) return conn def get_pokemon_from_map(self): @@ -34,7 +35,7 @@ def get_pokemon_from_map(self): pokemon_list = [] - now = int(time.time() + self.bot.config.map_min_time) + now = int(time.time() + self.config['min_time']) for row in cursor.execute('SELECT * FROM pokemon WHERE datetime(disappear_time) > datetime(?, "unixepoch");', (now, )): encounter_id = row[1] pokemon_id = row[2] @@ -48,7 +49,7 @@ def get_pokemon_from_map(self): lon ) - if dist > self.bot.config.map_max_distance: + if dist > self.config['max_distance']: continue if encounter_id in self.caught: @@ -72,8 +73,8 @@ def is_in_vip(self, pokemon_id): return self.get_name_from_id(pokemon_id) in self.bot.config.vips def get_config_priority(self, pokemon_id): - if (self.get_name_from_id(pokemon_id) in self.bot.config.map_priority): - return self.bot.config.map_priority[self.get_name_from_id(pokemon_id)] + if (self.get_name_from_id(pokemon_id) in self.config['priority']): + return self.config['priority'][self.get_name_from_id(pokemon_id)] else: return 0 @@ -86,17 +87,17 @@ def score_pokemon(self, pokemon_list): new_list = [] for pokemon in pokemon_list: score = 0 - if self.bot.config.map_prioritize_vips and self.is_in_vip(pokemon['pokemon_id']): + if self.config['prioritize_vips'] and self.is_in_vip(pokemon['pokemon_id']): score += 1000 - if self.bot.config.map_mode == 'distance': + if self.config['mode'] == 'distance': score -= pokemon['dist'] - elif self.bot.config.map_mode == 'priority': + elif self.config['mode'] == 'priority': score += self.get_config_priority(pokemon['pokemon_id']) pokemon['name'] = self.get_name_from_id(pokemon['pokemon_id']) pokemon['score'] = score - if self.bot.config.map_mode == 'priority' and pokemon['score'] < 1: + if self.config['mode'] == 'priority' and pokemon['score'] < 1: continue new_list.append(pokemon) return new_list From 9e8b470b357eb69ff44d4be1ba4b6629e599d9f5 Mon Sep 17 00:00:00 2001 From: mhdasding Date: Sun, 31 Jul 2016 07:15:06 +0200 Subject: [PATCH 04/48] Automatically update Map position --- configs/config.json.example | 1 + .../cell_workers/move_to_map_pokemon.py | 25 ++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/configs/config.json.example b/configs/config.json.example index bb2b3cb4ff..50f4b526ba 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -49,6 +49,7 @@ }, "map": { "db_file": "../PokemonGo-Map/pogom.db", + "address": "http://localhost:5000", "max_distance": 300, "min_time": 60, "prioritize_vips": true, diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py index fab4ae7a01..a987e5a144 100644 --- a/pokemongo_bot/cell_workers/move_to_map_pokemon.py +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -3,6 +3,7 @@ import json import time import sqlite3 +import requests from pokemongo_bot import logger from pokemongo_bot.cell_workers.utils import distance, i2f, format_dist from pokemongo_bot.human_behaviour import sleep @@ -15,7 +16,7 @@ class MoveToMapPokemon(object): def __init__(self, bot, config): self.bot = bot self.config = config - self.ptr = 0 + self.last_map_update = 0 self.db = self.load_db() self.pokemon_data = bot.pokemon_list self.caught = [] @@ -102,7 +103,29 @@ def score_pokemon(self, pokemon_list): new_list.append(pokemon) return new_list + def update_map_location(self): + r = requests.get('{}/loc'.format(self.config['address'])) + if r.status_code != 200: + logger.log('Could not reach PokemonGo-Map Server', color='red') + return + j = r.json() + + dist = distance( + self.bot.position[0], + self.bot.position[1], + j['lat'], + j['lng'] + ) + + # update map when 500m away from center and last update longer than 2 minutes away + now = int(time.time()) + if dist > 500 and now - self.last_map_update > 2 * 60: + requests.post('{}/next_loc?lat={}&lon={}'.format(self.config['address'], self.bot.position[0], self.bot.position[1])) + logger.log('Updated PokemonGo-Map position') + self.last_map_update = now + def work(self): + self.update_map_location() unit = self.bot.config.distance_unit pokemon_on_map = self.get_pokemon_from_map() pokemon_on_map = self.score_pokemon(pokemon_on_map) From 4bb8379b645778310cc3a838ed9ff3550ea1eed6 Mon Sep 17 00:00:00 2001 From: mhdasding Date: Sun, 31 Jul 2016 07:56:06 +0200 Subject: [PATCH 05/48] remove pokemon when encountered early --- pokemongo_bot/__init__.py | 1 + pokemongo_bot/cell_workers/catch_visible_pokemon.py | 3 ++- pokemongo_bot/cell_workers/move_to_map_pokemon.py | 9 ++++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index a8816141f2..5097b23c65 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -45,6 +45,7 @@ def __init__(self, config): self.tick_count = 0 self.softban = False self.start_position = None + self.passon = {} # Make our own copy of the workers for this instance self.workers = [] diff --git a/pokemongo_bot/cell_workers/catch_visible_pokemon.py b/pokemongo_bot/cell_workers/catch_visible_pokemon.py index 1551ff57bf..17288cfbc3 100644 --- a/pokemongo_bot/cell_workers/catch_visible_pokemon.py +++ b/pokemongo_bot/cell_workers/catch_visible_pokemon.py @@ -22,7 +22,7 @@ def work(self): for pokemon in self.bot.cell['catchable_pokemons']: with open(user_web_catchable, 'w') as outfile: json.dump(pokemon, outfile) - + self.bot.passon['catched_pokemon'] = self.bot.cell['catchable_pokemons'][0] return self.catch_pokemon(self.bot.cell['catchable_pokemons'][0]) if 'wild_pokemons' in self.bot.cell and len(self.bot.cell['wild_pokemons']) > 0: @@ -31,6 +31,7 @@ def work(self): self.bot.cell['wild_pokemons'].sort( key= lambda x: distance(self.bot.position[0], self.bot.position[1], x['latitude'], x['longitude'])) + self.bot.passon['catched_pokemon'] = self.bot.cell['wild_pokemons'][0] return self.catch_pokemon(self.bot.cell['wild_pokemons'][0]) def catch_pokemon(self, pokemon): diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py index a987e5a144..813df31258 100644 --- a/pokemongo_bot/cell_workers/move_to_map_pokemon.py +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -4,6 +4,7 @@ import time import sqlite3 import requests +import base64 from pokemongo_bot import logger from pokemongo_bot.cell_workers.utils import distance, i2f, format_dist from pokemongo_bot.human_behaviour import sleep @@ -38,7 +39,7 @@ def get_pokemon_from_map(self): now = int(time.time() + self.config['min_time']) for row in cursor.execute('SELECT * FROM pokemon WHERE datetime(disappear_time) > datetime(?, "unixepoch");', (now, )): - encounter_id = row[1] + encounter_id = long(base64.b64decode(row[0])) pokemon_id = row[2] lat = row[3] lon = row[4] @@ -82,6 +83,7 @@ def get_config_priority(self, pokemon_id): def addCaught(self, pokemon): if len(self.caught) >= 200: self.caught.pop(0) + logger.log('e_id: {}'.format(pokemon['encounter_id'])) self.caught.append(pokemon['encounter_id']) def score_pokemon(self, pokemon_list): @@ -127,6 +129,11 @@ def update_map_location(self): def work(self): self.update_map_location() unit = self.bot.config.distance_unit + + if 'catched_pokemon' in self.bot.passon: + self.addCaught(self.bot.passon['catched_pokemon']) + del self.bot.passon['catched_pokemon'] + return WorkerResult.SUCCESS pokemon_on_map = self.get_pokemon_from_map() pokemon_on_map = self.score_pokemon(pokemon_on_map) pokemon_on_map.sort(key=lambda x: x['score'], reverse=True) From 4feabeb5429d9100b262d3b00115483b74af9800 Mon Sep 17 00:00:00 2001 From: mhdasding Date: Sun, 31 Jul 2016 07:57:16 +0200 Subject: [PATCH 06/48] forgot to remove a log --- pokemongo_bot/cell_workers/move_to_map_pokemon.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py index 813df31258..a91bffbf25 100644 --- a/pokemongo_bot/cell_workers/move_to_map_pokemon.py +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -83,7 +83,6 @@ def get_config_priority(self, pokemon_id): def addCaught(self, pokemon): if len(self.caught) >= 200: self.caught.pop(0) - logger.log('e_id: {}'.format(pokemon['encounter_id'])) self.caught.append(pokemon['encounter_id']) def score_pokemon(self, pokemon_list): From c1886310480fbe381c31f3a182e3c01cbdfea5e3 Mon Sep 17 00:00:00 2001 From: mhdasding Date: Sun, 31 Jul 2016 08:00:34 +0200 Subject: [PATCH 07/48] minor fix --- pokemongo_bot/cell_workers/move_to_fort.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pokemongo_bot/cell_workers/move_to_fort.py b/pokemongo_bot/cell_workers/move_to_fort.py index 6c546fce7f..124292de4a 100644 --- a/pokemongo_bot/cell_workers/move_to_fort.py +++ b/pokemongo_bot/cell_workers/move_to_fort.py @@ -7,7 +7,7 @@ class MoveToFort(object): - def __init__(self, bot, config): + def __init__(self, bot, config=None): self.bot = bot def should_run(self): From 86910ba9af57b0b480d921ddb415783ec037c4be Mon Sep 17 00:00:00 2001 From: mhdasding Date: Sun, 31 Jul 2016 08:15:49 +0200 Subject: [PATCH 08/48] updated example config and added ignore config --- configs/config.json.example | 31 ++++++++++--------- .../cell_workers/move_to_map_pokemon.py | 4 +++ 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/configs/config.json.example b/configs/config.json.example index 82b3eb5962..2a2096b270 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -36,7 +36,23 @@ "type": "SpinFort" }, { - "type": "MoveToMapPokemon" + "type": "MoveToMapPokemon", + "config": { + "db_file": "../PokemonGo-Map/pogom.db", + "address": "http://localhost:5000", + "max_distance": 500, + "min_time": 60, + "prioritize_vips": true, + "mode": "distance", + "priority": { + "Bulbasaur": 1, + "Squirtle": 3, + "Mewtwo": 100 + }, + "ignore": { + "Drowzee" + } + } }, { "type": "MoveToFort" @@ -50,19 +66,6 @@ "avoid_circles": true, "max_circle_size": 50 }, - "map": { - "db_file": "../PokemonGo-Map/pogom.db", - "address": "http://localhost:5000", - "max_distance": 300, - "min_time": 60, - "prioritize_vips": true, - "mode": "distance", - "priority": { - "Bulbasaur": 1, - "Squirtle": 3, - "Mewtwo": 100 - } - }, "websocket_server": false, "walk": 4.16, "action_wait_min": 1, diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py index a91bffbf25..f2036cf7d6 100644 --- a/pokemongo_bot/cell_workers/move_to_map_pokemon.py +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -101,6 +101,10 @@ def score_pokemon(self, pokemon_list): if self.config['mode'] == 'priority' and pokemon['score'] < 1: continue + + if pokemon['name'] in self.config['ignore']: + continue + new_list.append(pokemon) return new_list From 761ad02bb0d7f4dcc3e2d66a0cc8a0263a307020 Mon Sep 17 00:00:00 2001 From: mhdasding Date: Sun, 31 Jul 2016 08:18:19 +0200 Subject: [PATCH 09/48] change ignore config to a list --- configs/config.json.example | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/configs/config.json.example b/configs/config.json.example index 2a2096b270..9eb7054f20 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -49,9 +49,10 @@ "Squirtle": 3, "Mewtwo": 100 }, - "ignore": { - "Drowzee" - } + "ignore": [ + "Drowzee", + "Jynx" + ] } }, { From 507261293cc70c6fd64a45f91a2b0ea31934dd09 Mon Sep 17 00:00:00 2001 From: mhdasding Date: Sun, 31 Jul 2016 16:12:32 +0200 Subject: [PATCH 10/48] teleport to pokemon if walk option is 0 --- .../cell_workers/move_to_map_pokemon.py | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py index f2036cf7d6..36a3ceabd4 100644 --- a/pokemongo_bot/cell_workers/move_to_map_pokemon.py +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -95,6 +95,9 @@ def score_pokemon(self, pokemon_list): score -= pokemon['dist'] elif self.config['mode'] == 'priority': score += self.get_config_priority(pokemon['pokemon_id']) + elif self.config['mode'] == 'hybrid': + score += self.get_config_priority(pokemon['pokemon_id']) + score -= pokemon['dist'] pokemon['name'] = self.get_name_from_id(pokemon['pokemon_id']) pokemon['score'] = score @@ -145,14 +148,19 @@ def work(self): return pokemon = pokemon_on_map[0] + now = int(time.time()) logger.log('Moving towards {}, {} left'.format(pokemon['name'], format_dist(pokemon['dist'], unit))) - step_walker = StepWalker( - self.bot, - self.bot.config.walk, - pokemon['lat'], - pokemon['lon'] - ) + + if self.bot.config.walk > 0: + step_walker = StepWalker( + self.bot, + self.bot.config.walk, + pokemon['lat'], + pokemon['lon'] + ) + else: + self.bot.api.set_position(pokemon['lat'], pokemon['lon']) if not step_walker.step(): return WorkerResult.RUNNING From 68e6e5b70628dfa93a09cff14f1b01e686e18762 Mon Sep 17 00:00:00 2001 From: mhdasding Date: Sun, 31 Jul 2016 16:15:00 +0200 Subject: [PATCH 11/48] added snipe option --- configs/config.json.example | 1 + pokemongo_bot/cell_workers/move_to_map_pokemon.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/configs/config.json.example b/configs/config.json.example index 9eb7054f20..d8311dbc65 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -43,6 +43,7 @@ "max_distance": 500, "min_time": 60, "prioritize_vips": true, + "snipe": false, "mode": "distance", "priority": { "Bulbasaur": 1, diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py index 36a3ceabd4..172732149c 100644 --- a/pokemongo_bot/cell_workers/move_to_map_pokemon.py +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -152,7 +152,7 @@ def work(self): logger.log('Moving towards {}, {} left'.format(pokemon['name'], format_dist(pokemon['dist'], unit))) - if self.bot.config.walk > 0: + if self.bot.config.walk > 0 and not self.config['snipe']: step_walker = StepWalker( self.bot, self.bot.config.walk, From 6620bae9e22307f6da9c263e3095a8bb5a88a59d Mon Sep 17 00:00:00 2001 From: mhdasding Date: Sun, 31 Jul 2016 16:42:24 +0200 Subject: [PATCH 12/48] Teleport back after sniped pokemon was caught --- .../cell_workers/move_to_map_pokemon.py | 38 +++++++++++++------ 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py index 172732149c..898ddefa83 100644 --- a/pokemongo_bot/cell_workers/move_to_map_pokemon.py +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -21,6 +21,9 @@ def __init__(self, bot, config): self.db = self.load_db() self.pokemon_data = bot.pokemon_list self.caught = [] + self.last_position = None + self.sniped_last_tick = False + self.sniped_pokemon = None def load_db(self): if self.config['db_file'] == None: @@ -140,6 +143,16 @@ def work(self): self.addCaught(self.bot.passon['catched_pokemon']) del self.bot.passon['catched_pokemon'] return WorkerResult.SUCCESS + + # teleport back if sniped + if self.sniped_last_tick: + logger.log('Teleport back') + self.bot.api.set_position(self.last_position[0], self.last_position[1], 0) + self.addCaught(self.sniped_pokemon) + self.sniped_last_tick = False + return WorkerResult.SUCCESS + + pokemon_on_map = self.get_pokemon_from_map() pokemon_on_map = self.score_pokemon(pokemon_on_map) pokemon_on_map.sort(key=lambda x: x['score'], reverse=True) @@ -149,23 +162,26 @@ def work(self): pokemon = pokemon_on_map[0] now = int(time.time()) - logger.log('Moving towards {}, {} left'.format(pokemon['name'], format_dist(pokemon['dist'], unit))) + if self.bot.config.walk <= 0 or self.config['snipe']: + logger.log('Teleporting to {} ({})'.format(pokemon['name'], format_dist(pokemon['dist'], unit))) + self.bot.api.set_position(pokemon['lat'], pokemon['lon'], 0) + self.last_position = self.bot.position[0:2] + self.sniped_last_tick = True + self.sniped_pokemon = pokemon + return WorkerResult.RUNNING - if self.bot.config.walk > 0 and not self.config['snipe']: - step_walker = StepWalker( - self.bot, - self.bot.config.walk, - pokemon['lat'], - pokemon['lon'] - ) - else: - self.bot.api.set_position(pokemon['lat'], pokemon['lon']) + logger.log('Moving towards {}, {} left'.format(pokemon['name'], format_dist(pokemon['dist'], unit))) + step_walker = StepWalker( + self.bot, + self.bot.config.walk, + pokemon['lat'], + pokemon['lon'] + ) if not step_walker.step(): return WorkerResult.RUNNING logger.log('Arrived at {}'.format(pokemon['name'])) self.addCaught(pokemon) - return WorkerResult.SUCCESS \ No newline at end of file From 2c047594a7e1e6bf66d781e0149949ae548513e7 Mon Sep 17 00:00:00 2001 From: mhdasding Date: Sun, 31 Jul 2016 17:08:41 +0200 Subject: [PATCH 13/48] proper sniping --- .../cell_workers/move_to_map_pokemon.py | 48 +++++++++++-------- .../cell_workers/pokemon_catch_worker.py | 6 ++- 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py index 898ddefa83..a919283f4c 100644 --- a/pokemongo_bot/cell_workers/move_to_map_pokemon.py +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -10,6 +10,7 @@ from pokemongo_bot.human_behaviour import sleep from pokemongo_bot.step_walker import StepWalker from pokemongo_bot.worker_result import WorkerResult +from pokemon_catch_worker import PokemonCatchWorker class MoveToMapPokemon(object): @@ -21,9 +22,7 @@ def __init__(self, bot, config): self.db = self.load_db() self.pokemon_data = bot.pokemon_list self.caught = [] - self.last_position = None - self.sniped_last_tick = False - self.sniped_pokemon = None + self.unit = self.bot.config.distance_unit def load_db(self): if self.config['db_file'] == None: @@ -43,6 +42,7 @@ def get_pokemon_from_map(self): now = int(time.time() + self.config['min_time']) for row in cursor.execute('SELECT * FROM pokemon WHERE datetime(disappear_time) > datetime(?, "unixepoch");', (now, )): encounter_id = long(base64.b64decode(row[0])) + spawn_point_id = row[1] pokemon_id = row[2] lat = row[3] lon = row[4] @@ -62,6 +62,7 @@ def get_pokemon_from_map(self): pokemon_list.append({ 'encounter_id': encounter_id, + 'spawn_point_id': spawn_point_id, 'pokemon_id': pokemon_id, 'lat': lat, 'lon': lon, @@ -135,24 +136,36 @@ def update_map_location(self): logger.log('Updated PokemonGo-Map position') self.last_map_update = now + def snipe(self, pokemon): + last_position = self.bot.position[0:2] + logger.log('Teleporting to {} ({})'.format(pokemon['name'], format_dist(pokemon['dist'], self.unit))) + self.bot.api.set_position(pokemon['lat'], pokemon['lon'], 0) + + logger.log('Encounter pokemon', 'green') + pokemon['latitude'] = pokemon['lat'] + pokemon['longitude'] = pokemon['lon'] + catchWorker = PokemonCatchWorker(pokemon, self.bot) + apiEncounterResponse = catchWorker.create_encounter_api_call() + + time.sleep(2) + logger.log('Teleport back previous location..', 'green') + self.bot.api.set_position(last_position[0], last_position[1], 0) + time.sleep(2) + self.bot.heartbeat() + + catchWorker.work(apiEncounterResponse) + + return WorkerResult.SUCCESS + + def work(self): self.update_map_location() - unit = self.bot.config.distance_unit if 'catched_pokemon' in self.bot.passon: self.addCaught(self.bot.passon['catched_pokemon']) del self.bot.passon['catched_pokemon'] return WorkerResult.SUCCESS - # teleport back if sniped - if self.sniped_last_tick: - logger.log('Teleport back') - self.bot.api.set_position(self.last_position[0], self.last_position[1], 0) - self.addCaught(self.sniped_pokemon) - self.sniped_last_tick = False - return WorkerResult.SUCCESS - - pokemon_on_map = self.get_pokemon_from_map() pokemon_on_map = self.score_pokemon(pokemon_on_map) pokemon_on_map.sort(key=lambda x: x['score'], reverse=True) @@ -164,14 +177,9 @@ def work(self): now = int(time.time()) if self.bot.config.walk <= 0 or self.config['snipe']: - logger.log('Teleporting to {} ({})'.format(pokemon['name'], format_dist(pokemon['dist'], unit))) - self.bot.api.set_position(pokemon['lat'], pokemon['lon'], 0) - self.last_position = self.bot.position[0:2] - self.sniped_last_tick = True - self.sniped_pokemon = pokemon - return WorkerResult.RUNNING + return self.snipe(pokemon) - logger.log('Moving towards {}, {} left'.format(pokemon['name'], format_dist(pokemon['dist'], unit))) + logger.log('Moving towards {}, {} left'.format(pokemon['name'], format_dist(pokemon['dist'], self.unit))) step_walker = StepWalker( self.bot, self.bot.config.walk, diff --git a/pokemongo_bot/cell_workers/pokemon_catch_worker.py b/pokemongo_bot/cell_workers/pokemon_catch_worker.py index a0359edd2e..55b4962e06 100644 --- a/pokemongo_bot/cell_workers/pokemon_catch_worker.py +++ b/pokemongo_bot/cell_workers/pokemon_catch_worker.py @@ -24,9 +24,11 @@ def __init__(self, pokemon, bot): self.response_key = '' self.response_status_key = '' - def work(self): + def work(self, response_dict=None): encounter_id = self.pokemon['encounter_id'] - response_dict = self.create_encounter_api_call() + + if not response_dict: + response_dict = self.create_encounter_api_call() if response_dict and 'responses' in response_dict: if self.response_key in response_dict['responses']: From b1489c545bccd67bd72517984ef3cd8c92f0d462 Mon Sep 17 00:00:00 2001 From: mhdasding Date: Sun, 31 Jul 2016 17:19:47 +0200 Subject: [PATCH 14/48] mark sniped pokemon as caught --- pokemongo_bot/cell_workers/move_to_map_pokemon.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py index a919283f4c..41aa89382d 100644 --- a/pokemongo_bot/cell_workers/move_to_map_pokemon.py +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -138,8 +138,12 @@ def update_map_location(self): def snipe(self, pokemon): last_position = self.bot.position[0:2] - logger.log('Teleporting to {} ({})'.format(pokemon['name'], format_dist(pokemon['dist'], self.unit))) + self.bot.check_session(last_position) + self.bot.heartbeat() + + logger.log('Teleporting to {} ({})'.format(pokemon['name'], format_dist(pokemon['dist'], self.unit)), 'green') self.bot.api.set_position(pokemon['lat'], pokemon['lon'], 0) + cell = self.bot.get_meta_cell() logger.log('Encounter pokemon', 'green') pokemon['latitude'] = pokemon['lat'] @@ -148,12 +152,13 @@ def snipe(self, pokemon): apiEncounterResponse = catchWorker.create_encounter_api_call() time.sleep(2) - logger.log('Teleport back previous location..', 'green') + logger.log('Teleport back to previous location..', 'green') self.bot.api.set_position(last_position[0], last_position[1], 0) time.sleep(2) self.bot.heartbeat() catchWorker.work(apiEncounterResponse) + self.addCaught(pokemon) return WorkerResult.SUCCESS @@ -173,6 +178,9 @@ def work(self): if (len(pokemon_on_map) < 1): return + for idx in xrange(5): + print pokemon_on_map[0] + pokemon = pokemon_on_map[0] now = int(time.time()) From 29ef1246aa2b92389463613af7d292d54b8dd798 Mon Sep 17 00:00:00 2001 From: mhdasding Date: Sun, 31 Jul 2016 17:21:08 +0200 Subject: [PATCH 15/48] forgot to remove print --- pokemongo_bot/cell_workers/move_to_map_pokemon.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py index 41aa89382d..0098fd89f8 100644 --- a/pokemongo_bot/cell_workers/move_to_map_pokemon.py +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -178,9 +178,6 @@ def work(self): if (len(pokemon_on_map) < 1): return - for idx in xrange(5): - print pokemon_on_map[0] - pokemon = pokemon_on_map[0] now = int(time.time()) From 44a2561f5bad581e14e09978e29de6cfa346270d Mon Sep 17 00:00:00 2001 From: mhdasding Date: Sun, 31 Jul 2016 17:34:36 +0200 Subject: [PATCH 16/48] minor bug fix --- pokemongo_bot/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index 42f6f8b63f..2a8a526cf3 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -395,6 +395,8 @@ def update_inventory(self): if inventory_items: for item in inventory_items: item_info = item.get('inventory_item_data', {}).get('item') + if not item_info: + continue if {"item_id", "count"}.issubset(set(item_info.keys())): self.inventory.append(item['inventory_item_data']['item']) From aa15bf07cb8a7495ee6e1e8996234352fa211f10 Mon Sep 17 00:00:00 2001 From: mhdasding Date: Sun, 31 Jul 2016 17:41:03 +0200 Subject: [PATCH 17/48] ignore max_distance when sniping --- pokemongo_bot/cell_workers/move_to_map_pokemon.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py index 0098fd89f8..4354cc7857 100644 --- a/pokemongo_bot/cell_workers/move_to_map_pokemon.py +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -54,7 +54,7 @@ def get_pokemon_from_map(self): lon ) - if dist > self.config['max_distance']: + if dist > self.config['max_distance'] and self.config['mode'] != 'snipe': continue if encounter_id in self.caught: From 4302f304809f8d7de6ee60daa83175885814541a Mon Sep 17 00:00:00 2001 From: mhdasding Date: Sun, 31 Jul 2016 17:57:00 +0200 Subject: [PATCH 18/48] prioritize VIPs in a 10km radius --- pokemongo_bot/cell_workers/move_to_map_pokemon.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py index 4354cc7857..f2c959fe38 100644 --- a/pokemongo_bot/cell_workers/move_to_map_pokemon.py +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -94,7 +94,7 @@ def score_pokemon(self, pokemon_list): for pokemon in pokemon_list: score = 0 if self.config['prioritize_vips'] and self.is_in_vip(pokemon['pokemon_id']): - score += 1000 + score += 10000 if self.config['mode'] == 'distance': score -= pokemon['dist'] elif self.config['mode'] == 'priority': From e1e4c8f66640c48eab894fa5e2b7e8db26e568b1 Mon Sep 17 00:00:00 2001 From: mhdasding Date: Sun, 31 Jul 2016 18:08:20 +0200 Subject: [PATCH 19/48] better prioritize vips --- pokemongo_bot/__init__.py | 4 +--- pokemongo_bot/cell_workers/move_to_map_pokemon.py | 14 +++++++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index 2a8a526cf3..2662aed032 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -394,9 +394,7 @@ def update_inventory(self): 'inventory_delta', {}).get('inventory_items', {}) if inventory_items: for item in inventory_items: - item_info = item.get('inventory_item_data', {}).get('item') - if not item_info: - continue + item_info = item.get('inventory_item_data', {}).get('item', {}) if {"item_id", "count"}.issubset(set(item_info.keys())): self.inventory.append(item['inventory_item_data']['item']) diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py index f2c959fe38..d4c060a18c 100644 --- a/pokemongo_bot/cell_workers/move_to_map_pokemon.py +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -75,7 +75,7 @@ def get_pokemon_from_map(self): def get_name_from_id(self, pokemon_id): return self.pokemon_data[pokemon_id - 1]['Name'] - def is_in_vip(self, pokemon_id): + def is_vip(self, pokemon_id): return self.get_name_from_id(pokemon_id) in self.bot.config.vips def get_config_priority(self, pokemon_id): @@ -91,10 +91,14 @@ def addCaught(self, pokemon): def score_pokemon(self, pokemon_list): new_list = [] + has_vips = False + for pokemon in pokemon_list: + if self.config['prioritize_vips'] and self.is_vip(pokemon['pokemon_id']): + has_vips = True + break + for pokemon in pokemon_list: score = 0 - if self.config['prioritize_vips'] and self.is_in_vip(pokemon['pokemon_id']): - score += 10000 if self.config['mode'] == 'distance': score -= pokemon['dist'] elif self.config['mode'] == 'priority': @@ -112,6 +116,10 @@ def score_pokemon(self, pokemon_list): if pokemon['name'] in self.config['ignore']: continue + if has_vips: + if not self.is_vip(pokemon['pokemon_id']): + pokemon['score'] = 0 + new_list.append(pokemon) return new_list From 5a4eb402faa801d7f90c0809dbe1b6d7b06411ac Mon Sep 17 00:00:00 2001 From: mhdasding Date: Sun, 31 Jul 2016 18:12:52 +0200 Subject: [PATCH 20/48] syntax error fix --- pokemongo_bot/cell_workers/move_to_map_pokemon.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py index d4c060a18c..801bec6568 100644 --- a/pokemongo_bot/cell_workers/move_to_map_pokemon.py +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -118,7 +118,7 @@ def score_pokemon(self, pokemon_list): if has_vips: if not self.is_vip(pokemon['pokemon_id']): - pokemon['score'] = 0 + pokemon['score'] = 0 new_list.append(pokemon) return new_list From 88068ca2e0adc2aa13aaaef343fea694a2e728ba Mon Sep 17 00:00:00 2001 From: mhdasding Date: Sun, 31 Jul 2016 18:14:43 +0200 Subject: [PATCH 21/48] set base priority for vips --- pokemongo_bot/cell_workers/move_to_map_pokemon.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py index 801bec6568..6c50c18285 100644 --- a/pokemongo_bot/cell_workers/move_to_map_pokemon.py +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -99,6 +99,8 @@ def score_pokemon(self, pokemon_list): for pokemon in pokemon_list: score = 0 + if self.is_vip(pokemon['pokemon_id']): + score += 10000 if self.config['mode'] == 'distance': score -= pokemon['dist'] elif self.config['mode'] == 'priority': From 3e06e14555d39f0d853dfdd957c176a141f72246 Mon Sep 17 00:00:00 2001 From: mhdasding Date: Sun, 31 Jul 2016 20:54:07 +0200 Subject: [PATCH 22/48] move map config example to seperate file --- .gitignore | 1 + configs/config.json.example | 21 --- configs/config.json.map.example | 139 ++++++++++++++++++ .../cell_workers/move_to_map_pokemon.py | 2 +- 4 files changed, 141 insertions(+), 22 deletions(-) create mode 100644 configs/config.json.map.example diff --git a/.gitignore b/.gitignore index 58f90e86e3..00173615de 100644 --- a/.gitignore +++ b/.gitignore @@ -109,6 +109,7 @@ configs/* !configs/config.json.pokemons.example !configs/config.json.pokemon.example !configs/config.json.path.example +!configs/config.json.map.example !configs/path.example.json # Virtualenv folders diff --git a/configs/config.json.example b/configs/config.json.example index 46cee3fbe0..7c250203d5 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -39,27 +39,6 @@ { "type": "SpinFort" }, - { - "type": "MoveToMapPokemon", - "config": { - "db_file": "../PokemonGo-Map/pogom.db", - "address": "http://localhost:5000", - "max_distance": 500, - "min_time": 60, - "prioritize_vips": true, - "snipe": false, - "mode": "distance", - "priority": { - "Bulbasaur": 1, - "Squirtle": 3, - "Mewtwo": 100 - }, - "ignore": [ - "Drowzee", - "Jynx" - ] - } - }, { "type": "MoveToFort" }, diff --git a/configs/config.json.map.example b/configs/config.json.map.example new file mode 100644 index 0000000000..46cee3fbe0 --- /dev/null +++ b/configs/config.json.map.example @@ -0,0 +1,139 @@ +{ + "auth_service": "google", + "username": "YOUR_USERNAME", + "password": "YOUR_PASSWORD", + "location": "SOME_LOCATION", + "gmapkey": "GOOGLE_MAPS_API_KEY", + "tasks": [ + { + "type": "HandleSoftBan" + }, + { + "type": "CollectLevelUpReward" + }, + { + "type": "IncubateEggs", + "config": { + "longer_eggs_first": true + } + }, + { + "type": "TransferPokemon" + }, + { + "type": "EvolveAll", + "config": { + "evolve_speed": 20, + "use_lucky_egg": true + } + }, + { + "type": "RecycleItems" + }, + { + "type": "CatchVisiblePokemon" + }, + { + "type": "CatchLuredPokemon" + }, + { + "type": "SpinFort" + }, + { + "type": "MoveToMapPokemon", + "config": { + "db_file": "../PokemonGo-Map/pogom.db", + "address": "http://localhost:5000", + "max_distance": 500, + "min_time": 60, + "prioritize_vips": true, + "snipe": false, + "mode": "distance", + "priority": { + "Bulbasaur": 1, + "Squirtle": 3, + "Mewtwo": 100 + }, + "ignore": [ + "Drowzee", + "Jynx" + ] + } + }, + { + "type": "MoveToFort" + }, + { + "type": "FollowSpiral" + } + ], + "max_steps": 5, + "forts": { + "avoid_circles": true, + "max_circle_size": 50 + }, + "websocket_server": false, + "walk": 4.16, + "action_wait_min": 1, + "action_wait_max": 4, + "debug": false, + "test": false, + "health_record": true, + "location_cache": true, + "distance_unit": "km", + "reconnecting_timeout": 15, + "item_filter": { + "Pokeball": { "keep" : 100 }, + "Potion": { "keep" : 10 }, + "Super Potion": { "keep" : 20 }, + "Hyper Potion": { "keep" : 30 }, + "Revive": { "keep" : 30 }, + "Razz Berry": { "keep" : 100 } + }, + "evolve_all": "NONE", + "evolve_cp_min": 300, + "evolve_captured": "NONE", + "catch_randomize_reticle_factor": 1.0, + "catch_randomize_spin_factor": 1.0, + "catch": { + "any": {"catch_above_cp": 0, "catch_above_iv": 0, "logic": "or"}, + "// Example of always catching Rattata:": {}, + "// Rattata": { "always_catch" : true } + }, + "release": { + "any": {"release_below_cp": 0, "release_below_iv": 0, "logic": "or"}, + "// Example of always releasing Rattata:": {}, + "// Rattata": {"always_release": true}, + "// Example of keeping 3 stronger (based on CP) Pidgey:": {}, + "// Pidgey": {"keep_best_cp": 3}, + "// Example of keeping 2 stronger (based on IV) Zubat:": {}, + "// Zubat": {"keep_best_iv": 2}, + "// Also, it is working with any": {}, + "// any": {"keep_best_iv": 3}, + "// Example of keeping the 2 strongest (based on CP) and 3 best (based on IV) Zubat:": {}, + "// Zubat": {"keep_best_cp": 2, "keep_best_iv": 3} + }, + "vips" : { + "Any pokemon put here directly force to use Berry & Best Ball to capture, to secure the capture rate!": {}, + "any": {"catch_above_cp": 1200, "catch_above_iv": 0.9, "logic": "or" }, + "Lapras": {}, + "Moltres": {}, + "Zapdos": {}, + "Articuno": {}, + + "// S-Tier pokemons (if pokemon can be evolved into tier, list the representative)": {}, + "Mewtwo": {}, + "Dragonite": {}, + "Snorlax": {}, + "// Mew evolves to Mewtwo": {}, + "Mew": {}, + "Arcanine": {}, + "Vaporeon": {}, + "Gyarados": {}, + "Exeggutor": {}, + "Muk": {}, + "Weezing": {}, + "Flareon": {} + + } +} diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py index 6c50c18285..835f0cec07 100644 --- a/pokemongo_bot/cell_workers/move_to_map_pokemon.py +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -25,7 +25,7 @@ def __init__(self, bot, config): self.unit = self.bot.config.distance_unit def load_db(self): - if self.config['db_file'] == None: + if not 'db_file' in self.config: raise RuntimeError('You need to specify a db file (sqlite)') try: From a2f443a1c51512fdffcc34be154ab9ece72e1d12 Mon Sep 17 00:00:00 2001 From: mhdasding Date: Sun, 31 Jul 2016 21:37:01 +0200 Subject: [PATCH 23/48] use web api instead of sqlite db --- configs/config.json.map.example | 1 - .../cell_workers/move_to_map_pokemon.py | 65 +++++++------------ 2 files changed, 25 insertions(+), 41 deletions(-) diff --git a/configs/config.json.map.example b/configs/config.json.map.example index 46cee3fbe0..4546d13986 100644 --- a/configs/config.json.map.example +++ b/configs/config.json.map.example @@ -42,7 +42,6 @@ { "type": "MoveToMapPokemon", "config": { - "db_file": "../PokemonGo-Map/pogom.db", "address": "http://localhost:5000", "max_distance": 500, "min_time": 60, diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py index 835f0cec07..1cbf4cc2c5 100644 --- a/pokemongo_bot/cell_workers/move_to_map_pokemon.py +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -2,7 +2,6 @@ import json import time -import sqlite3 import requests import base64 from pokemongo_bot import logger @@ -19,57 +18,44 @@ def __init__(self, bot, config): self.bot = bot self.config = config self.last_map_update = 0 - self.db = self.load_db() self.pokemon_data = bot.pokemon_list self.caught = [] self.unit = self.bot.config.distance_unit - def load_db(self): - if not 'db_file' in self.config: - raise RuntimeError('You need to specify a db file (sqlite)') - + def get_pokemon_from_map(self): try: - conn = sqlite3.connect(self.config['db_file']) + r = requests.get('{}/raw_data?gyms=false&scanned=false'.format(self.config['address'])) except: - raise RuntimeError('Could not open db file "{}"'.format(self.config['db_file'])) - return conn + logger.log('Could not reach PokemonGo-Map Server', color='red') + return [] - def get_pokemon_from_map(self): - cursor = self.db.cursor() + raw_data = r.json() pokemon_list = [] + now = int(time.time()) - now = int(time.time() + self.config['min_time']) - for row in cursor.execute('SELECT * FROM pokemon WHERE datetime(disappear_time) > datetime(?, "unixepoch");', (now, )): - encounter_id = long(base64.b64decode(row[0])) - spawn_point_id = row[1] - pokemon_id = row[2] - lat = row[3] - lon = row[4] + for pokemon in raw_data['pokemons']: + pokemon['encounter_id'] = long(base64.b64decode(pokemon['encounter_id'])) + pokemon['spawn_point_id'] = pokemon['spawnpoint_id'] - dist = distance( + pokemon['dist'] = distance( self.bot.position[0], self.bot.position[1], - lat, - lon + pokemon['latitude'], + pokemon['longitude'], ) - if dist > self.config['max_distance'] and self.config['mode'] != 'snipe': + if pokemon['disappear_time'] < (now + self.config['min_time']): continue - if encounter_id in self.caught: + if pokemon['dist'] > self.config['max_distance'] and self.config['mode'] != 'snipe': continue - pokemon_list.append({ - 'encounter_id': encounter_id, - 'spawn_point_id': spawn_point_id, - 'pokemon_id': pokemon_id, - 'lat': lat, - 'lon': lon, - 'dist': dist - }) + if pokemon['encounter_id'] in self.caught: + continue + + pokemon_list.append(pokemon) - cursor.close() return pokemon_list def get_name_from_id(self, pokemon_id): @@ -126,8 +112,9 @@ def score_pokemon(self, pokemon_list): return new_list def update_map_location(self): - r = requests.get('{}/loc'.format(self.config['address'])) - if r.status_code != 200: + try: + r = requests.get('{}/loc'.format(self.config['address'])) + except: logger.log('Could not reach PokemonGo-Map Server', color='red') return j = r.json() @@ -152,12 +139,10 @@ def snipe(self, pokemon): self.bot.heartbeat() logger.log('Teleporting to {} ({})'.format(pokemon['name'], format_dist(pokemon['dist'], self.unit)), 'green') - self.bot.api.set_position(pokemon['lat'], pokemon['lon'], 0) + self.bot.api.set_position(pokemon['latitude'], pokemon['longitude'], 0) cell = self.bot.get_meta_cell() logger.log('Encounter pokemon', 'green') - pokemon['latitude'] = pokemon['lat'] - pokemon['longitude'] = pokemon['lon'] catchWorker = PokemonCatchWorker(pokemon, self.bot) apiEncounterResponse = catchWorker.create_encounter_api_call() @@ -186,7 +171,7 @@ def work(self): pokemon_on_map.sort(key=lambda x: x['score'], reverse=True) if (len(pokemon_on_map) < 1): - return + return WorkerResult.SUCCESS pokemon = pokemon_on_map[0] now = int(time.time()) @@ -198,8 +183,8 @@ def work(self): step_walker = StepWalker( self.bot, self.bot.config.walk, - pokemon['lat'], - pokemon['lon'] + pokemon['latitude'], + pokemon['longitude'] ) if not step_walker.step(): From 546586101f021015be6e50a9383166d35b448e5a Mon Sep 17 00:00:00 2001 From: mhdasding Date: Sun, 31 Jul 2016 22:00:21 +0200 Subject: [PATCH 24/48] fix datetime format --- pokemongo_bot/cell_workers/move_to_map_pokemon.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py index 1cbf4cc2c5..0c208ce7b3 100644 --- a/pokemongo_bot/cell_workers/move_to_map_pokemon.py +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -5,7 +5,7 @@ import requests import base64 from pokemongo_bot import logger -from pokemongo_bot.cell_workers.utils import distance, i2f, format_dist +from pokemongo_bot.cell_workers.utils import distance, i2f, format_dist, format_time from pokemongo_bot.human_behaviour import sleep from pokemongo_bot.step_walker import StepWalker from pokemongo_bot.worker_result import WorkerResult @@ -37,6 +37,7 @@ def get_pokemon_from_map(self): for pokemon in raw_data['pokemons']: pokemon['encounter_id'] = long(base64.b64decode(pokemon['encounter_id'])) pokemon['spawn_point_id'] = pokemon['spawnpoint_id'] + pokemon['disappear_time'] = int(pokemon['disappear_time'] / 1000) pokemon['dist'] = distance( self.bot.position[0], @@ -179,7 +180,7 @@ def work(self): if self.bot.config.walk <= 0 or self.config['snipe']: return self.snipe(pokemon) - logger.log('Moving towards {}, {} left'.format(pokemon['name'], format_dist(pokemon['dist'], self.unit))) + logger.log('Moving towards {}, {} left ({})'.format(pokemon['name'], format_dist(pokemon['dist'], self.unit), format_time(pokemon['disappear_time'] - now))) step_walker = StepWalker( self.bot, self.bot.config.walk, From 97bb3fbdc569e38feee222253b43b90775d17f56 Mon Sep 17 00:00:00 2001 From: mhdasding Date: Sun, 31 Jul 2016 22:52:09 +0200 Subject: [PATCH 25/48] huge code cleanup --- configs/config.json.map.example | 11 +- pokemongo_bot/__init__.py | 1 - .../cell_workers/catch_visible_pokemon.py | 2 - pokemongo_bot/cell_workers/move_to_fort.py | 3 - .../cell_workers/move_to_map_pokemon.py | 106 ++++++------------ 5 files changed, 35 insertions(+), 88 deletions(-) diff --git a/configs/config.json.map.example b/configs/config.json.map.example index 4546d13986..e442f980ca 100644 --- a/configs/config.json.map.example +++ b/configs/config.json.map.example @@ -47,17 +47,12 @@ "min_time": 60, "prioritize_vips": true, "snipe": false, - "mode": "distance", - "priority": { + "mode": "priority", + "catch": { "Bulbasaur": 1, "Squirtle": 3, "Mewtwo": 100 - }, - "ignore": [ - "Drowzee", - "Jynx" - ] - } + } }, { "type": "MoveToFort" diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index 2662aed032..72214a9f79 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -45,7 +45,6 @@ def __init__(self, config): self.tick_count = 0 self.softban = False self.start_position = None - self.passon = {} # Make our own copy of the workers for this instance self.workers = [] diff --git a/pokemongo_bot/cell_workers/catch_visible_pokemon.py b/pokemongo_bot/cell_workers/catch_visible_pokemon.py index cc038ce939..39f297e6e1 100644 --- a/pokemongo_bot/cell_workers/catch_visible_pokemon.py +++ b/pokemongo_bot/cell_workers/catch_visible_pokemon.py @@ -20,7 +20,6 @@ def work(self): for pokemon in self.bot.cell['catchable_pokemons']: with open(user_web_catchable, 'w') as outfile: json.dump(pokemon, outfile) - self.bot.passon['catched_pokemon'] = self.bot.cell['catchable_pokemons'][0] return self.catch_pokemon(self.bot.cell['catchable_pokemons'][0]) if 'wild_pokemons' in self.bot.cell and len(self.bot.cell['wild_pokemons']) > 0: @@ -29,7 +28,6 @@ def work(self): self.bot.cell['wild_pokemons'].sort( key= lambda x: distance(self.bot.position[0], self.bot.position[1], x['latitude'], x['longitude'])) - self.bot.passon['catched_pokemon'] = self.bot.cell['wild_pokemons'][0] return self.catch_pokemon(self.bot.cell['wild_pokemons'][0]) def catch_pokemon(self, pokemon): diff --git a/pokemongo_bot/cell_workers/move_to_fort.py b/pokemongo_bot/cell_workers/move_to_fort.py index 01988584b4..80cdc43e28 100644 --- a/pokemongo_bot/cell_workers/move_to_fort.py +++ b/pokemongo_bot/cell_workers/move_to_fort.py @@ -7,9 +7,6 @@ class MoveToFort(BaseTask): - def __init__(self, bot, config=None): - self.bot = bot - def should_run(self): return (self.bot.has_space_for_loot()) or self.bot.softban diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py index 0c208ce7b3..485a1f9b70 100644 --- a/pokemongo_bot/cell_workers/move_to_map_pokemon.py +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -9,16 +9,14 @@ from pokemongo_bot.human_behaviour import sleep from pokemongo_bot.step_walker import StepWalker from pokemongo_bot.worker_result import WorkerResult +from pokemongo_bot.cell_workers.base_task import BaseTask from pokemon_catch_worker import PokemonCatchWorker -class MoveToMapPokemon(object): - - def __init__(self, bot, config): - self.bot = bot - self.config = config +class MoveToMapPokemon(BaseTask): + def initialize(self): self.last_map_update = 0 - self.pokemon_data = bot.pokemon_list + self.pokemon_data = self.bot.pokemon_list self.caught = [] self.unit = self.bot.config.distance_unit @@ -38,6 +36,19 @@ def get_pokemon_from_map(self): pokemon['encounter_id'] = long(base64.b64decode(pokemon['encounter_id'])) pokemon['spawn_point_id'] = pokemon['spawnpoint_id'] pokemon['disappear_time'] = int(pokemon['disappear_time'] / 1000) + pokemon['name'] = self.pokemon_data[pokemon['pokemon_id'] - 1]['Name'] + pokemon['is_vip'] = pokemon['name'] in self.bot.config.vips + + if (pokemon['name'] not in self.config['catch']): + continue + + if pokemon['disappear_time'] < (now + self.config['min_time']): + continue + + if pokemon['encounter_id'] in self.caught: + continue + + pokemon['priority'] = self.config['catch'][pokemon['name']] pokemon['dist'] = distance( self.bot.position[0], @@ -46,72 +57,18 @@ def get_pokemon_from_map(self): pokemon['longitude'], ) - if pokemon['disappear_time'] < (now + self.config['min_time']): - continue - - if pokemon['dist'] > self.config['max_distance'] and self.config['mode'] != 'snipe': - continue - - if pokemon['encounter_id'] in self.caught: + if pokemon['dist'] > self.config['max_distance'] and not self.config['snipe']: continue pokemon_list.append(pokemon) return pokemon_list - def get_name_from_id(self, pokemon_id): - return self.pokemon_data[pokemon_id - 1]['Name'] - - def is_vip(self, pokemon_id): - return self.get_name_from_id(pokemon_id) in self.bot.config.vips - - def get_config_priority(self, pokemon_id): - if (self.get_name_from_id(pokemon_id) in self.config['priority']): - return self.config['priority'][self.get_name_from_id(pokemon_id)] - else: - return 0 - def addCaught(self, pokemon): if len(self.caught) >= 200: self.caught.pop(0) self.caught.append(pokemon['encounter_id']) - def score_pokemon(self, pokemon_list): - new_list = [] - has_vips = False - for pokemon in pokemon_list: - if self.config['prioritize_vips'] and self.is_vip(pokemon['pokemon_id']): - has_vips = True - break - - for pokemon in pokemon_list: - score = 0 - if self.is_vip(pokemon['pokemon_id']): - score += 10000 - if self.config['mode'] == 'distance': - score -= pokemon['dist'] - elif self.config['mode'] == 'priority': - score += self.get_config_priority(pokemon['pokemon_id']) - elif self.config['mode'] == 'hybrid': - score += self.get_config_priority(pokemon['pokemon_id']) - score -= pokemon['dist'] - - pokemon['name'] = self.get_name_from_id(pokemon['pokemon_id']) - pokemon['score'] = score - - if self.config['mode'] == 'priority' and pokemon['score'] < 1: - continue - - if pokemon['name'] in self.config['ignore']: - continue - - if has_vips: - if not self.is_vip(pokemon['pokemon_id']): - pokemon['score'] = 0 - - new_list.append(pokemon) - return new_list - def update_map_location(self): try: r = requests.get('{}/loc'.format(self.config['address'])) @@ -162,24 +119,25 @@ def snipe(self, pokemon): def work(self): self.update_map_location() - if 'catched_pokemon' in self.bot.passon: - self.addCaught(self.bot.passon['catched_pokemon']) - del self.bot.passon['catched_pokemon'] - return WorkerResult.SUCCESS + pokemon_list = self.get_pokemon_from_map() + pokemon_list.sort(key=lambda x: x['dist']) + if self.config['mode'] == 'priority': + pokemon_list.sort(key=lambda x: x['priority'], reverse=True) + if self.config['prioritize_vips'] == 'priority': + pokemon_list.sort(key=lambda x: x['is_vip']) - pokemon_on_map = self.get_pokemon_from_map() - pokemon_on_map = self.score_pokemon(pokemon_on_map) - pokemon_on_map.sort(key=lambda x: x['score'], reverse=True) - - if (len(pokemon_on_map) < 1): + if (len(pokemon_list) < 1): return WorkerResult.SUCCESS - pokemon = pokemon_on_map[0] - now = int(time.time()) + pokemon = pokemon_list[0] - if self.bot.config.walk <= 0 or self.config['snipe']: - return self.snipe(pokemon) + if 'catchable_pokemons' in self.bot.cell and len(self.bot.cell['catchable_pokemons']) > 0: + for catchable_pokemon in self.bot.cell['catchable_pokemons']: + if pokemon['encounter_id'] == catchable_pokemon['encounter_id']: + self.addCaught(pokemon) + return WorkerResult.SUCCESS + now = int(time.time()) logger.log('Moving towards {}, {} left ({})'.format(pokemon['name'], format_dist(pokemon['dist'], self.unit), format_time(pokemon['disappear_time'] - now))) step_walker = StepWalker( self.bot, From 74dd39349d77261e59b79938f155afbe83870c0a Mon Sep 17 00:00:00 2001 From: mhdasding Date: Sun, 31 Jul 2016 23:06:08 +0200 Subject: [PATCH 26/48] forgot to snipe --- pokemongo_bot/cell_workers/catch_visible_pokemon.py | 1 + pokemongo_bot/cell_workers/move_to_map_pokemon.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pokemongo_bot/cell_workers/catch_visible_pokemon.py b/pokemongo_bot/cell_workers/catch_visible_pokemon.py index 39f297e6e1..8b0ca86c73 100644 --- a/pokemongo_bot/cell_workers/catch_visible_pokemon.py +++ b/pokemongo_bot/cell_workers/catch_visible_pokemon.py @@ -20,6 +20,7 @@ def work(self): for pokemon in self.bot.cell['catchable_pokemons']: with open(user_web_catchable, 'w') as outfile: json.dump(pokemon, outfile) + return self.catch_pokemon(self.bot.cell['catchable_pokemons'][0]) if 'wild_pokemons' in self.bot.cell and len(self.bot.cell['wild_pokemons']) > 0: diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py index 485a1f9b70..005862baa6 100644 --- a/pokemongo_bot/cell_workers/move_to_map_pokemon.py +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -98,7 +98,6 @@ def snipe(self, pokemon): logger.log('Teleporting to {} ({})'.format(pokemon['name'], format_dist(pokemon['dist'], self.unit)), 'green') self.bot.api.set_position(pokemon['latitude'], pokemon['longitude'], 0) - cell = self.bot.get_meta_cell() logger.log('Encounter pokemon', 'green') catchWorker = PokemonCatchWorker(pokemon, self.bot) @@ -137,6 +136,9 @@ def work(self): self.addCaught(pokemon) return WorkerResult.SUCCESS + if self.config['snipe']: + return self.snipe(pokemon) + now = int(time.time()) logger.log('Moving towards {}, {} left ({})'.format(pokemon['name'], format_dist(pokemon['dist'], self.unit), format_time(pokemon['disappear_time'] - now))) step_walker = StepWalker( From 24667a815374f13e9bca0c89a4b768a82f770df5 Mon Sep 17 00:00:00 2001 From: mhdasding Date: Mon, 1 Aug 2016 07:38:20 +0200 Subject: [PATCH 27/48] add vips to catch as default --- pokemongo_bot/cell_workers/move_to_map_pokemon.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py index 005862baa6..341f7315b7 100644 --- a/pokemongo_bot/cell_workers/move_to_map_pokemon.py +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -39,7 +39,7 @@ def get_pokemon_from_map(self): pokemon['name'] = self.pokemon_data[pokemon['pokemon_id'] - 1]['Name'] pokemon['is_vip'] = pokemon['name'] in self.bot.config.vips - if (pokemon['name'] not in self.config['catch']): + if pokemon['name'] not in self.config['catch'] and pokemon['name'] not in self.bot.config.vips: continue if pokemon['disappear_time'] < (now + self.config['min_time']): From cd7001ccdfa3f440919cc112361a82c36b811704 Mon Sep 17 00:00:00 2001 From: mhdasding Date: Mon, 1 Aug 2016 07:44:20 +0200 Subject: [PATCH 28/48] default priority for vips --- pokemongo_bot/cell_workers/move_to_map_pokemon.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py index 341f7315b7..790579ab6e 100644 --- a/pokemongo_bot/cell_workers/move_to_map_pokemon.py +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -48,7 +48,10 @@ def get_pokemon_from_map(self): if pokemon['encounter_id'] in self.caught: continue - pokemon['priority'] = self.config['catch'][pokemon['name']] + if pokemon['name'] in self.config['catch']: + pokemon['priority'] = self.config['catch'][pokemon['name']] + else: + pokemon['priority'] = 0 pokemon['dist'] = distance( self.bot.position[0], From 9cc997b1b2d2dda87fca524bad7f9f50d6a889ae Mon Sep 17 00:00:00 2001 From: mhdasding Date: Mon, 1 Aug 2016 08:56:29 +0200 Subject: [PATCH 29/48] only mark pokemon as caught when it really was caught --- .../cell_workers/move_to_map_pokemon.py | 37 ++++++++++++++++--- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py index 790579ab6e..e973678ca7 100644 --- a/pokemongo_bot/cell_workers/move_to_map_pokemon.py +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -18,6 +18,7 @@ def initialize(self): self.last_map_update = 0 self.pokemon_data = self.bot.pokemon_list self.caught = [] + self.seen = [] self.unit = self.bot.config.distance_unit def get_pokemon_from_map(self): @@ -68,10 +69,27 @@ def get_pokemon_from_map(self): return pokemon_list def addCaught(self, pokemon): + for caught_pokemon in self.caught: + if caught_pokemon['encounter_id'] == pokemon['encounter_id']: + return if len(self.caught) >= 200: self.caught.pop(0) self.caught.append(pokemon['encounter_id']) + def addSeen(self, pokemon): + for seen_pokemon in self.seen: + if seen_pokemon['encounter_id'] == pokemon['encounter_id']: + return + if len(self.seen) >= 200: + self.seen.pop(0) + self.seen.append(pokemon['encounter_id']) + + def removeSeen(self, pokemon): + for idx in xrange(len(self.seen)): + if self.seen[idx]['encounter_id'] == pokemon['encounter_id']: + del self.seen[idx] + return + def update_map_location(self): try: r = requests.get('{}/loc'.format(self.config['address'])) @@ -121,6 +139,19 @@ def snipe(self, pokemon): def work(self): self.update_map_location() + # remove caught pokemon from candidates + if 'catchable_pokemons' in self.bot.cell and len(self.bot.cell['catchable_pokemons']) > 0: + for catchable_pokemon in self.bot.cell['catchable_pokemons']: + if pokemon['encounter_id'] == catchable_pokemon['encounter_id']: + self.addSeen(pokemon) + + for seen_pokemon in self.seen: + for catchable_pokemon in self.bot.cell['catchable_pokemons']: + if catchable_pokemon['encounter_id'] == seen_pokemon['encounter_id']: + self.removeSeen(seen_pokemon) + self.addCaught(seen_pokemon) + break + pokemon_list = self.get_pokemon_from_map() pokemon_list.sort(key=lambda x: x['dist']) if self.config['mode'] == 'priority': @@ -133,12 +164,6 @@ def work(self): pokemon = pokemon_list[0] - if 'catchable_pokemons' in self.bot.cell and len(self.bot.cell['catchable_pokemons']) > 0: - for catchable_pokemon in self.bot.cell['catchable_pokemons']: - if pokemon['encounter_id'] == catchable_pokemon['encounter_id']: - self.addCaught(pokemon) - return WorkerResult.SUCCESS - if self.config['snipe']: return self.snipe(pokemon) From 6fbe750c8589e8e110005353dee464c24d0fce23 Mon Sep 17 00:00:00 2001 From: mhdasding Date: Mon, 1 Aug 2016 09:07:38 +0200 Subject: [PATCH 30/48] bugfix --- pokemongo_bot/cell_workers/move_to_map_pokemon.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py index e973678ca7..b6c5a83b0e 100644 --- a/pokemongo_bot/cell_workers/move_to_map_pokemon.py +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -74,7 +74,7 @@ def addCaught(self, pokemon): return if len(self.caught) >= 200: self.caught.pop(0) - self.caught.append(pokemon['encounter_id']) + self.caught.append(pokemon) def addSeen(self, pokemon): for seen_pokemon in self.seen: @@ -82,7 +82,7 @@ def addSeen(self, pokemon): return if len(self.seen) >= 200: self.seen.pop(0) - self.seen.append(pokemon['encounter_id']) + self.seen.append(pokemon) def removeSeen(self, pokemon): for idx in xrange(len(self.seen)): @@ -142,8 +142,7 @@ def work(self): # remove caught pokemon from candidates if 'catchable_pokemons' in self.bot.cell and len(self.bot.cell['catchable_pokemons']) > 0: for catchable_pokemon in self.bot.cell['catchable_pokemons']: - if pokemon['encounter_id'] == catchable_pokemon['encounter_id']: - self.addSeen(pokemon) + self.addSeen(catchable_pokemon) for seen_pokemon in self.seen: for catchable_pokemon in self.bot.cell['catchable_pokemons']: From c480db56952e0c609ee832234d6fd7b22ecec315 Mon Sep 17 00:00:00 2001 From: mhdasding Date: Mon, 1 Aug 2016 09:14:29 +0200 Subject: [PATCH 31/48] bugfix #2 --- pokemongo_bot/cell_workers/move_to_map_pokemon.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py index b6c5a83b0e..391f9c97cd 100644 --- a/pokemongo_bot/cell_workers/move_to_map_pokemon.py +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -46,7 +46,7 @@ def get_pokemon_from_map(self): if pokemon['disappear_time'] < (now + self.config['min_time']): continue - if pokemon['encounter_id'] in self.caught: + if self.wasCaught(pokemon): continue if pokemon['name'] in self.config['catch']: @@ -76,6 +76,12 @@ def addCaught(self, pokemon): self.caught.pop(0) self.caught.append(pokemon) + def wasCaught(self, pokemon): + for caught_pokemon in self.caught: + if pokemon['encounter_id'] == caught['encounter_id']: + return True + return False + def addSeen(self, pokemon): for seen_pokemon in self.seen: if seen_pokemon['encounter_id'] == pokemon['encounter_id']: From fff50e45b0d177ff2ec1f832287a669ff46dbc8c Mon Sep 17 00:00:00 2001 From: mhdasding Date: Mon, 1 Aug 2016 09:15:43 +0200 Subject: [PATCH 32/48] i should go to bed --- pokemongo_bot/cell_workers/move_to_map_pokemon.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py index 391f9c97cd..b962815dc1 100644 --- a/pokemongo_bot/cell_workers/move_to_map_pokemon.py +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -78,7 +78,7 @@ def addCaught(self, pokemon): def wasCaught(self, pokemon): for caught_pokemon in self.caught: - if pokemon['encounter_id'] == caught['encounter_id']: + if pokemon['encounter_id'] == caught_pokemon['encounter_id']: return True return False From d8fd589a855fe508252e39bd536a5133c1a5d343 Mon Sep 17 00:00:00 2001 From: mhdasding Date: Mon, 1 Aug 2016 20:16:16 +0200 Subject: [PATCH 33/48] add option to disable map update --- configs/config.json.map.example | 1 + pokemongo_bot/cell_workers/move_to_map_pokemon.py | 2 ++ 2 files changed, 3 insertions(+) diff --git a/configs/config.json.map.example b/configs/config.json.map.example index e442f980ca..5ebe09957a 100644 --- a/configs/config.json.map.example +++ b/configs/config.json.map.example @@ -47,6 +47,7 @@ "min_time": 60, "prioritize_vips": true, "snipe": false, + "update_map": true, "mode": "priority", "catch": { "Bulbasaur": 1, diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py index b962815dc1..51d3236f4e 100644 --- a/pokemongo_bot/cell_workers/move_to_map_pokemon.py +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -97,6 +97,8 @@ def removeSeen(self, pokemon): return def update_map_location(self): + if not self.config['update_map']: + return try: r = requests.get('{}/loc'.format(self.config['address'])) except: From 98ee65db66bb892e5d0dd54f2b6a22c0498c0fed Mon Sep 17 00:00:00 2001 From: mhdasding Date: Mon, 1 Aug 2016 20:29:16 +0200 Subject: [PATCH 34/48] updated example map config to match default example --- configs/config.json.map.example | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/configs/config.json.map.example b/configs/config.json.map.example index 5ebe09957a..076463a536 100644 --- a/configs/config.json.map.example +++ b/configs/config.json.map.example @@ -23,12 +23,24 @@ { "type": "EvolveAll", "config": { + "evolve_all": "NONE", + "evolve_cp_min": 300, "evolve_speed": 20, - "use_lucky_egg": true + "use_lucky_egg": false } }, { - "type": "RecycleItems" + "type": "RecycleItems", + "config": { + "item_filter": { + "Pokeball": { "keep" : 100 }, + "Potion": { "keep" : 10 }, + "Super Potion": { "keep" : 20 }, + "Hyper Potion": { "keep" : 30 }, + "Revive": { "keep" : 30 }, + "Razz Berry": { "keep" : 100 } + } + } }, { "type": "CatchVisiblePokemon" @@ -62,6 +74,7 @@ "type": "FollowSpiral" } ], + "map_object_cache_time": 5, "max_steps": 5, "forts": { "avoid_circles": true, @@ -77,16 +90,6 @@ "location_cache": true, "distance_unit": "km", "reconnecting_timeout": 15, - "item_filter": { - "Pokeball": { "keep" : 100 }, - "Potion": { "keep" : 10 }, - "Super Potion": { "keep" : 20 }, - "Hyper Potion": { "keep" : 30 }, - "Revive": { "keep" : 30 }, - "Razz Berry": { "keep" : 100 } - }, - "evolve_all": "NONE", - "evolve_cp_min": 300, "evolve_captured": "NONE", "catch_randomize_reticle_factor": 1.0, "catch_randomize_spin_factor": 1.0, From 5cc2446d081a6c095f5bed37014b063e00c846af Mon Sep 17 00:00:00 2001 From: mhdasding Date: Mon, 1 Aug 2016 21:36:28 +0200 Subject: [PATCH 35/48] improve pylint result, fix catch recognition --- .../cell_workers/move_to_map_pokemon.py | 62 ++++++++++--------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py index 51d3236f4e..dfe2b0ace8 100644 --- a/pokemongo_bot/cell_workers/move_to_map_pokemon.py +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -1,16 +1,14 @@ # -*- coding: utf-8 -*- -import json import time -import requests import base64 +import requests from pokemongo_bot import logger -from pokemongo_bot.cell_workers.utils import distance, i2f, format_dist, format_time -from pokemongo_bot.human_behaviour import sleep +from pokemongo_bot.cell_workers.utils import distance, format_dist, format_time from pokemongo_bot.step_walker import StepWalker from pokemongo_bot.worker_result import WorkerResult from pokemongo_bot.cell_workers.base_task import BaseTask -from pokemon_catch_worker import PokemonCatchWorker +from pokemongo_bot.cell_workers.pokemon_catch_worker import PokemonCatchWorker class MoveToMapPokemon(BaseTask): @@ -23,12 +21,12 @@ def initialize(self): def get_pokemon_from_map(self): try: - r = requests.get('{}/raw_data?gyms=false&scanned=false'.format(self.config['address'])) - except: + req = requests.get('{}/raw_data?gyms=false&scanned=false'.format(self.config['address'])) + except requests.exceptions.ConnectionError: logger.log('Could not reach PokemonGo-Map Server', color='red') return [] - raw_data = r.json() + raw_data = req.json() pokemon_list = [] now = int(time.time()) @@ -46,7 +44,7 @@ def get_pokemon_from_map(self): if pokemon['disappear_time'] < (now + self.config['min_time']): continue - if self.wasCaught(pokemon): + if self.was_caught(pokemon): continue if pokemon['name'] in self.config['catch']: @@ -68,7 +66,7 @@ def get_pokemon_from_map(self): return pokemon_list - def addCaught(self, pokemon): + def add_caught(self, pokemon): for caught_pokemon in self.caught: if caught_pokemon['encounter_id'] == pokemon['encounter_id']: return @@ -76,13 +74,13 @@ def addCaught(self, pokemon): self.caught.pop(0) self.caught.append(pokemon) - def wasCaught(self, pokemon): + def was_caught(self, pokemon): for caught_pokemon in self.caught: if pokemon['encounter_id'] == caught_pokemon['encounter_id']: return True return False - def addSeen(self, pokemon): + def add_seen(self, pokemon): for seen_pokemon in self.seen: if seen_pokemon['encounter_id'] == pokemon['encounter_id']: return @@ -90,7 +88,7 @@ def addSeen(self, pokemon): self.seen.pop(0) self.seen.append(pokemon) - def removeSeen(self, pokemon): + def remove_seen(self, pokemon): for idx in xrange(len(self.seen)): if self.seen[idx]['encounter_id'] == pokemon['encounter_id']: del self.seen[idx] @@ -100,17 +98,17 @@ def update_map_location(self): if not self.config['update_map']: return try: - r = requests.get('{}/loc'.format(self.config['address'])) - except: + req = requests.get('{}/loc'.format(self.config['address'])) + except requests.exceptions.ConnectionError: logger.log('Could not reach PokemonGo-Map Server', color='red') return - j = r.json() + loc_json = req.json() dist = distance( self.bot.position[0], self.bot.position[1], - j['lat'], - j['lng'] + loc_json['lat'], + loc_json['lng'] ) # update map when 500m away from center and last update longer than 2 minutes away @@ -129,8 +127,8 @@ def snipe(self, pokemon): self.bot.api.set_position(pokemon['latitude'], pokemon['longitude'], 0) logger.log('Encounter pokemon', 'green') - catchWorker = PokemonCatchWorker(pokemon, self.bot) - apiEncounterResponse = catchWorker.create_encounter_api_call() + catch_worker = PokemonCatchWorker(pokemon, self.bot) + api_encounter_response = catch_worker.create_encounter_api_call() time.sleep(2) logger.log('Teleport back to previous location..', 'green') @@ -138,8 +136,8 @@ def snipe(self, pokemon): time.sleep(2) self.bot.heartbeat() - catchWorker.work(apiEncounterResponse) - self.addCaught(pokemon) + catch_worker.work(api_encounter_response) + self.add_caught(pokemon) return WorkerResult.SUCCESS @@ -148,16 +146,20 @@ def work(self): self.update_map_location() # remove caught pokemon from candidates - if 'catchable_pokemons' in self.bot.cell and len(self.bot.cell['catchable_pokemons']) > 0: - for catchable_pokemon in self.bot.cell['catchable_pokemons']: - self.addSeen(catchable_pokemon) + if not self.config['snipe']: + cell = self.bot.get_meta_cell() + for catchable_pokemon in cell['catchable_pokemons']: + self.add_seen(catchable_pokemon) for seen_pokemon in self.seen: + caught = True for catchable_pokemon in self.bot.cell['catchable_pokemons']: if catchable_pokemon['encounter_id'] == seen_pokemon['encounter_id']: - self.removeSeen(seen_pokemon) - self.addCaught(seen_pokemon) + caught = False break + if caught: + self.remove_seen(seen_pokemon) + self.add_caught(seen_pokemon) pokemon_list = self.get_pokemon_from_map() pokemon_list.sort(key=lambda x: x['dist']) @@ -166,7 +168,7 @@ def work(self): if self.config['prioritize_vips'] == 'priority': pokemon_list.sort(key=lambda x: x['is_vip']) - if (len(pokemon_list) < 1): + if len(pokemon_list) < 1: return WorkerResult.SUCCESS pokemon = pokemon_list[0] @@ -187,5 +189,5 @@ def work(self): return WorkerResult.RUNNING logger.log('Arrived at {}'.format(pokemon['name'])) - self.addCaught(pokemon) - return WorkerResult.SUCCESS \ No newline at end of file + self.add_caught(pokemon) + return WorkerResult.SUCCESS From dd74f346041f20e0913f50035467bf946a498f79 Mon Sep 17 00:00:00 2001 From: mhdasding Date: Mon, 1 Aug 2016 21:56:18 +0200 Subject: [PATCH 36/48] more code clean up --- .../cell_workers/move_to_map_pokemon.py | 35 ++----------------- 1 file changed, 2 insertions(+), 33 deletions(-) diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py index dfe2b0ace8..713f5ef9db 100644 --- a/pokemongo_bot/cell_workers/move_to_map_pokemon.py +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -16,7 +16,6 @@ def initialize(self): self.last_map_update = 0 self.pokemon_data = self.bot.pokemon_list self.caught = [] - self.seen = [] self.unit = self.bot.config.distance_unit def get_pokemon_from_map(self): @@ -38,7 +37,7 @@ def get_pokemon_from_map(self): pokemon['name'] = self.pokemon_data[pokemon['pokemon_id'] - 1]['Name'] pokemon['is_vip'] = pokemon['name'] in self.bot.config.vips - if pokemon['name'] not in self.config['catch'] and pokemon['name'] not in self.bot.config.vips: + if pokemon['name'] not in self.config['catch'] and not pokemon['is_vip']: continue if pokemon['disappear_time'] < (now + self.config['min_time']): @@ -80,20 +79,6 @@ def was_caught(self, pokemon): return True return False - def add_seen(self, pokemon): - for seen_pokemon in self.seen: - if seen_pokemon['encounter_id'] == pokemon['encounter_id']: - return - if len(self.seen) >= 200: - self.seen.pop(0) - self.seen.append(pokemon) - - def remove_seen(self, pokemon): - for idx in xrange(len(self.seen)): - if self.seen[idx]['encounter_id'] == pokemon['encounter_id']: - del self.seen[idx] - return - def update_map_location(self): if not self.config['update_map']: return @@ -131,7 +116,7 @@ def snipe(self, pokemon): api_encounter_response = catch_worker.create_encounter_api_call() time.sleep(2) - logger.log('Teleport back to previous location..', 'green') + logger.log('Teleporting back to previous location..', 'green') self.bot.api.set_position(last_position[0], last_position[1], 0) time.sleep(2) self.bot.heartbeat() @@ -145,22 +130,6 @@ def snipe(self, pokemon): def work(self): self.update_map_location() - # remove caught pokemon from candidates - if not self.config['snipe']: - cell = self.bot.get_meta_cell() - for catchable_pokemon in cell['catchable_pokemons']: - self.add_seen(catchable_pokemon) - - for seen_pokemon in self.seen: - caught = True - for catchable_pokemon in self.bot.cell['catchable_pokemons']: - if catchable_pokemon['encounter_id'] == seen_pokemon['encounter_id']: - caught = False - break - if caught: - self.remove_seen(seen_pokemon) - self.add_caught(seen_pokemon) - pokemon_list = self.get_pokemon_from_map() pokemon_list.sort(key=lambda x: x['dist']) if self.config['mode'] == 'priority': From 67047981ebd58811a5fa35aa0fbbb0dae2fa7e9b Mon Sep 17 00:00:00 2001 From: mhdasding Date: Tue, 2 Aug 2016 09:36:11 +0200 Subject: [PATCH 37/48] better config example --- configs/config.json.map.example | 231 +++++++++++++++++++++++++++++++- 1 file changed, 228 insertions(+), 3 deletions(-) diff --git a/configs/config.json.map.example b/configs/config.json.map.example index 076463a536..f9dd7aff8f 100644 --- a/configs/config.json.map.example +++ b/configs/config.json.map.example @@ -62,10 +62,235 @@ "update_map": true, "mode": "priority", "catch": { - "Bulbasaur": 1, - "Squirtle": 3, - "Mewtwo": 100 + "==========Legendaries==========": 0, + "Aerodactyl": 1000, + "Snorlax": 1000, + "Articuno": 1000, + "Zapdos": 1000, + "Moltres": 1000, + "Dratini": 1000, + "Dragonair": 1000, + "Dragonite": 1000, + "Mewtwo": 1000, + "Mew": 1000, + + "==========Region Locked==========": 0, + "Farfetch'd": 1000, + "Kangaskhan": 1000, + "Mr Mime": 1000, + "Tauros": 1000, + + "==========Very Rare==========": 0, + "Lapras": 900, + "Electabuzz": 900, + "Magmar": 900, + "Ditto": 900, + + "==========Starters==========": 0, + "Bulbasaur": 400, + "Ivysaur": 600, + "Venusaur": 1000, + + "Charmander": 400, + "Charmeleon": 600, + "Charizard": 1000, + + "Squirtle": 400, + "Wartortle": 600, + "Blastoise": 1000, + + "Pikachu": 600, + "Raichu": 1000, + + "==========Semi Rare==========": 0, + "Porygon": 200, + "Scyther": 200, + "Jynx": 200, + + "==========Uncommon==========": 0, + + "Omanyte": 150, + "Omastar": 500, + + "Seel": 300, + "Dewgong": 500, + + "Grimer": 200, + "Muk": 500, + + "Shellder": 200, + "Cloyster": 500, + + "Gastly": 200, + "Haunter": 500, + "Gengar": 1000, + + "Onix": 600, + + "Drowzee": 600, + + "Hypno": 600, + + "Vulpix": 200, + "Ninetales": 600, + + "Paras": 100, + "Parasect": 500, + + "Growlithe": 200, + "Arcanine": 700, + + "Tentacool": 200, + "Tentacruel": 500, + + "Mankey": 150, + "Primeape": 500, + + "Clefairy": 150, + "Clefable": 500, + + "Jigglypuff": 150, + "Wigglytuff": 500, + + "Venonat": 100, + "Venomoth": 500, + + "Diglett": 200, + "Dugtrio": 500, + + "Meowth": 250, + "Persian": 500, + + "Psyduck": 150, + "Golduck": 500, + + "Geodude": 100, + "Graveler": 500, + "Golem": 800, + + "Eevee": 200, + "Vaporeon": 800, + "Jolteon": 800, + "Flareon": 800, + + "Kabuto": 150, + "Kabutops": 500, + + "Magikarp": 150, + "Gyarados": 800, + + "Pinsir": 150, + + "Ponyta": 200, + "Rapidash": 500, + + "Slowpoke": 200, + "Slowbro": 500, + + "Magnemite": 250, + "Magneton": 500, + + "Krabby": 100, + "Kingler": 500, + + "Voltorb": 200, + "Electrode": 500, + + "Exeggcute": 250, + "Exeggcutor": 500, + + "Cubone": 300, + "Marowak": 800, + + "Hitmonlee": 400, + + "Hitmonchan": 400, + + "Lickitung": 500, + + "Koffing": 200, + "Weezing": 500, + + "Rhyhorn": 200, + "Rhydon": 500, + + "Chansey": 800, + + "Tangela": 300, + + "Horsea": 200, + "Seadra": 600, + + "Goldeen": 150, + "Seaking": 500, + + "Staryu": 200, + "Starmie": 800, + + + "==========T1 Evolvers==========": 0, + "Caterpie": 10, + "Metapod": 10, + "Butterfree": 500, + + "Weedle": 10, + "Kakuna": 10, + "Beedrill": 500, + + "Pidgey": 10, + "Pidgeotto": 10, + "Pidgeot": 300, + + "==========T2 Evolvers==========": 0, + "Nidoran ♀": 10, + "Nidorina": 10, + "Nidoqueen": 10, + + "Nidoran ♂": 10, + "Nidorino": 10, + "Nidoking": 10, + + "Oddish": 100, + "Gloom": 200, + "Vileplume": 600, + + "Poliwag": 200, + "Poliwhirl": 400, + "Poliwrath": 800, + + "Abra": 300, + "Kadabra": 600, + "Alakazam": 800, + + "Machop": 150, + "Machoke": 400, + "Machamp": 800, + + "Bellsprout": 100, + "Weepinbell": 400, + "Victreebel": 800, + + "==========Trash==========": 0, + + "Rattata": 10, + "Raticate": 10, + + "Spearow": 10, + "Fearow": 10, + + "Ekans": 10, + "Arbok": 10, + + "Sandshrew": 10, + "Sandslash": 10, + + "Zubat": 10, + "Golbat": 10, + + "Doduo": 10, + "Dodrio": 10 } + } }, { "type": "MoveToFort" From d9fac09ec7ff393be513b06d2cbee47b50dc8d64 Mon Sep 17 00:00:00 2001 From: mhdasding Date: Tue, 2 Aug 2016 10:21:24 +0200 Subject: [PATCH 38/48] dump caught pokemon to json file to prevent targeting them on restart --- .gitignore | 1 + pokemongo_bot/cell_workers/move_to_map_pokemon.py | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 76cfa82f55..a12509c322 100644 --- a/.gitignore +++ b/.gitignore @@ -101,6 +101,7 @@ src/ web/ data/last-location*.json data/cells-*.json +data/map-caught-*.json # Multiple config configs/* diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py index 713f5ef9db..14893127ad 100644 --- a/pokemongo_bot/cell_workers/move_to_map_pokemon.py +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- +import os import time +import json import base64 import requests from pokemongo_bot import logger @@ -15,8 +17,14 @@ class MoveToMapPokemon(BaseTask): def initialize(self): self.last_map_update = 0 self.pokemon_data = self.bot.pokemon_list - self.caught = [] self.unit = self.bot.config.distance_unit + self.caught = [] + + data_file = 'data/map-caught-{}.json'.format(self.bot.config.username) + if os.path.isfile(data_file): + self.caught = json.load( + open(data_file) + ) def get_pokemon_from_map(self): try: @@ -126,9 +134,14 @@ def snipe(self, pokemon): return WorkerResult.SUCCESS + def dump_caught_pokemon(self): + user_data_map_caught = 'data/map-caught-{}.json'.format(self.bot.config.username) + with open(user_data_map_caught, 'w') as outfile: + json.dump(self.caught, outfile) def work(self): self.update_map_location() + self.dump_caught_pokemon() pokemon_list = self.get_pokemon_from_map() pokemon_list.sort(key=lambda x: x['dist']) From 8f6c6669889a65a254968110a0078feb0909a8dc Mon Sep 17 00:00:00 2001 From: mhdasding Date: Tue, 2 Aug 2016 11:14:31 +0200 Subject: [PATCH 39/48] check if we got pokeballs to use --- pokemongo_bot/cell_workers/move_to_map_pokemon.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py index 14893127ad..3d0f4f3e4f 100644 --- a/pokemongo_bot/cell_workers/move_to_map_pokemon.py +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -140,6 +140,16 @@ def dump_caught_pokemon(self): json.dump(self.caught, outfile) def work(self): + # check for pokeballs (excluding masterball) + pokeballs = 0 + pokeballs += self.bot.item_inventory_count(1) + pokeballs += self.bot.item_inventory_count(2) + pokeballs += self.bot.item_inventory_count(3) + + print pokeballs + if pokeballs < 1: + return + self.update_map_location() self.dump_caught_pokemon() From 596507044cfa401ecb7940de6409afd4931b5bd7 Mon Sep 17 00:00:00 2001 From: mhdasding Date: Tue, 2 Aug 2016 11:15:18 +0200 Subject: [PATCH 40/48] remove print --- pokemongo_bot/cell_workers/move_to_map_pokemon.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py index 3d0f4f3e4f..cdd9e36be3 100644 --- a/pokemongo_bot/cell_workers/move_to_map_pokemon.py +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -146,7 +146,6 @@ def work(self): pokeballs += self.bot.item_inventory_count(2) pokeballs += self.bot.item_inventory_count(3) - print pokeballs if pokeballs < 1: return From 6ee5ea501dfdddbed4df57dc79f1694baaa9e937 Mon Sep 17 00:00:00 2001 From: mhdasding Date: Tue, 2 Aug 2016 12:06:17 +0200 Subject: [PATCH 41/48] fix item_inventory_count returnin None instead of 0 --- pokemongo_bot/__init__.py | 1 + pokemongo_bot/cell_workers/move_to_map_pokemon.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index 85fd114e7f..758fd358a7 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -432,6 +432,7 @@ def _item_inventory_count_per_id(self, id, inventory_dict): item_count = item_dict.get('count', False) if item_id == int(id) and item_count: return item_count + return 0 def _all_items_inventory_count(self, inventory_dict): item_count_dict = {} diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py index cdd9e36be3..c4eb3d40d8 100644 --- a/pokemongo_bot/cell_workers/move_to_map_pokemon.py +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -147,7 +147,7 @@ def work(self): pokeballs += self.bot.item_inventory_count(3) if pokeballs < 1: - return + return WorkerResult.SUCCESS self.update_map_location() self.dump_caught_pokemon() From a790a66d7f16d4b67da2b0f94d9aa5ad222501d5 Mon Sep 17 00:00:00 2001 From: mhdasding Date: Tue, 2 Aug 2016 13:16:44 +0200 Subject: [PATCH 42/48] if we only have ultraballs and the target is not a vip don't snipe/walk --- pokemongo_bot/cell_workers/move_to_map_pokemon.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py index c4eb3d40d8..9156dd0ef0 100644 --- a/pokemongo_bot/cell_workers/move_to_map_pokemon.py +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -141,12 +141,11 @@ def dump_caught_pokemon(self): def work(self): # check for pokeballs (excluding masterball) - pokeballs = 0 - pokeballs += self.bot.item_inventory_count(1) - pokeballs += self.bot.item_inventory_count(2) - pokeballs += self.bot.item_inventory_count(3) + pokeballs = self.bot.item_inventory_count(1) + superballs = self.bot.item_inventory_count(2) + ultraballs = self.bot.item_inventory_count(3) - if pokeballs < 1: + if (pokeballs + superballs + ultraballs) < 1: return WorkerResult.SUCCESS self.update_map_location() @@ -164,6 +163,10 @@ def work(self): pokemon = pokemon_list[0] + # if we only have ultraballs and the target is not a vip don't snipe/walk + if (pokeballs + superballs) < 1 and not pokemon['is_vip']: + return WorkerResult.SUCCESS + if self.config['snipe']: return self.snipe(pokemon) From fcd8d12a347e630f26ef5b71d49c5093ee868839 Mon Sep 17 00:00:00 2001 From: mhdasding Date: Tue, 2 Aug 2016 17:03:14 +0200 Subject: [PATCH 43/48] remove gender symbols --- configs/config.json.map.example | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configs/config.json.map.example b/configs/config.json.map.example index f9dd7aff8f..d826c0b97e 100644 --- a/configs/config.json.map.example +++ b/configs/config.json.map.example @@ -242,11 +242,11 @@ "Pidgeot": 300, "==========T2 Evolvers==========": 0, - "Nidoran ♀": 10, + "Nidoran F": 10, "Nidorina": 10, "Nidoqueen": 10, - "Nidoran ♂": 10, + "Nidoran M": 10, "Nidorino": 10, "Nidoking": 10, From e32c731baa2cfb91d50c89aacb01b0b96e99a0da Mon Sep 17 00:00:00 2001 From: mhdasding Date: Tue, 2 Aug 2016 17:38:50 +0200 Subject: [PATCH 44/48] fix Mr. Mime --- configs/config.json.map.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configs/config.json.map.example b/configs/config.json.map.example index d826c0b97e..6436b95905 100644 --- a/configs/config.json.map.example +++ b/configs/config.json.map.example @@ -77,7 +77,7 @@ "==========Region Locked==========": 0, "Farfetch'd": 1000, "Kangaskhan": 1000, - "Mr Mime": 1000, + "Mr. Mime": 1000, "Tauros": 1000, "==========Very Rare==========": 0, From 8b182d4858eeddcc1e99eeeedc7836f7a2de92eb Mon Sep 17 00:00:00 2001 From: mhdasding Date: Tue, 2 Aug 2016 19:26:03 +0200 Subject: [PATCH 45/48] vip wrong order fix --- pokemongo_bot/cell_workers/move_to_map_pokemon.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py index 9156dd0ef0..b93656a2e9 100644 --- a/pokemongo_bot/cell_workers/move_to_map_pokemon.py +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -54,10 +54,7 @@ def get_pokemon_from_map(self): if self.was_caught(pokemon): continue - if pokemon['name'] in self.config['catch']: - pokemon['priority'] = self.config['catch'][pokemon['name']] - else: - pokemon['priority'] = 0 + pokemon['priority'] = self.config['catch'].get(pokemon['name'], 0) pokemon['dist'] = distance( self.bot.position[0], @@ -156,7 +153,7 @@ def work(self): if self.config['mode'] == 'priority': pokemon_list.sort(key=lambda x: x['priority'], reverse=True) if self.config['prioritize_vips'] == 'priority': - pokemon_list.sort(key=lambda x: x['is_vip']) + pokemon_list.sort(key=lambda x: x['is_vip'], reverse=True) if len(pokemon_list) < 1: return WorkerResult.SUCCESS From f9a92faa3fa35ab8ba1a1031b5332ef00a4bab12 Mon Sep 17 00:00:00 2001 From: mhdasding Date: Tue, 2 Aug 2016 19:30:04 +0200 Subject: [PATCH 46/48] bugfix --- pokemongo_bot/cell_workers/move_to_map_pokemon.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py index b93656a2e9..53aa85fcc8 100644 --- a/pokemongo_bot/cell_workers/move_to_map_pokemon.py +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -152,7 +152,7 @@ def work(self): pokemon_list.sort(key=lambda x: x['dist']) if self.config['mode'] == 'priority': pokemon_list.sort(key=lambda x: x['priority'], reverse=True) - if self.config['prioritize_vips'] == 'priority': + if self.config['prioritize_vips']: pokemon_list.sort(key=lambda x: x['is_vip'], reverse=True) if len(pokemon_list) < 1: From 2a3b31e0ee7113152705ca13a46955d3480e742c Mon Sep 17 00:00:00 2001 From: mhdasding Date: Tue, 2 Aug 2016 23:51:17 +0200 Subject: [PATCH 47/48] log error when JSON decoding fails --- .../cell_workers/move_to_map_pokemon.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py index 53aa85fcc8..ff5311d9fc 100644 --- a/pokemongo_bot/cell_workers/move_to_map_pokemon.py +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -30,10 +30,14 @@ def get_pokemon_from_map(self): try: req = requests.get('{}/raw_data?gyms=false&scanned=false'.format(self.config['address'])) except requests.exceptions.ConnectionError: - logger.log('Could not reach PokemonGo-Map Server', color='red') + logger.log('Could not reach PokemonGo-Map Server', 'red') return [] - raw_data = req.json() + try: + raw_data = req.json() + except ValueError: + logger.log('Map data was not valid', 'red') + return [] pokemon_list = [] now = int(time.time()) @@ -90,9 +94,14 @@ def update_map_location(self): try: req = requests.get('{}/loc'.format(self.config['address'])) except requests.exceptions.ConnectionError: - logger.log('Could not reach PokemonGo-Map Server', color='red') + logger.log('Could not reach PokemonGo-Map Server', 'red') return - loc_json = req.json() + + try: + loc_json = req.json() + except ValueError: + return log.logger('Map location data was not valid', 'red') + dist = distance( self.bot.position[0], @@ -110,7 +119,7 @@ def update_map_location(self): def snipe(self, pokemon): last_position = self.bot.position[0:2] - self.bot.check_session(last_position) + self.bot.heartbeat() logger.log('Teleporting to {} ({})'.format(pokemon['name'], format_dist(pokemon['dist'], self.unit)), 'green') From 89ba4517f0c4cc57769e538191f9d3374389b065 Mon Sep 17 00:00:00 2001 From: mhdasding Date: Tue, 2 Aug 2016 23:58:01 +0200 Subject: [PATCH 48/48] handle base64 error --- pokemongo_bot/cell_workers/move_to_map_pokemon.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py index ff5311d9fc..bce39e0143 100644 --- a/pokemongo_bot/cell_workers/move_to_map_pokemon.py +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -43,7 +43,11 @@ def get_pokemon_from_map(self): now = int(time.time()) for pokemon in raw_data['pokemons']: - pokemon['encounter_id'] = long(base64.b64decode(pokemon['encounter_id'])) + try: + pokemon['encounter_id'] = long(base64.b64decode(pokemon['encounter_id'])) + except TypeError: + log.logger('base64 error: {}'.format(pokemon['encounter_id']), 'red') + continue pokemon['spawn_point_id'] = pokemon['spawnpoint_id'] pokemon['disappear_time'] = int(pokemon['disappear_time'] / 1000) pokemon['name'] = self.pokemon_data[pokemon['pokemon_id'] - 1]['Name']