def step(self, destination): # type: (Destination) -> None self.bot.fire("walking_started", coords=(destination.target_lat, destination.target_lng, destination.target_alt)) dist = distance(self.current_lat, self.current_lng, destination.target_lat, destination.target_lng) if destination.name: logger.log("Walking towards {} ({} away, eta {})".format( destination.name, format_dist(dist, self.config.distance_unit), format_time(len(destination.steps))), prefix="Navigation") for step in destination.steps: self._step_to(*step) yield step if destination.name: logger.log("Arrived at {} ({} away)".format( destination.name, format_dist(dist, self.config.distance_unit)), prefix="Navigation") self.bot.fire("walking_finished", coords=(destination.target_lat, destination.target_lng, destination.target_alt))
def work(self): lat = self.fort.latitude lng = self.fort.longitude unit = self.config.distance_unit # Unit to use when printing formatted distance fort_id = self.fort.fort_id dist = distance(self.position[0], self.position[1], lat, lng) self.api_wrapper.fort_details(fort_id=fort_id, latitude=lat, longitude=lng) response_dict = self.api_wrapper.call() if response_dict is None: return fort_details = response_dict["fort"] fort_name = fort_details.fort_name self.bot.fire("fort_found", fort_name=fort_name, fort_distance=format_dist(dist, unit)) if dist > 0: self.bot.fire("fort_moving", fort_name=fort_name) position = (lat, lng, 0.0) if self.config.walk > 0: self.stepper.walk_to(self.config.walk, *position) else: self.api_wrapper.set_position(*position) self.api_wrapper.player_update(latitude=lat, longitude=lng) sleep(2) self.bot.fire("fort_arrived", fort_name=fort_name)
def work(self): lat = self.fort.latitude lng = self.fort.longitude unit = self.config.distance_unit # Unit to use when printing formatted distance fort_id = self.fort.fort_id dist = distance(self.position[0], self.position[1], lat, lng) self.api_wrapper.fort_details(fort_id=fort_id, latitude=lat, longitude=lng) response_dict = self.api_wrapper.call() if response_dict is None: return fort_details = response_dict["fort"] fort_name = fort_details.fort_name logger.log(u"[#] Found fort {} at distance {}".format(fort_name, format_dist(dist, unit))) if dist > 0: logger.log(u"[#] Moving closer to {}".format(fort_name)) position = (lat, lng, 0.0) if self.config.walk > 0: self.stepper.walk_to(self.config.walk, *position) else: self.api_wrapper.set_position(*position) self.api_wrapper.player_update(latitude=lat, longitude=lng) sleep(2) logger.log(u"[#] Now at Pokestop: {}".format(fort_name))
def work(self): lat = self.fort["latitude"] lng = self.fort["longitude"] unit = self.config.distance_unit # Unit to use when printing formatted distance fort_id = self.fort["id"] dist = distance(self.position[0], self.position[1], lat, lng) logger.log("[#] Found fort {} at distance {}".format(fort_id, format_dist(dist, unit))) if dist > 0: logger.log("[#] Need to move closer to Pokestop") position = (lat, lng, 0.0) if self.config.walk > 0: self.stepper.walk_to(self.config.walk, *position) else: self.api.set_position(*position) self.api.player_update(latitude=lat, longitude=lng) logger.log("[#] Arrived at Pokestop") sleep(2) self.api.fort_details(fort_id=self.fort["id"], latitude=lat, longitude=lng) response_dict = self.api.call() if response_dict is None: return fort_details = response_dict.get("responses", {}).get("FORT_DETAILS", {}) fort_name = fort_details.get("name") if fort_details.get("name") else "Unknown" logger.log(u"[#] Now at Pokestop: " + fort_name)
def step(self, destination): # type: (Destination) -> List[(float, float, float)] dist = distance(self.current_lat, self.current_lng, destination.target_lat, destination.target_lng) if destination.name: self.logger.log("Walking towards {} ({} away, eta {})".format(destination.name, format_dist(dist, self.config["mapping"]["distance_unit"]), format_time(destination.get_step_count())), prefix="Navigation") for step in destination.step(): if distance(self.current_lat, self.current_lng, destination.target_lat, destination.target_lng) < 30: break self._step_to(*step) yield step if destination.name: self.logger.log("Arrived at {} ({} away)".format(destination.name, format_dist(dist, self.config["mapping"]["distance_unit"])), prefix="Navigation")
def test_format_dist(): assert (format_dist(1.234567, 'mm')) == "1234.57mm" assert (format_dist(1.234567, 'cm')) == "123.46cm" assert (format_dist(1.234567, 'm')) == "1.23m" assert (format_dist(123.4567, 'km')) == "0.12km" assert (format_dist(123.4567, 'ft')) == "405.04ft" assert (format_dist(123.4567, 'yd')) == "135.01yd" assert (format_dist(1234.567, 'mi')) == "0.77mi"
def step(self, destination): # type: (Destination) -> None self.bot.fire("walking_started", coords=(destination.target_lat, destination.target_lng, destination.target_alt)) dist = distance(self.current_lat, self.current_lng, destination.target_lat, destination.target_lng) if destination.name: logger.log("Walking towards {} ({} away, eta {})".format(destination.name, format_dist(dist, self.config.distance_unit), format_time(len(destination.steps))), prefix="Navigation") for step in destination.steps: self._step_to(*step) yield step if destination.name: logger.log("Arrived at {} ({} away)".format(destination.name, format_dist(dist, self.config.distance_unit)), prefix="Navigation") self.bot.fire("walking_finished", coords=(destination.target_lat, destination.target_lng, destination.target_alt))
def work(self): if self.config.fill_incubators: self.api_wrapper.get_inventory() response_dict = self.api_wrapper.call() eggs = [egg.unique_id for egg in response_dict["eggs"] if egg.egg_incubator_id == ""] incubators = [incu.unique_id for incu in response_dict["egg_incubators"] if incu.pokemon_id == 0 and ( self.config.use_all_incubators or incu.item_id == 901)] for incubator_unique_id in incubators: if len(eggs) > 0: self.api_wrapper.use_item_egg_incubator(item_id=incubator_unique_id, pokemon_id=eggs.pop()) self.api_wrapper.call() logger.log("[+] Put an egg into an incubator", "green") else: logger.log("[+] No more free incubators", "yellow") lat = self.fort.latitude lng = self.fort.longitude unit = self.config.distance_unit # Unit to use when printing formatted distance fort_id = self.fort.fort_id dist = distance(self.position[0], self.position[1], lat, lng) self.api_wrapper.fort_details(fort_id=fort_id, latitude=lat, longitude=lng) response_dict = self.api_wrapper.call() if response_dict is None: return fort_details = response_dict["fort"] fort_name = fort_details.fort_name logger.log(u"[#] Found fort {} at distance {}".format(fort_name, format_dist(dist, unit))) if dist > 0: logger.log(u"[#] Moving closer to {}".format(fort_name)) position = (lat, lng, 0.0) if self.config.walk > 0: self.stepper.walk_to(self.config.walk, *position) else: self.api_wrapper.set_position(*position) self.api_wrapper.player_update(latitude=lat, longitude=lng) sleep(2) logger.log(u"[#] Now at Pokestop: {}".format(fort_name))
def spin_pokestop(bot, pokestop=None): # type: (PokemonGoBot, Optional[List[Fort]]) -> None if pokestop is None: return def log(text, color="black"): logger.log(text, color=color, prefix="PokeStop") fort_id = pokestop.fort_id latitude = pokestop.latitude longitude = pokestop.longitude player_latitude = bot.stepper.current_lat player_longitude = bot.stepper.current_lng fort_details = bot.api_wrapper.fort_details(fort_id=pokestop.fort_id, latitude=pokestop.latitude, longitude=pokestop.longitude).call() dist = distance(bot.stepper.current_lat, bot.stepper.current_lng, pokestop.latitude, pokestop.longitude) log("Nearby PokeStop found \"{}\" ({} away)".format(fort_details["fort"].fort_name, format_dist(dist, bot.config["mapping"]["distance_unit"])), color="yellow") log("Spinning...", color="yellow") sleep(3) bot.api_wrapper.fort_search(fort_id=fort_id, fort_latitude=latitude, fort_longitude=longitude, player_latitude=player_latitude, player_longitude=player_longitude) response = bot.api_wrapper.call() if response is None: log("Got empty response from the API. Skipping.", color="red") return # TODO: Fix this to use a response object spin_details = response["FORT_SEARCH"] spin_result = spin_details.get("result") if spin_result == 1: log("Loot: ", "green") manager.fire_with_context('pokestop_visited', bot, pokestop=pokestop) experience_awarded = spin_details.get("experience_awarded", False) if experience_awarded: log("+ {} XP".format(experience_awarded), "green") items_awarded = spin_details.get("items_awarded", []) if len(items_awarded) > 0: tmp_count_items = {} for item in items_awarded: item_id = item["item_id"] if item_id not in tmp_count_items: tmp_count_items[item_id] = item["item_count"] else: tmp_count_items[item_id] += item["item_count"] for item_id, item_count in tmp_count_items.items(): item_name = bot.item_list[item_id] log("+ {} {}{}".format(item_count, item_name, "s" if item_count > 1 else ""), "green") else: log("Nothing found.", "yellow") pokestop_cooldown = spin_details.get("cooldown_complete_timestamp_ms") if pokestop_cooldown: seconds_since_epoch = time.time() cooldown_time = str(format_time((pokestop_cooldown / 1000) - seconds_since_epoch)) log("PokeStop is on cooldown for {}.".format(cooldown_time)) # Update the cooldown manually pokestop.cooldown_timestamp_ms = pokestop_cooldown if not items_awarded and not experience_awarded and not pokestop_cooldown: log("Might be softbanned, try again later.", "red") elif spin_result == 2: log("PokeStop is out of range.", "red") elif spin_result == 3: log("PokeStop is already on cooldown.", "red") pokestop_cooldown = spin_details.get("cooldown_complete_timestamp_ms") if pokestop_cooldown: seconds_since_epoch = time.time() cooldown_time = str(format_time((pokestop_cooldown / 1000) - seconds_since_epoch)) log("PokeStop is already on cooldown for {}.".format(cooldown_time), "red") elif spin_result == 4: manager.fire_with_context('pokestop_visited', bot, pokestop=pokestop) experience_awarded = spin_details.get("experience_awarded", False) if experience_awarded: log("Loot: ", "green") log("+ {} XP".format(experience_awarded), "green") log("Item bag is full.", "red") bot.fire("item_bag_full") if not experience_awarded and not pokestop_cooldown: log("Might be softbanned, try again later.", "red") else: log("I don't know what happened! Maybe servers are down?", "red") sleep(2)
def navigate(self, map_cells): # type: (List[Cell]) -> None try: camp_site = self.camping_sites[self.pointer] lat, lng = camp_site position = (lat, lng, 0.0) unit = self.config.distance_unit # Unit to use when printing formatted distance dist = floor(distance(self.stepper.current_lat, self.stepper.current_lng, lat, lng)) # Given the random delta we add to the if dist > 0: logger.log( "[#] Moving to camping position at {},{} at distance {}".format(lat, lng, format_dist(dist, unit))) self.stepper.walk_to(*position) self.stepper.snap_to(*position) else: # fire any events on these cells logger.log("[#] Camping on {},{}".format(lat, lng)) position_map_cells = self.bot.mapper.get_cells(lat, lng) self.bot.work_on_cells(position_map_cells) sleep(5) except KeyError: logger.log("[#] No campsite location found", color="red")
def spin_pokestop(self, bot, pokestop=None): # type: (PokemonGoBot, Optional[List[Fort]]) -> None if pokestop is None: return fort_id = pokestop.fort_id latitude = pokestop.latitude longitude = pokestop.longitude player_latitude = bot.stepper.current_lat player_longitude = bot.stepper.current_lng fort_details = bot.api_wrapper.fort_details( fort_id=pokestop.fort_id, latitude=pokestop.latitude, longitude=pokestop.longitude).call() dist = distance(bot.stepper.current_lat, bot.stepper.current_lng, pokestop.latitude, pokestop.longitude) self.log("Nearby PokeStop found \"{}\" ({} away)".format( fort_details["fort"].fort_name, format_dist(dist, bot.config["mapping"]["distance_unit"])), color="yellow") self.log("Spinning...", color="yellow") sleep(3) bot.api_wrapper.fort_search(fort_id=fort_id, fort_latitude=latitude, fort_longitude=longitude, player_latitude=player_latitude, player_longitude=player_longitude) response = bot.api_wrapper.call() if response is None: self.log("Got empty response from the API. Skipping.", color="red") return # TODO: Fix this to use a response object spin_details = response["FORT_SEARCH"] spin_result = spin_details.get("result") if spin_result == 1: self.log("Loot: ", "green") self.event_manager.fire_with_context('pokestop_visited', bot, pokestop=pokestop) experience_awarded = spin_details.get("experience_awarded", False) if experience_awarded: self.log("+ {} XP".format(experience_awarded), "green") items_awarded = spin_details.get("items_awarded", []) if len(items_awarded) > 0: tmp_count_items = {} for item in items_awarded: item_id = item["item_id"] if item_id not in tmp_count_items: tmp_count_items[item_id] = item["item_count"] else: tmp_count_items[item_id] += item["item_count"] for item_id, item_count in tmp_count_items.items(): item_name = bot.item_list[item_id] self.log( "+ {} {}{}".format(item_count, item_name, "s" if item_count > 1 else ""), "green") else: self.log("Nothing found.", "yellow") pokestop_cooldown = spin_details.get( "cooldown_complete_timestamp_ms") if pokestop_cooldown: seconds_since_epoch = time.time() cooldown_time = str( format_time((pokestop_cooldown / 1000) - seconds_since_epoch)) self.log( "PokeStop is on cooldown for {}.".format(cooldown_time)) # Update the cooldown manually pokestop.cooldown_timestamp_ms = pokestop_cooldown if not items_awarded and not experience_awarded and not pokestop_cooldown: self.log("Might be softbanned, try again later.", "red") elif spin_result == 2: self.log("PokeStop is out of range.", "red") elif spin_result == 3: self.log("PokeStop is already on cooldown.", "red") pokestop_cooldown = spin_details.get( "cooldown_complete_timestamp_ms") if pokestop_cooldown: seconds_since_epoch = time.time() cooldown_time = str( format_time((pokestop_cooldown / 1000) - seconds_since_epoch)) self.log( "PokeStop is already on cooldown for {}.".format( cooldown_time), "red") elif spin_result == 4: self.event_manager.fire_with_context('pokestop_visited', bot, pokestop=pokestop) experience_awarded = spin_details.get("experience_awarded", False) if experience_awarded: self.log("Loot: ", "green") self.log("+ {} XP".format(experience_awarded), "green") self.log("Item bag is full.", "red") bot.fire("item_bag_full") if not experience_awarded and not pokestop_cooldown: self.log("Might be softbanned, try again later.", "red") else: self.log("I don't know what happened! Maybe servers are down?", "red") sleep(2)
def navigate(self, map_cells): # type: (List[Cell]) -> None while self.pointer < len(self.waypoints)-1: waypoint = self.waypoints[self.pointer] if waypoint is None: self.pointer += 1 continue lat, lng = waypoint position = (lat, lng, 0.0) unit = self.config.distance_unit # Unit to use when printing formatted distance dist = distance(self.stepper.current_lat, self.stepper.current_lng, lat, lng) logger.log("[#] Moving to waypoint at {},{} at distance {}".format(lat, lng, format_dist(dist, unit))) self.stepper.walk_to(*position) self.pointer += 1 self.pointer = 0