def _move_to_pokemon_througt_fort(self, fort, pokemon):
        """Moves trainer towards a fort before a Pokemon.

        Args:
            fort

        Returns:
            StepWalker
        """

        nearest_fort = fort

        lat = nearest_fort['latitude']
        lng = nearest_fort['longitude']
        fortID = nearest_fort['id']
        details = fort_details(self.bot, fortID, lat, lng)
        fort_name = details.get('name', 'Unknown')

        unit = self.bot.config.distance_unit  # Unit to use when printing formatted distance

        dist = distance(
            self.bot.position[0],
            self.bot.position[1],
            lat,
            lng
        )

        if dist > Constants.MAX_DISTANCE_FORT_IS_REACHABLE:
            pokemon_throught_fort_event_data = {
                'fort_name': u"{}".format(fort_name),
                'distance': format_dist(dist, unit),
                'poke_name': pokemon['name'],
                'poke_dist': (format_dist(pokemon['dist'], self.unit))
            }

            self.emit_event(
                'moving_to_pokemon_throught_fort',
                formatted="Moving towards {poke_name} - {poke_dist}  through pokestop  {fort_name} - {distance}",
                data= pokemon_throught_fort_event_data
            )
        else:
            self.emit_event(
                'arrived_at_fort',
                formatted='Arrived at fort.'
            )

	return walker_factory(self.walker,
            self.bot,
            lat,
            lng
        )
Exemple #2
0
    def _pokemon_event_data(self, pokemon):
        """Generates parameters used for the Bot's event manager.

        Args:
            pokemon: Pokemon object

        Returns:
            Dictionary with Pokemon's info.
        """
        now = int(time.time())
        return {
            'poke_name': pokemon['name'],
            'poke_dist': (format_dist(pokemon['dist'], self.unit)),
            'poke_lat': pokemon['latitude'],
            'poke_lon': pokemon['longitude'],
            'disappears_in': (format_time(pokemon['disappear_time'] - now))
        }
    def work(self):
        # check for pokeballs (excluding masterball)
        pokeballs = self.bot.item_inventory_count(1)
        superballs = self.bot.item_inventory_count(2)
        ultraballs = self.bot.item_inventory_count(3)

        if (pokeballs + superballs + ultraballs) < 1:
            return WorkerResult.SUCCESS

        self.update_map_location()
        self.dump_caught_pokemon()

        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']:
            pokemon_list.sort(key=lambda x: x['is_vip'], reverse=True)

        if len(pokemon_list) < 1:
            return WorkerResult.SUCCESS

        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)

        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,
            self.bot.config.walk,
            pokemon['latitude'],
            pokemon['longitude']
        )

        if not step_walker.step():
            return WorkerResult.RUNNING

        logger.log('Arrived at {}'.format(pokemon['name']))
        self.add_caught(pokemon)
        return WorkerResult.SUCCESS
    def _pokemon_event_data(self, pokemon):
        """Generates parameters used for the Bot's event manager.

        Args:
            pokemon: Pokemon object

        Returns:
            Dictionary with Pokemon's info.
        """
        now = int(time.time())
        return {
            'poke_name': pokemon['name'],
            'poke_dist': (format_dist(pokemon['dist'], self.unit)),
            'poke_lat': pokemon['latitude'],
            'poke_lon': pokemon['longitude'],
            'disappears_in': (format_time(pokemon['disappear_time'] - now))
        }
    def snipe(self, pokemon):
        last_position = self.bot.position[0:2]

        self.bot.heartbeat()

        logger.log('Teleporting to {} ({})'.format(pokemon['name'], format_dist(pokemon['dist'], self.unit)), 'green')
        self.bot.api.set_position(pokemon['latitude'], pokemon['longitude'], 0)

        logger.log('Encounter pokemon', 'green')
        catch_worker = PokemonCatchWorker(pokemon, self.bot)
        api_encounter_response = catch_worker.create_encounter_api_call()

        time.sleep(2)
        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()

        catch_worker.work(api_encounter_response)
        self.add_caught(pokemon)

        return WorkerResult.SUCCESS
