diff --git a/configs/config.json.cluster.example b/configs/config.json.cluster.example index b847c1a638..52baa7055b 100644 --- a/configs/config.json.cluster.example +++ b/configs/config.json.cluster.example @@ -65,8 +65,8 @@ "config": { "enabled": true, "min_free_slot": 5, - "transfer_wait_min": 1, - "transfer_wait_max": 4 + "transfer_wait_min": 3, + "transfer_wait_max": 5 } }, { @@ -86,7 +86,8 @@ "evolve_above_cp": 500, "evolve_above_iv": 0.8, "logic": "or", - "evolve_speed": 20, + "min_evolve_speed": 25, + "max_evolve_speed": 30, "use_lucky_egg": false } }, @@ -107,8 +108,8 @@ "Revive": { "keep" : 30 }, "Razz Berry": { "keep" : 100 } }, - "recycle_wait_min": 1, - "recycle_wait_max": 4 + "recycle_wait_min": 3, + "recycle_wait_max": 5 } }, { @@ -130,12 +131,12 @@ "catch_simulation": { "flee_count": 3, "flee_duration": 2, - "catch_wait_min": 2, + "catch_wait_min": 3, "catch_wait_max": 6, - "berry_wait_min": 2, - "berry_wait_max": 3, - "changeball_wait_min": 2, - "changeball_wait_max": 3 + "berry_wait_min": 3, + "berry_wait_max": 5, + "changeball_wait_min": 3, + "changeball_wait_max": 5 } } }, diff --git a/configs/config.json.example b/configs/config.json.example index 2986e59205..29256ebea5 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -78,8 +78,8 @@ "config": { "enabled": true, "min_free_slot": 5, - "transfer_wait_min": 1, - "transfer_wait_max": 4 + "transfer_wait_min": 3, + "transfer_wait_max": 5 } }, { @@ -99,7 +99,8 @@ "evolve_above_cp": 500, "evolve_above_iv": 0.8, "logic": "or", - "evolve_speed": 20, + "min_evolve_speed": 25, + "max_evolve_speed": 30, "use_lucky_egg": false } }, @@ -120,8 +121,8 @@ "Revive": { "keep" : 30 }, "Razz Berry": { "keep" : 100 } }, - "recycle_wait_min": 1, - "recycle_wait_max": 4 + "recycle_wait_min": 3, + "recycle_wait_max": 5 } }, { @@ -145,12 +146,12 @@ "catch_simulation": { "flee_count": 3, "flee_duration": 2, - "catch_wait_min": 2, + "catch_wait_min": 3, "catch_wait_max": 6, - "berry_wait_min": 2, - "berry_wait_max": 3, - "changeball_wait_min": 2, - "changeball_wait_max": 3 + "berry_wait_min": 3, + "berry_wait_max": 5, + "changeball_wait_min": 3, + "changeball_wait_max": 5 } } }, diff --git a/configs/config.json.map.example b/configs/config.json.map.example index d2990b1b38..d4abf5e6bb 100644 --- a/configs/config.json.map.example +++ b/configs/config.json.map.example @@ -86,7 +86,8 @@ "evolve_above_cp": 500, "evolve_above_iv": 0.8, "logic": "or", - "evolve_speed": 20, + "min_evolve_speed": 25, + "max_evolve_speed": 30, "use_lucky_egg": false } }, diff --git a/configs/config.json.optimizer.example b/configs/config.json.optimizer.example index 54886ee30f..0e6656ffaa 100644 --- a/configs/config.json.optimizer.example +++ b/configs/config.json.optimizer.example @@ -71,8 +71,8 @@ "transfer": true, "// 'transfer_wait_min' and 'transfer_wait_max' are the minimum and maximum": {}, "// time to wait when transferring a pokemon": {}, - "transfer_wait_min": 2, - "transfer_wait_max": 4, + "transfer_wait_min": 3, + "transfer_wait_max": 5, "// the 'evolve' parameter activate or deactivate the evolution of pokemons": {}, "// at false, no pokemon is going to be evolved, ever": {}, "// at false, you will still get the log information of what the": {}, @@ -169,8 +169,8 @@ "Revive": { "keep" : 30 }, "Razz Berry": { "keep" : 100 } }, - "recycle_wait_min": 1, - "recycle_wait_max": 4 + "recycle_wait_min": 3, + "recycle_wait_max": 5 } }, { @@ -193,12 +193,12 @@ "catch_simulation": { "flee_count": 3, "flee_duration": 2, - "catch_wait_min": 2, + "catch_wait_min": 3, "catch_wait_max": 6, - "berry_wait_min": 2, - "berry_wait_max": 3, - "changeball_wait_min": 2, - "changeball_wait_max": 3 + "berry_wait_min": 3, + "berry_wait_max": 5, + "changeball_wait_min": 3, + "changeball_wait_max": 5 } } }, diff --git a/configs/config.json.path.example b/configs/config.json.path.example index 291a2351d2..a8bf6cb8e2 100644 --- a/configs/config.json.path.example +++ b/configs/config.json.path.example @@ -65,8 +65,8 @@ "config": { "enabled": true, "min_free_slot": 5, - "transfer_wait_min": 1, - "transfer_wait_max": 4 + "transfer_wait_min": 3, + "transfer_wait_max": 5 } }, { @@ -86,7 +86,8 @@ "evolve_above_cp": 500, "evolve_above_iv": 0.8, "logic": "or", - "evolve_speed": 20, + "min_evolve_speed": 25, + "max_evolve_speed": 30, "use_lucky_egg": false } }, @@ -107,8 +108,8 @@ "Revive": { "keep" : 30 }, "Razz Berry": { "keep" : 100 } }, - "recycle_wait_min": 1, - "recycle_wait_max": 4 + "recycle_wait_min": 3, + "recycle_wait_max": 5 } }, { @@ -131,12 +132,12 @@ "catch_simulation": { "flee_count": 3, "flee_duration": 2, - "catch_wait_min": 2, + "catch_wait_min": 3, "catch_wait_max": 6, - "berry_wait_min": 2, - "berry_wait_max": 3, - "changeball_wait_min": 2, - "changeball_wait_max": 3 + "berry_wait_min": 3, + "berry_wait_max": 5, + "changeball_wait_min": 3, + "changeball_wait_max": 5 } } }, @@ -152,6 +153,7 @@ "type": "FollowPath", "config": { "enabled": true, + "walker": "StepWalker", "path_mode": "loop", "path_start_mode": "first", "path_file": "configs/path.example.json", diff --git a/configs/config.json.pokemon.example b/configs/config.json.pokemon.example index 484c4f4877..df51153b77 100644 --- a/configs/config.json.pokemon.example +++ b/configs/config.json.pokemon.example @@ -65,8 +65,8 @@ "config": { "enabled": true, "min_free_slot": 5, - "transfer_wait_min": 1, - "transfer_wait_max": 4 + "transfer_wait_min": 3, + "transfer_wait_max": 5 } }, { @@ -107,8 +107,8 @@ "Revive": { "keep" : 30 }, "Razz Berry": { "keep" : 100 } }, - "recycle_wait_min": 1, - "recycle_wait_max": 4 + "recycle_wait_min": 3, + "recycle_wait_max": 5 } }, { @@ -131,12 +131,12 @@ "catch_simulation": { "flee_count": 3, "flee_duration": 2, - "catch_wait_min": 2, + "catch_wait_min": 3, "catch_wait_max": 6, - "berry_wait_min": 2, - "berry_wait_max": 3, - "changeball_wait_min": 2, - "changeball_wait_max": 3 + "berry_wait_min": 3, + "berry_wait_max": 5, + "changeball_wait_min": 3, + "changeball_wait_max": 5 } } }, diff --git a/docs/configuration_files.md b/docs/configuration_files.md index 8836d5d94a..d931ee5a7f 100644 --- a/docs/configuration_files.md +++ b/docs/configuration_files.md @@ -94,7 +94,8 @@ The behaviors of the bot are configured via the `tasks` key in the `config.json` * `treat_unseen_as_vip`: Default `"true"` | Set to `"false"` to disable treating pokemons you don't have in your pokedex as VIPs. * EvolvePokemon * `evolve_all`: Default `NONE` | Set to `"all"` to evolve Pokémon if possible when the bot starts. Can also be set to individual Pokémon as well as multiple separated by a comma. e.g "Pidgey,Rattata,Weedle,Zubat" - * `evolve_speed`: Default `20` + * `min_evolve_speed`: Default `25` | Minimum seconds to wait between each evolution + * `max_evolve_speed`: Default `30` | Maximum seconds to wait between each evolution * `use_lucky_egg`: Default: `False` * FollowPath * `path_mode`: Default `loop` | Set the mode for the path navigator (loop or linear). @@ -494,7 +495,7 @@ If you want to make your bot behave as it did prior to the catch_simulation upda ### Description [[back to top](#table-of-contents)] -This task will fetch current pokemon spawns from /raw_data of an PokemonGo-Map instance. For information on how to properly setup PokemonGo-Map have a look at the Github page of the project [here](https://github.com/AHAAAAAAA/PokemonGo-Map/). There is an example config in `config/config.json.map.example` +This task will fetch current pokemon spawns from /raw_data of an PokemonGo-Map instance. For information on how to properly setup PokemonGo-Map have a look at the Github page of the project [here](https://github.com/PokemonGoMap/PokemonGo-Map). There is an example config in `config/config.json.map.example` ### Options [[back to top](#table-of-contents)] diff --git a/map-chat/images/blue_marker.png b/map-chat/images/blue_marker.png index a7f31c1f39..2716997528 100644 Binary files a/map-chat/images/blue_marker.png and b/map-chat/images/blue_marker.png differ diff --git a/map-chat/images/grey_marker.png b/map-chat/images/grey_marker.png index 20343a36a8..c1d2027631 100644 Binary files a/map-chat/images/grey_marker.png and b/map-chat/images/grey_marker.png differ diff --git a/map-chat/images/p/01.png b/map-chat/images/p/01.png new file mode 100644 index 0000000000..376637ade6 Binary files /dev/null and b/map-chat/images/p/01.png differ diff --git a/map-chat/images/p/02.png b/map-chat/images/p/02.png new file mode 100644 index 0000000000..f2e6b0e751 Binary files /dev/null and b/map-chat/images/p/02.png differ diff --git a/map-chat/images/p/03.png b/map-chat/images/p/03.png new file mode 100644 index 0000000000..fa41d34b9b Binary files /dev/null and b/map-chat/images/p/03.png differ diff --git a/map-chat/images/p/04.png b/map-chat/images/p/04.png new file mode 100644 index 0000000000..52703f2b4f Binary files /dev/null and b/map-chat/images/p/04.png differ diff --git a/map-chat/images/p/05.png b/map-chat/images/p/05.png new file mode 100644 index 0000000000..787469c195 Binary files /dev/null and b/map-chat/images/p/05.png differ diff --git a/map-chat/images/p/06.png b/map-chat/images/p/06.png new file mode 100644 index 0000000000..8bfa5f8697 Binary files /dev/null and b/map-chat/images/p/06.png differ diff --git a/map-chat/images/p/07.png b/map-chat/images/p/07.png new file mode 100644 index 0000000000..a7a8f5cc44 Binary files /dev/null and b/map-chat/images/p/07.png differ diff --git a/map-chat/images/p/08.png b/map-chat/images/p/08.png new file mode 100644 index 0000000000..74e47b4332 Binary files /dev/null and b/map-chat/images/p/08.png differ diff --git a/map-chat/images/p/09.png b/map-chat/images/p/09.png new file mode 100644 index 0000000000..d092154faa Binary files /dev/null and b/map-chat/images/p/09.png differ diff --git a/map-chat/index.html b/map-chat/index.html index 5e1f8b99df..27b174ec53 100644 --- a/map-chat/index.html +++ b/map-chat/index.html @@ -23,7 +23,7 @@ - + - + Fork me on GitHub @@ -111,7 +111,7 @@ - + diff --git a/map-chat/javascript/main.js b/map-chat/javascript/main.js index a914b96b7d..c708c81477 100644 --- a/map-chat/javascript/main.js +++ b/map-chat/javascript/main.js @@ -7,7 +7,7 @@ var urlHashTopic = location.hash ? location.hash.substring(1).toLowerCase() : nu var topic = urlHashTopic ? urlHashTopic : "pgomapcatch/chat"; function initialiseEventBus(){ - window.client = mqtt.connect('ws://test.mosca.io'); // you add a ws:// url here + window.client = mqtt.connect('ws://broker.pikabot.org'); // you add a ws:// url here client.subscribe("pgomapcatch/#"); client.on("message", function(topic, payload) { @@ -18,6 +18,7 @@ function initialiseEventBus(){ if(topic === 'pgomapcatch/chat'){ console.log('Chatting event') displayChatMessageOnMap(payload) + Materialize.toast(payload, 5000); } else { //@ro: let's grab the message and split that shit. (simple for now, maybe we could just parse the json instead) @@ -27,12 +28,14 @@ function initialiseEventBus(){ var olong = pLoadR2[1] var sessid = pLoadR2[2] var ico = pLoadR2[3] + var expir = pLoadR2[4] + var pokenick = pLoadR2[5] var path = "./images/p/" var icon = path+"0"+ico+".png" - var icostr = icon.toString(); - //console.log(icostr) + var icostr = icon.toString(); + //console.log(icostr) - displayMessageOnMap(payload, olat, olong, sessid, icostr); + displayMessageOnMap(payload, olat, olong, sessid, icostr, expir, pokenick); } }); diff --git a/map-chat/javascript/map.js b/map-chat/javascript/map.js index f4bf861a18..f93eacc684 100644 --- a/map-chat/javascript/map.js +++ b/map-chat/javascript/map.js @@ -138,7 +138,7 @@ function displayChatMessageOnMap(raw){ }); // msg.text = msg.text ? embedTweet(msg.text) : ""; - msg.text = msg.text.replace(/#(\S*)/g,'#$1'); + msg.text = msg.text.replace(/#(\S*)/g,'#$1'); // linkify msg.text = msg.text.replace(/(\b(https?|ftp|file)://[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig, @@ -207,12 +207,27 @@ function displayChatMessageOnMap(raw){ } } -function displayMessageOnMap(msg, olat, olong, sessid, icostr){ +// @ro: to calculate time until expiration +function timeUntil(now, then) { + var timestampNow = Date.parse(now); + var timestampThen = Date.parse(then); + var diff = new Date(timestampThen - timestampNow); + + diff.setSeconds(Math.round(diff.getSeconds() / 30) * 30); + + return diff; +} + + +function displayMessageOnMap(msg, olat, olong, sessid, icostr, expir, pokenick){ // @ro: passing values split from incoming payload into two variables for now (lat and long) var newPosition = new google.maps.LatLng(olat, olong); var msgSessionId = sessid; - + var expiration = expir; + var thetime = "155564565475" + var pName = pokenick/* + " disappears in " + timeUntil(thetime,expiration)*/; + console.log(pName) // @ro: just checking the output //console.log(olat); //console.log(olong); @@ -225,7 +240,7 @@ function displayMessageOnMap(msg, olat, olong, sessid, icostr){ }); // msg.text = msg.text ? embedTweet(msg.text) : ""; - msg.text = msg.text.replace(/#(\S*)/g,'#$1'); + msg.text = msg.text.replace(/#(\S*)/g,'#$1'); // linkify msg.text = msg.text.replace(/(\b(https?|ftp|file)://[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig, @@ -233,7 +248,7 @@ function displayMessageOnMap(msg, olat, olong, sessid, icostr){ if(markersMap[msgSessionId]){ // update existing marker var infoWindow = new google.maps.InfoWindow({ - content: msg.text, + content: pName, maxWidth: 400, disableAutoPan: true, zIndex: infoWindowZIndex @@ -245,6 +260,7 @@ function displayMessageOnMap(msg, olat, olong, sessid, icostr){ map: map, draggable: false, icon: icostr, + icon: { url: icostr, scaledSize: new google.maps.Size(60,60) }, title: "Click to mute/un-mute User "+msgSessionId }); @@ -260,7 +276,7 @@ function displayMessageOnMap(msg, olat, olong, sessid, icostr){ }); } else { // new marker var infoWindow = new google.maps.InfoWindow({ - content: msg.text, + content: pName, maxWidth: 400, disableAutoPan: true, zIndex: infoWindowZIndex @@ -271,7 +287,7 @@ function displayMessageOnMap(msg, olat, olong, sessid, icostr){ position: newPosition, map: map, draggable: false, - icon: markerImage, + icon: { url: icostr, scaledSize: new google.maps.Size(60,60) }, title: "Click to mute/un-mute User "+msgSessionId }); @@ -307,7 +323,7 @@ function displayMessageOnMap(msg, olat, olong, sessid, icostr){ function embedTweet(text) { var tweetText = "Someone wrote " + text + " on "; - var tweetUrl = "https:\/\/twitter.com\/share?url=http://idoco.github.io/map-chat&text=" + tweetText; + var tweetUrl = "https:\/\/twitter.com\/share?url=http://maps.pikabot.org/&text=" + tweetText; var width = 500, height = 300; var left = (screen.width / 2) - (width / 2); var top = (screen.height / 2) - (height / 2); diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index 94ecf8ef09..7f0047eedd 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -289,7 +289,8 @@ def _register_events(self): 'encounter_id', 'latitude', 'longitude', - 'expiration_timestamp_ms' + 'expiration_timestamp_ms', + 'pokemon_name' ) ) self.event_manager.register_event( @@ -608,6 +609,10 @@ def update_web_location(self, cells=[], lat=None, lng=None, alt=None): if alt is None: alt = self.api._position_alt + # dont cache when teleport_to + if self.api.teleporting: + return + if cells == []: location = self.position[0:2] cells = self.find_close_cells(*location) diff --git a/pokemongo_bot/api_wrapper.py b/pokemongo_bot/api_wrapper.py index a4ecaef51c..70333d3c7b 100644 --- a/pokemongo_bot/api_wrapper.py +++ b/pokemongo_bot/api_wrapper.py @@ -27,6 +27,7 @@ def __init__(self, config=None): PGoApi.__init__(self) # Set to default, just for CI... self.actual_lat, self.actual_lng, self.actual_alt = PGoApi.get_position(self) + self.teleporting = False self.noised_lat, self.noised_lng, self.noised_alt = self.actual_lat, self.actual_lng, self.actual_alt self.useVanillaRequest = False @@ -81,14 +82,15 @@ def login(self, *args): self.useVanillaRequest = False return ret_value - def set_position(self, lat, lng, alt=None): + def set_position(self, lat, lng, alt=None, teleporting=False): self.actual_lat = lat self.actual_lng = lng if None != alt: self.actual_alt = alt else: alt = self.actual_alt - + self.teleporting = teleporting + if self.config.replicate_gps_xy_noise: lat_noise = gps_noise_rng(self.config.gps_xy_noise_range) lng_noise = gps_noise_rng(self.config.gps_xy_noise_range) diff --git a/pokemongo_bot/cell_workers/__init__.py b/pokemongo_bot/cell_workers/__init__.py index 66df050917..088e11dccd 100644 --- a/pokemongo_bot/cell_workers/__init__.py +++ b/pokemongo_bot/cell_workers/__init__.py @@ -1,7 +1,5 @@ # -*- coding: utf-8 -*- -from catch_lured_pokemon import CatchLuredPokemon -from catch_visible_pokemon import CatchVisiblePokemon from evolve_pokemon import EvolvePokemon from incubate_eggs import IncubateEggs from move_to_fort import MoveToFort @@ -22,4 +20,4 @@ from update_live_inventory import UpdateLiveInventory from catch_pokemon import CatchPokemon from complete_tutorial import CompleteTutorial -from random_pause import RandomPause \ No newline at end of file +from random_pause import RandomPause diff --git a/pokemongo_bot/cell_workers/catch_lured_pokemon.py b/pokemongo_bot/cell_workers/catch_lured_pokemon.py deleted file mode 100644 index e5e4053ef7..0000000000 --- a/pokemongo_bot/cell_workers/catch_lured_pokemon.py +++ /dev/null @@ -1,85 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from pokemongo_bot.base_task import BaseTask -from pokemongo_bot.worker_result import WorkerResult -from pokemongo_bot.constants import Constants -from pokemongo_bot.cell_workers.utils import fort_details, distance -from pokemongo_bot.cell_workers.pokemon_catch_worker import PokemonCatchWorker - - -class CatchLuredPokemon(BaseTask): - SUPPORTED_TASK_API_VERSION = 1 - - def initialize(self): - self.encountered = [None] * 10 - - def add_encountered(self, pokemon): - self.encountered = self.encountered[1:] + [pokemon['encounter_id']] - - def was_encountered(self, pokemon): - if pokemon['encounter_id'] in self.encountered: - return True - return False - - def work(self): - lured_pokemon = self.get_lured_pokemon() - if len(lured_pokemon) > 0: - for pokemon in lured_pokemon: - if not self.was_encountered(pokemon): - self.catch_pokemon(pokemon) - self.add_encountered(pokemon) - return WorkerResult.RUNNING - - return WorkerResult.SUCCESS - - def get_lured_pokemon(self): - forts_in_range = [] - pokemon_to_catch = [] - forts = self.bot.get_forts(order_by_distance=True) - - if len(forts) == 0: - return [] - - for fort in forts: - distance_to_fort = distance( - self.bot.position[0], - self.bot.position[1], - fort['latitude'], - fort['longitude'] - ) - - encounter_id = fort.get('lure_info', {}).get('encounter_id', None) - if distance_to_fort < Constants.MAX_DISTANCE_FORT_IS_REACHABLE and encounter_id: - forts_in_range.append(fort) - - - for fort in forts_in_range: - details = fort_details(self.bot, fort_id=fort['id'], - latitude=fort['latitude'], - longitude=fort['longitude']) - fort_name = details.get('name', 'Unknown') - encounter_id = fort['lure_info']['encounter_id'] - - result = { - 'encounter_id': encounter_id, - 'fort_id': fort['id'], - 'fort_name': u"{}".format(fort_name), - 'latitude': fort['latitude'], - 'longitude': fort['longitude'] - } - pokemon_to_catch.append(result) - - self.emit_event( - 'lured_pokemon_found', - level='info', - formatted='Lured pokemon at fort {fort_name} ({fort_id})', - data=result - ) - return pokemon_to_catch - - def catch_pokemon(self, pokemon): - worker = PokemonCatchWorker(pokemon, self.bot, self.config) - return_value = worker.work() - - return return_value diff --git a/pokemongo_bot/cell_workers/catch_pokemon.py b/pokemongo_bot/cell_workers/catch_pokemon.py index b5380f6510..09d01e1db8 100644 --- a/pokemongo_bot/cell_workers/catch_pokemon.py +++ b/pokemongo_bot/cell_workers/catch_pokemon.py @@ -3,6 +3,7 @@ import json import os +import random from pokemongo_bot.base_task import BaseTask from pokemongo_bot.cell_workers.pokemon_catch_worker import PokemonCatchWorker @@ -17,26 +18,36 @@ class CatchPokemon(BaseTask): SUPPORTED_TASK_API_VERSION = 1 + def initialize(self): + self.pokemon = [] + def work(self): + # make sure we have SOME balls if sum([inventory.items().get(ball.value).count for ball in [Item.ITEM_POKE_BALL, Item.ITEM_GREAT_BALL, Item.ITEM_ULTRA_BALL]]) <= 0: return WorkerResult.ERROR - pokemon = [] - if self.config.get('catch_visible_pokemon', True): - pokemon = self.get_visible_pokemon() - if self.config.get('catch_lured_pokemon', True): - pokemon += self.get_lured_pokemon() + # check if we have already loaded a list + if len(self.pokemon) <= 0: + # load available pokemon by config settings + if self.config.get('catch_visible_pokemon', True): + self.get_visible_pokemon() + if self.config.get('catch_lured_pokemon', True): + self.get_lured_pokemon() + + random.shuffle(self.pokemon) - num_pokemon = len(pokemon) + num_pokemon = len(self.pokemon) if num_pokemon > 0: - pokemon = self.sort_pokemon(pokemon) - - if self.catch_pokemon(pokemon[0]) == WorkerResult.ERROR: + # try catching + if self.catch_pokemon(self.pokemon.pop()) == WorkerResult.ERROR: + # give up incase something went wrong in our catch worker (ran out of balls, etc) return WorkerResult.ERROR elif num_pokemon > 1: + # we have more pokemon to catch return WorkerResult.RUNNING + # all pokemon have been processed return WorkerResult.SUCCESS def get_visible_pokemon(self): @@ -45,33 +56,35 @@ def get_visible_pokemon(self): pokemon_to_catch = self.bot.cell['catchable_pokemons'] if len(pokemon_to_catch) > 0: - # Update web UI - user_web_catchable = os.path.join(_base_dir, 'web', 'catchable-{}.json'.format(self.bot.config.username)) - for pokemon in pokemon_to_catch: - with open(user_web_catchable, 'w') as outfile: - json.dump(pokemon, outfile) - self.emit_event( - 'catchable_pokemon', - level='debug', - data={ - 'pokemon_id': pokemon['pokemon_id'], - 'spawn_point_id': pokemon['spawn_point_id'], - 'encounter_id': pokemon['encounter_id'], - 'latitude': pokemon['latitude'], - 'longitude': pokemon['longitude'], - 'expiration_timestamp_ms': pokemon['expiration_timestamp_ms'], - } - ) + user_web_catchable = os.path.join(_base_dir, 'web', 'catchable-{}.json'.format(self.bot.config.username)) + for pokemon in pokemon_to_catch: + + # Update web UI + with open(user_web_catchable, 'w') as outfile: + json.dump(pokemon, outfile) + + self.emit_event( + 'catchable_pokemon', + level='debug', + data={ + 'pokemon_id': pokemon['pokemon_id'], + 'spawn_point_id': pokemon['spawn_point_id'], + 'encounter_id': pokemon['encounter_id'], + 'latitude': pokemon['latitude'], + 'longitude': pokemon['longitude'], + 'expiration_timestamp_ms': pokemon['expiration_timestamp_ms'], + } + ) + + self.add_pokemon(pokemon) if 'wild_pokemons' in self.bot.cell: - pokemon_to_catch += self.bot.cell['wild_pokemons'] - - return pokemon_to_catch + for pokemon in self.bot.cell['wild_pokemons']: + self.add_pokemon(pokemon) def get_lured_pokemon(self): forts_in_range = [] - pokemon_to_catch = [] - forts = self.bot.get_forts(order_by_distance=True) + forts = self.bot.get_forts(order_by_distance=False) if len(forts) == 0: return [] @@ -84,6 +97,7 @@ def get_lured_pokemon(self): fort['longitude'] ) + # See if we have an encounter at this fort encounter_id = fort.get('lure_info', {}).get('encounter_id', None) if distance_to_fort < Constants.MAX_DISTANCE_FORT_IS_REACHABLE and encounter_id: forts_in_range.append(fort) @@ -96,35 +110,29 @@ def get_lured_pokemon(self): fort_name = details.get('name', 'Unknown') encounter_id = fort['lure_info']['encounter_id'] - result = { + pokemon = { 'encounter_id': encounter_id, 'fort_id': fort['id'], 'fort_name': u"{}".format(fort_name), 'latitude': fort['latitude'], 'longitude': fort['longitude'] } - pokemon_to_catch.append(result) self.emit_event( 'lured_pokemon_found', level='info', formatted='Lured pokemon at fort {fort_name} ({fort_id})', - data=result + data=pokemon ) - return pokemon_to_catch + + self.add_pokemon(pokemon) + + def add_pokemon(self, pokemon): + if pokemon['encounter_id'] not in self.pokemon: + self.pokemon.append(pokemon) def catch_pokemon(self, pokemon): worker = PokemonCatchWorker(pokemon, self.bot, self.config) return_value = worker.work() return return_value - - def sort_pokemon(self, pokemon_list): - # Sort all by distance from current pos- eventually this should - # build graph & A* it - pokemon_list.sort( - key= - lambda x: distance(self.bot.position[0], self.bot.position[1], x['latitude'], x['longitude']) - ) - - return pokemon_list diff --git a/pokemongo_bot/cell_workers/catch_visible_pokemon.py b/pokemongo_bot/cell_workers/catch_visible_pokemon.py deleted file mode 100644 index 33ddfffcef..0000000000 --- a/pokemongo_bot/cell_workers/catch_visible_pokemon.py +++ /dev/null @@ -1,85 +0,0 @@ -import json -import os - -from pokemongo_bot.base_task import BaseTask -from pokemongo_bot.cell_workers.pokemon_catch_worker import PokemonCatchWorker -from utils import distance -from pokemongo_bot.worker_result import WorkerResult -from pokemongo_bot.base_dir import _base_dir - - -class CatchVisiblePokemon(BaseTask): - SUPPORTED_TASK_API_VERSION = 1 - - def initialize(self): - self.encountered = [None] * 10 - - def add_encountered(self, pokemon): - self.encountered = self.encountered[1:] + [pokemon['encounter_id']] - - def was_encountered(self, pokemon): - if pokemon['encounter_id'] in self.encountered: - return True - return False - - def work(self): - num_catchable_pokemon = 0 - if 'catchable_pokemons' in self.bot.cell: - num_catchable_pokemon = len(self.bot.cell['catchable_pokemons']) - - num_wild_pokemon = 0 - if 'wild_pokemons' in self.bot.cell: - num_wild_pokemon = len(self.bot.cell['wild_pokemons']) - - num_available_pokemon = num_catchable_pokemon + num_wild_pokemon - - if num_catchable_pokemon > 0: - # Sort all by distance from current pos- eventually this should - # build graph & A* it - self.bot.cell['catchable_pokemons'].sort( - key= - lambda x: distance(self.bot.position[0], self.bot.position[1], x['latitude'], x['longitude']) - ) - user_web_catchable = os.path.join(_base_dir, 'web', 'catchable-{}.json'.format(self.bot.config.username)) - for pokemon in self.bot.cell['catchable_pokemons']: - with open(user_web_catchable, 'w') as outfile: - json.dump(pokemon, outfile) - self.emit_event( - 'catchable_pokemon', - level='debug', - data={ - 'pokemon_id': pokemon['pokemon_id'], - 'spawn_point_id': pokemon['spawn_point_id'], - 'encounter_id': pokemon['encounter_id'], - 'latitude': pokemon['latitude'], - 'longitude': pokemon['longitude'], - 'expiration_timestamp_ms': pokemon['expiration_timestamp_ms'], - } - ) - if not self.was_encountered(pokemon): - self.catch_pokemon(pokemon) - self.add_encountered(pokemon) - return WorkerResult.RUNNING - - return WorkerResult.SUCCESS - - if num_available_pokemon > 0: - # Sort all by distance from current pos- eventually this should - # build graph & A* it - self.bot.cell['wild_pokemons'].sort( - key= - lambda x: distance(self.bot.position[0], self.bot.position[1], x['latitude'], x['longitude'])) - - for pokemon in self.bot.cell['wild_pokemons']: - if not self.was_encountered(pokemon): - self.catch_pokemon(pokemon) - self.add_encountered(pokemon) - return WorkerResult.RUNNING - - return WorkerResult.SUCCESS - - def catch_pokemon(self, pokemon): - worker = PokemonCatchWorker(pokemon, self.bot, self.config) - return_value = worker.work() - - return return_value diff --git a/pokemongo_bot/cell_workers/evolve_pokemon.py b/pokemongo_bot/cell_workers/evolve_pokemon.py index d94bd5467f..7309a2bef4 100644 --- a/pokemongo_bot/cell_workers/evolve_pokemon.py +++ b/pokemongo_bot/cell_workers/evolve_pokemon.py @@ -1,3 +1,5 @@ +from random import uniform + from pokemongo_bot import inventory from pokemongo_bot.human_behaviour import sleep from pokemongo_bot.inventory import Pokemon @@ -14,7 +16,8 @@ def __init__(self, bot, config): def initialize(self): self.api = self.bot.api self.evolve_all = self.config.get('evolve_all', []) - self.evolve_speed = self.config.get('evolve_speed', 2) + self.min_evolve_speed = self.config.get('min_evolve_speed', 25) + self.max_evolve_speed = self.config.get('max_evolve_speed', 30) self.first_evolve_by = self.config.get('first_evolve_by', 'cp') self.evolve_above_cp = self.config.get('evolve_above_cp', 500) self.evolve_above_iv = self.config.get('evolve_above_iv', 0.8) @@ -26,6 +29,9 @@ def _validate_config(self): if isinstance(self.evolve_all, basestring): self.evolve_all = [str(pokemon_name).strip() for pokemon_name in self.evolve_all.split(',')] + if 'evolve_speed' in self.config: + self.logger.warning("evolve_speed is deprecated, please use instead 'min_evolve_speed' and 'max_evolved_speed'.") + def work(self): if not self._should_run(): return @@ -128,7 +134,7 @@ def _execute_pokemon_evolve(self, pokemon, cache): new_pokemon = inventory.Pokemon(evolution) inventory.pokemons().add(new_pokemon) - sleep(self.evolve_speed) + sleep(uniform(self.min_evolve_speed, self.max_evolve_speed)) evolve_result = True else: # cache pokemons we can't evolve. Less server calls diff --git a/pokemongo_bot/cell_workers/follow_path.py b/pokemongo_bot/cell_workers/follow_path.py index 6e106d7397..5b285f5425 100644 --- a/pokemongo_bot/cell_workers/follow_path.py +++ b/pokemongo_bot/cell_workers/follow_path.py @@ -6,7 +6,7 @@ from pokemongo_bot.base_task import BaseTask from pokemongo_bot.cell_workers.utils import distance, i2f, format_dist from pokemongo_bot.human_behaviour import sleep -from pokemongo_bot.walkers.step_walker import StepWalker +from pokemongo_bot.walkers.walker_factory import walker_factory from pgoapi.utilities import f2i from random import uniform from utils import getSeconds @@ -32,6 +32,7 @@ def _process_config(self): self.number_lap_max = self.config.get("number_lap", -1) # if < 0, then the number is inf. self.timer_restart_min = getSeconds(self.config.get("timer_restart_min", "00:20:00")) self.timer_restart_max = getSeconds(self.config.get("timer_restart_max", "02:00:00")) + self.walker = self.config.get('walker', 'StepWalker') if self.timer_restart_min > self.timer_restart_max: raise ValueError('path timer_restart_min is bigger than path timer_restart_max') #TODO there must be a more elegant way to do it... @@ -140,7 +141,7 @@ def work(self): alt = uniform(self.bot.config.alt_min, self.bot.config.alt_max) if self.bot.config.walk_max > 0: - step_walker = StepWalker( + step_walker = walker_factory(self.walker, self.bot, lat, lng, diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py index 91219451c5..02b11be795 100644 --- a/pokemongo_bot/cell_workers/move_to_map_pokemon.py +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -228,7 +228,7 @@ def snipe(self, pokemon): api_encounter_response = catch_worker.create_encounter_api_call() time.sleep(SNIPE_SLEEP_SEC) self._teleport_back(last_position) - self.bot.api.set_position(last_position[0], last_position[1], self.alt) + self.bot.api.set_position(last_position[0], last_position[1], self.alt, False) time.sleep(SNIPE_SLEEP_SEC) self.bot.heartbeat() catch_worker.work(api_encounter_response) @@ -350,7 +350,7 @@ def _teleport_to(self, pokemon): formatted='Teleporting to {poke_name}. ({poke_dist})', data=self._pokemon_event_data(pokemon) ) - self.bot.api.set_position(pokemon['latitude'], pokemon['longitude'], self.alt) + self.bot.api.set_position(pokemon['latitude'], pokemon['longitude'], self.alt, True) self._encountered(pokemon) def _encountered(self, pokemon): diff --git a/pokemongo_bot/cell_workers/transfer_pokemon.py b/pokemongo_bot/cell_workers/transfer_pokemon.py index 62a660c380..08093dd9c7 100644 --- a/pokemongo_bot/cell_workers/transfer_pokemon.py +++ b/pokemongo_bot/cell_workers/transfer_pokemon.py @@ -29,9 +29,10 @@ def work(self): pokemon_name = Pokemons.name_for(pokemon_id) self._release_pokemon_worst_in_group(group, pokemon_name) - group = [p for p in inventory.pokemons().all() - if p.in_fort is False and p.is_favorite is False] - self._release_pokemon_worst_in_group(group, 'all') + if self.bot.config.release.get('all'): + group = [p for p in inventory.pokemons().all() + if p.in_fort is False and p.is_favorite is False] + self._release_pokemon_worst_in_group(group, 'all') def _should_work(self): return inventory.Pokemons.get_space_left() <= self.min_free_slot diff --git a/pokemongo_bot/constants.py b/pokemongo_bot/constants.py index 95d044dadf..0d8f4f3d1a 100644 --- a/pokemongo_bot/constants.py +++ b/pokemongo_bot/constants.py @@ -1,3 +1,3 @@ class Constants(object): - MAX_DISTANCE_FORT_IS_REACHABLE = 40 # meters - MAX_DISTANCE_POKEMON_IS_REACHABLE = 60 + MAX_DISTANCE_FORT_IS_REACHABLE = 38 # meters + MAX_DISTANCE_POKEMON_IS_REACHABLE = 48 diff --git a/pokemongo_bot/event_handlers/social_handler.py b/pokemongo_bot/event_handlers/social_handler.py index 7e514cdd5f..22ab9dc5cd 100644 --- a/pokemongo_bot/event_handlers/social_handler.py +++ b/pokemongo_bot/event_handlers/social_handler.py @@ -4,19 +4,30 @@ import paho.mqtt.client as mqtt import Geohash import errno +import json from socket import error as socket_error class MyMQTTClass: - def __init__(self, clientid=None): + def __init__(self, bot, clientid=None): self._mqttc = mqtt.Client(clientid) self._mqttc.on_message = self.mqtt_on_message + self.bot = bot + self.bot.mqtt_pokemon_list = [] #self._mqttc.on_connect = self.mqtt_on_connect #self._mqttc.on_publish = self.mqtt_on_publish #self._mqttc.on_subscribe = self.mqtt_on_subscribe #def mqtt_on_connect(self, mqttc, obj, flags, rc): #print "rc: "+str(rc) def mqtt_on_message(self, mqttc, obj, msg): - msg.topic+" "+str(msg.qos)+" "+str(msg.payload) + #msg.topic+" "+str(msg.qos)+" "+str(msg.payload) + pokemon = json.loads(msg.payload) + print pokemon + #if pokemon and 'encounter_id' in pokemon: + # matches = (x for x in self.bot.mqtt_pokemon_list if x.encounter_id is pokemon['encounter_id']) + # if matches and len(matches) > 0: + # print 'Match es' + # else: + # self.bot.mqtt_pokemon_list.append(pokemon) #def mqtt_on_publish(self, mqttc, obj, mid): #print "mid: "+str(mid) #def mqtt_on_subscribe(self, mqttc, obj, mid, granted_qos): @@ -26,15 +37,16 @@ def mqtt_on_message(self, mqttc, obj, msg): def publish(self, channel, message): self._mqttc.publish(channel, message) def connect_to_mqtt(self): - self._mqttc.connect("test.mosca.io", 1883, 60) - self._mqttc.subscribe("pgomapcatch/#", 0) + self._mqttc.connect("broker.pikabot.org", 1883, 60) + # Enable this line if you are doing the snip code, off stress + self._mqttc.subscribe("pgo/#", 0) def run(self): self._mqttc.loop_forever() class SocialHandler(EventHandler): def __init__(self, bot): self.bot = bot try: - self.mqttc = MyMQTTClass() + self.mqttc = MyMQTTClass(bot) self.mqttc.connect_to_mqtt() thread.start_new_thread(self.mqttc.run) except socket_error as serr: @@ -52,12 +64,16 @@ def handle_event(self, event, sender, level, formatted_msg, data): if event == 'catchable_pokemon': #self.mqttc.publish("pgomapcatch/all", str(data)) #print data - if data['pokemon_id']: + if 'pokemon_id' in data: #self.mqttc.publish("pgomapcatch/all/catchable/"+str(data['pokemon_id']), str(data)) # precision=4 mean 19545 meters, http://stackoverflow.com/questions/13836416/geohash-and-max-distance - geo_hash = Geohash.encode(data['latitude'], data['longitude'], precision=4) - self.mqttc.publish("pgomapgeo/"+geo_hash+"/"+str(data['pokemon_id']), str(data['latitude'])+","+str(data['longitude'])+","+str(data['encounter_id'])+","+str(data['pokemon_id'])) - self.mqttc.publish("pgomapcatch/all/catchable/"+str(data['pokemon_id']), str(data['latitude'])+","+str(data['longitude'])+","+str(data['encounter_id'])+","+str(data['pokemon_id'])) + #geo_hash = Geohash.encode(data['latitude'], data['longitude'], precision=4) + #self.mqttc.publish("pgomapgeo/"+geo_hash+"/"+str(data['pokemon_id']), str(data['latitude'])+","+str(data['longitude'])+","+str(data['encounter_id'])+","+str(data['pokemon_id'])+","+str(data['expiration_timestamp_ms'])+","+str(data['pokemon_name'])) + #{u'pokemon_id': 13, u'expiration_timestamp_ms': 1472017713812L, u'longitude': 4.897220519201337, u'latitude': 52.33937206069979, u'spawn_point_id': u'47c60a241ad', u'encounter_id': 13653280540966083917L} + self.mqttc.publish("pgomapcatch/all/catchable/"+str(data['pokemon_id']), str(data['latitude'])+","+str(data['longitude'])+","+str(data['encounter_id'])+","+str(data['pokemon_id'])+","+str(data['expiration_timestamp_ms'])) + print data + json_data = json.dumps(data) + self.mqttc.publish("pgo/all/catchable/"+str(data['pokemon_id']), json_data) #print 'have catchable_pokemon' #print message