Exemple #6
0
    def work(self):
        # If done or wandering allow the next task to run
        if self.status == STATUS_FINISHED:
            return WorkerResult.SUCCESS

        if self.disable_while_hunting and hasattr(self.bot,
                                                  "hunter_locked_target"):
            if self.bot.hunter_locked_target != None:
                return WorkerResult.SUCCESS

        if time.time() < self.waiting_end_time:
            if self.status == STATUS_WANDERING:
                return WorkerResult.SUCCESS
            elif self.status == STATUS_LOITERING:
                return WorkerResult.RUNNING

        last_lat, last_lng, last_alt = self.bot.position

        point = self.points[self.ptr]
        lat = point['lat']
        lng = point['lng']

        if 'alt' in point:
            alt = float(point['alt'])
        else:
            alt = uniform(self.bot.config.alt_min, self.bot.config.alt_max)

        if self.bot.config.walk_max > 0:
            step_walker = walker_factory(self.walker, self.bot, lat, lng, alt)

            is_at_destination = False
            if step_walker.step():
                is_at_destination = True

        else:
            self.bot.api.set_position(lat, lng, alt)

        dist = distance(last_lat, last_lng, lat, lng)

        if not self.disable_location_output:
            self.emit_event(
                'position_update',
                formatted=
                "Walking from {last_position} to {current_position}, distance left: ({distance} {distance_unit}) ..",
                data={
                    'last_position': (last_lat, last_lng, last_alt),
                    'current_position':
                    point["location"],
                    'distance':
                    format_dist(dist, self.distance_unit, self.append_unit),
                    'distance_unit':
                    self.distance_unit
                })

        if (self.bot.config.walk_min > 0 and is_at_destination) or (
                self.status in [STATUS_WANDERING, STATUS_LOITERING]
                and time.time() >= self.waiting_end_time):
            if "loiter" in point and self.status != STATUS_LOITERING:
                self.logger.info("Loitering for {} seconds...".format(
                    point["loiter"]))
                self.status = STATUS_LOITERING
                self.waiting_end_time = time.time() + point["loiter"]
                return WorkerResult.RUNNING
            if "wander" in point and self.status != STATUS_WANDERING:
                self.logger.info("Wandering for {} seconds...".format(
                    point["wander"]))
                self.status = STATUS_WANDERING
                self.waiting_end_time = time.time() + point["wander"]
                return WorkerResult.SUCCESS
            if (self.ptr + 1) == len(self.points):
                if self.path_mode == 'single':
                    self.status = STATUS_FINISHED
                    return WorkerResult.SUCCESS
                self.ptr = 0
                if self.path_mode == 'linear':
                    self.points = list(reversed(self.points))
                if self.number_lap_max >= 0:
                    self.number_lap += 1
                    self.emit_event(
                        'path_lap_update',
                        formatted=
                        "number lap : {number_lap} / {number_lap_max}",
                        data={
                            'number_lap': str(self.number_lap),
                            'number_lap_max': str(self.number_lap_max)
                        })
                    if self.number_lap >= self.number_lap_max:
                        self.endLaps()
            else:
                self.ptr += 1

        self.status = STATUS_MOVING
        return WorkerResult.RUNNING
    def work(self):
        # If done or loitering allow the next task to run
        if self.status == STATUS_FINISHED:
            return WorkerResult.SUCCESS

        if self.status == STATUS_LOITERING and time.time() < self.loiter_end_time:
            return WorkerResult.SUCCESS

        last_lat, last_lng, last_alt = self.bot.position

        point = self.points[self.ptr]
        lat = point['lat']
        lng = point['lng']

        if 'alt' in point:
            alt = float(point['alt'])
        else:
            alt = uniform(self.bot.config.alt_min, self.bot.config.alt_max)

        if self.bot.config.walk_max > 0:
            step_walker = walker_factory(self.walker,
                self.bot,
                lat,
                lng,
                alt
            )

            is_at_destination = False
            if step_walker.step():
                is_at_destination = True

        else:
            self.bot.api.set_position(lat, lng, alt)

        dist = distance(
            last_lat,
            last_lng,
            lat,
            lng
        )

        self.emit_event(
            'position_update',
            formatted="Walking from {last_position} to {current_position}, distance left: ({distance} {distance_unit}) ..",
            data={
                'last_position': (last_lat, last_lng, last_alt),
                'current_position': (lat, lng, alt),
                'distance': format_dist(dist,self.distance_unit,self.append_unit),
                'distance_unit': self.distance_unit
            }
        )
        
        if dist <= 1 or (self.bot.config.walk_min > 0 and is_at_destination) or (self.status == STATUS_LOITERING and time.time() >= self.loiter_end_time):
            if "loiter" in point and self.status != STATUS_LOITERING:
                self.logger.info("Loitering for {} seconds...".format(point["loiter"]))
                self.status = STATUS_LOITERING
                self.loiter_end_time = time.time() + point["loiter"]
                return WorkerResult.SUCCESS
            if (self.ptr + 1) == len(self.points):
                if self.path_mode == 'single':
                    self.status = STATUS_FINISHED
                    return WorkerResult.SUCCESS
                self.ptr = 0
                if self.path_mode == 'linear':
                    self.points = list(reversed(self.points))
                if self.number_lap_max >= 0:
                    self.number_lap+=1
                    self.emit_event(
                        'path_lap_update',
                        formatted="number lap : {number_lap} / {number_lap_max}",
                        data={
                            'number_lap': str(self.number_lap),
                            'number_lap_max': str(self.number_lap_max)
                        }
                    )
                    if self.number_lap >= self.number_lap_max:
                        self.endLaps()
            else:
                self.ptr += 1
        
        self.status = STATUS_MOVING
        return WorkerResult.RUNNING
    def work(self):
        point = self.points[self.ptr]
        self.cnt += 1

        if self.bot.config.walk > 0:
            step_walker = StepWalker(
                self.bot,
                self.bot.config.walk,
                point['lat'],
                point['lng']
            )

            dist = distance(
                self.bot.api._position_lat,
                self.bot.api._position_lng,
                point['lat'],
                point['lng']
            )

            if self.cnt == 1:
                logger.log(
                    'Walking from ' + str((self.bot.api._position_lat,
                    self.bot.api._position_lng)) + " to " + str([point['lat'], point['lng']]) + " " + format_dist(dist,
                                                                                                   self.bot.config.distance_unit))

            if step_walker.step():
                step_walker = None
        else:
            self.bot.api.set_position(point['lat'], point['lng'])

        if distance(
                    self.bot.api._position_lat,
                    self.bot.api._position_lng,
                    point['lat'],
                    point['lng']
                ) <= 1 or (self.bot.config.walk > 0 and step_walker == None):
            if self.ptr + self.direction >= len(self.points) or self.ptr + self.direction <= -1:
                self.direction *= -1
            if len(self.points) != 1:
                self.ptr += self.direction
            else:
                self.ptr = 0
            self.cnt = 0

        return [point['lat'], point['lng']]