コード例 #1
0
ファイル: __init__.py プロジェクト: piersimak/GYARADOS
    def work_on_cell(self, cell, position, include_fort_on_path):
        self._filter_ignored_pokemons(cell)

        if (self.config.mode == "all" or self.config.mode ==
                "poke") and 'catchable_pokemons' in cell and len(cell[
                    'catchable_pokemons']) > 0:
            logger.log('[#] Something rustles nearby!')
            # Sort all by distance from current pos- eventually this should
            # build graph & A* it
            cell['catchable_pokemons'].sort(
                key=
                lambda x: distance(self.position[0], self.position[1], x['latitude'], x['longitude']))
            for pokemon in cell['catchable_pokemons']:
                with open('web/catchable-%s.json' %
                          (self.config.username), 'w') as outfile:
                    json.dump(pokemon, outfile)

                if self.catch_pokemon(pokemon) == PokemonCatchWorker.NO_POKEBALLS:
                    break
                with open('web/catchable-%s.json' %
                          (self.config.username), 'w') as outfile:
                    json.dump({}, outfile)
        if (self.config.mode == "all" or self.config.mode == "poke"
            ) and 'wild_pokemons' in cell and len(cell['wild_pokemons']) > 0:
            # Sort all by distance from current pos- eventually this should
            # build graph & A* it
            cell['wild_pokemons'].sort(
                key=
                lambda x: distance(self.position[0], self.position[1], x['latitude'], x['longitude']))
            for pokemon in cell['wild_pokemons']:
                if self.catch_pokemon(pokemon) == PokemonCatchWorker.NO_POKEBALLS:
                    break
        if (self.config.mode == "all" or
                self.config.mode == "farm") and include_fort_on_path:
            if 'forts' in cell:
                # Only include those with a lat/long
                forts = [fort
                         for fort in cell['forts']
                         if 'latitude' in fort and 'type' in fort]
		gyms = [gym for gym in cell['forts'] if 'gym_points' in gym]

                # Sort all by distance from current pos- eventually this should
                # build graph & A* it
                forts.sort(key=lambda x: distance(self.position[
                           0], self.position[1], x['latitude'], x['longitude']))
                for fort in forts:
                    worker = MoveToFortWorker(fort, self)
                    worker.work()

                    worker = SeenFortWorker(fort, self)
                    hack_chain = worker.work()
                    if hack_chain > 10:
                        #print('need a rest')
                        break
コード例 #2
0
    def work_on_cell(self, cell, position, include_fort_on_path):
        if self.config.evolve_all:
            # Run evolve all once. Flip the bit.
            print('[#] Attempting to evolve all pokemons ...')
            worker = EvolveAllWorker(self)
            worker.work()
            self.config.evolve_all = []

        self._filter_ignored_pokemons(cell)

        if (self.config.mode == "all" or self.config.mode ==
                "poke") and 'catchable_pokemons' in cell and len(cell[
                    'catchable_pokemons']) > 0:
            self.logger.info('[#] Something rustles nearby!')
            # Sort all by distance from current pos- eventually this should
            # build graph & A* it
            cell['catchable_pokemons'].sort(
                key=
                lambda x: distance(self.position[0], self.position[1], x['latitude'], x['longitude']))

        if (self.config.mode == "all" or self.config.mode == "poke"
            ) and 'wild_pokemons' in cell and len(cell['wild_pokemons']) > 0:
            # Sort all by distance from current pos- eventually this should
            # build graph & A* it
            cell['wild_pokemons'].sort(
                key=
                lambda x: distance(self.position[0], self.position[1], x['latitude'], x['longitude']))
            for pokemon in cell['wild_pokemons']:
                if self.catch_pokemon(pokemon) == PokemonCatchWorker.NO_POKEBALLS:
                    break
        if (self.config.mode == "all" or
                self.config.mode == "farm") and include_fort_on_path:
            if 'forts' in cell:
                # Only include those with a lat/long
                forts = [fort
                         for fort in cell['forts']
                         if 'latitude' in fort and 'type' in fort]
                gyms = [gym for gym in cell['forts'] if 'gym_points' in gym]

                # Sort all by distance from current pos- eventually this should
                # build graph & A* it
                forts.sort(key=lambda x: distance(self.position[
                           0], self.position[1], x['latitude'], x['longitude']))
                for fort in forts:
                    worker = MoveToFortWorker(fort, self)
                    worker.work()

                    worker = SeenFortWorker(fort, self)
                    hack_chain = worker.work()
                    if hack_chain > 10:
                        #print('need a rest')
                        break
コード例 #3
0
ファイル: __init__.py プロジェクト: kmcgaire/PokemonGoBot
    def find_close_cells(self, lat, lng):
        cellid = get_cellid(lat, lng)
        timestamp = [0, ] * len(cellid)

        self.api.get_map_objects(
            latitude=f2i(lat),
            longitude=f2i(lng),
            since_timestamp_ms=timestamp,
            cell_id=cellid
        )
        response_dict = self.api.call()
        map_objects = response_dict.get('responses', {}).get('GET_MAP_OBJECTS', {})
        status = map_objects.get('status', None)

        map_cells = []
        if status and status == 1:
            map_cells = map_objects['map_cells']
            position = (lat, lng, 0)
            map_cells.sort(
                key=lambda x: distance(
                    lat,
                    lng,
                    x['forts'][0]['latitude'],
                    x['forts'][0]['longitude']) if x.get('forts', []) else 1e6
            )
        return map_cells
コード例 #4
0
ファイル: stepper.py プロジェクト: Cyberschorsch/OpenPoGoBot
    def _work_at_position(self, lat, long, alt, pokemon_only=False):
        cell_id = get_cell_id_from_latlong(lat, long)
        timestamp = [0, ] * len(cell_id)
        self.api.get_map_objects(latitude=f2i(lat),
                                 longitude=f2i(long),
                                 since_timestamp_ms=timestamp,
                                 cell_id=cell_id)

        response_dict = self.api.call()
        # Passing data through last-location and location
        map_objects = response_dict.get("responses", {}).get("GET_MAP_OBJECTS")
        if map_objects is not None:
            with open("web/location-{}.json".format(self.config.username), "w") as outfile:
                json.dump({"lat": lat, "lng": long, "cells": map_objects.get("map_cells")}, outfile)
            with open("data/last-location-{}.json".format(self.config.username), "w") as outfile:
                outfile.truncate()
                json.dump({"lat": lat, "lng": long}, outfile)
            if "status" in map_objects:
                if map_objects.get("status") is 1:
                    map_cells = map_objects.get("map_cells")
                    position = lat, long, alt
                # Sort all by distance from current pos - eventually this should build graph and A* it
                map_cells.sort(key=lambda x: distance(lat, long, x["forts"][0]["latitude"], x["forts"][0]["longitude"]) if "forts" in x and x["forts"] != [] else 1e6)
                for cell in map_cells:
                    self.bot.work_on_cell(cell, position, pokemon_only)
コード例 #5
0
ファイル: step_walker.py プロジェクト: Bashin/PokemonGo-Bot
    def __init__(self, bot, dest_lat, dest_lng):
        self.bot = bot
        self.api = bot.api

        self.initLat, self.initLng = self.bot.position[0:2]

        self.dist = distance(
            self.initLat,
            self.initLng,
            dest_lat,
            dest_lng
        )

        self.speed = self.bot.config.walk_max - random() * (self.bot.config.walk_max - self.bot.config.walk_min)

        self.destLat = dest_lat
        self.destLng = dest_lng
        self.totalDist = max(1, self.dist)

        if self.speed == 0:
            self.steps = 1
        else:
            self.steps = (self.dist + 0.0) / (self.speed + 0.0)

        if self.dist < self.speed or int(self.steps) <= 1:
            self.dLat = 0
            self.dLng = 0
            self.magnitude = 0
        else:
            self.dLat = (dest_lat - self.initLat) / int(self.steps)
            self.dLng = (dest_lng - self.initLng) / int(self.steps)
            self.magnitude = self._pythagorean(self.dLat, self.dLng)
コード例 #6
0
    def _walk_to(self, speed, lat, lng, alt):
        dist = distance(
            i2f(self.api._position_lat), i2f(self.api._position_lng), lat, lng)
        steps = (dist + 0.0) / (speed + 0.0)  # may be rational number
        intSteps = int(steps)
        residuum = steps - intSteps
        self.logger.info('[#] Walking from ' + str((i2f(self.api._position_lat), i2f(
            self.api._position_lng))) + " to " + str(str((lat, lng))) +
                   " for approx. " + str(format_time(ceil(steps))))
        if steps != 0:
            dLat = (lat - i2f(self.api._position_lat)) / steps
            dLng = (lng - i2f(self.api._position_lng)) / steps

            for i in range(intSteps):
                cLat = i2f(self.api._position_lat) + \
                    dLat + random_lat_long_delta()
                cLng = i2f(self.api._position_lng) + \
                    dLng + random_lat_long_delta()
                self.api.set_position(cLat, cLng, alt)
                self.bot.heartbeat()
                sleep(1)  # sleep one second plus a random delta
                self._work_at_position(
                    i2f(self.api._position_lat), i2f(self.api._position_lng),
                    alt, False)

            self.api.set_position(lat, lng, alt)
            self.bot.heartbeat()
            self.logger.info("[#] Finished walking")
コード例 #7
0
    def __init__(self, bot, dest_lat, dest_lng):
        self.bot = bot
        self.api = bot.api

        self.initLat, self.initLng = self.bot.position[0:2]

        self.dist = distance(self.initLat, self.initLng, dest_lat, dest_lng)

        self.speed = self.bot.config.walk_max - random() * (
            self.bot.config.walk_max - self.bot.config.walk_min)

        self.destLat = dest_lat
        self.destLng = dest_lng
        self.totalDist = max(1, self.dist)

        if self.speed == 0:
            self.steps = 1
        else:
            self.steps = (self.dist + 0.0) / (self.speed + 0.0)

        if self.dist < self.speed or int(self.steps) <= 1:
            self.dLat = 0
            self.dLng = 0
            self.magnitude = 0
        else:
            self.dLat = (dest_lat - self.initLat) / int(self.steps)
            self.dLng = (dest_lng - self.initLng) / int(self.steps)
            self.magnitude = self._pythagorean(self.dLat, self.dLng)
コード例 #8
0
ファイル: step_walker.py プロジェクト: kmcgaire/PokemonGoBot
    def __init__(self, bot, speed, destLat, destLng):
        self.bot = bot
        self.api = bot.api

        self.initLat, self.initLng = self.bot.position[0:2]

        self.dist = distance(
            self.initLat,
            self.initLng,
            destLat,
            destLng
        )

        self.speed = speed

        self.destLat = destLat
        self.destLng = destLng
        self.totalDist = max(1, self.dist)

        self.steps = (self.dist + 0.0) / (speed + 0.0)

        if self.dist < speed or int(self.steps) <= 1:
            self.dLat = 0
            self.dLng = 0
            self.magnitude = 0;
        else:
            self.dLat = (destLat - self.initLat) / int(self.steps)
            self.dLng = (destLng - self.initLng) / int(self.steps)
            self.magnitude = self._pythagorean(self.dLat, self.dLng)
コード例 #9
0
    def _walk_to(self, speed, lat, lng, alt):
        dist = distance(i2f(self.api._position_lat),
                        i2f(self.api._position_lng), lat, lng)
        steps = (dist + 0.0) / (speed + 0.0)  # may be rational number
        intSteps = int(steps)
        residuum = steps - intSteps
        logger.log('[#] Walking from ' + str((i2f(self.api._position_lat),
                                              i2f(self.api._position_lng))) +
                   " to " + str(str((lat, lng))) + " for approx. " +
                   str(format_time(ceil(steps))))
        if steps != 0:
            dLat = (lat - i2f(self.api._position_lat)) / steps
            dLng = (lng - i2f(self.api._position_lng)) / steps

            for i in range(intSteps):
                cLat = i2f(self.api._position_lat) + \
                    dLat + random_lat_long_delta()
                cLng = i2f(self.api._position_lng) + \
                    dLng + random_lat_long_delta()
                self.api.set_position(cLat, cLng, alt)
                self.bot.heartbeat()
                sleep(1)  # sleep one second plus a random delta
                self._work_at_position(i2f(self.api._position_lat),
                                       i2f(self.api._position_lng), alt, False)

            self.api.set_position(lat, lng, alt)
            self.bot.heartbeat()
            logger.log("[#] Finished walking")
コード例 #10
0
    def _work_at_position(self, lat, lng, alt, pokemon_only=False):
        cellid = self._get_cellid(lat, lng)
        timestamp = [
            0,
        ] * len(cellid)
        self.api.get_map_objects(latitude=f2i(lat),
                                 longitude=f2i(lng),
                                 since_timestamp_ms=timestamp,
                                 cell_id=cellid)

        response_dict = self.api.call()
        # pprint.pprint(response_dict)
        # Passing Variables through a file
        if response_dict and 'responses' in response_dict:
            if 'GET_MAP_OBJECTS' in response_dict['responses']:
                if 'map_cells' in response_dict['responses'][
                        'GET_MAP_OBJECTS']:
                    user_web_location = 'web/location-%s.json' % (
                        self.config.username)
                    if os.path.isfile(user_web_location):
                        with open(user_web_location, 'w') as outfile:
                            json.dump(
                                {
                                    'lat':
                                    lat,
                                    'lng':
                                    lng,
                                    'cells':
                                    response_dict['responses']
                                    ['GET_MAP_OBJECTS']['map_cells']
                                }, outfile)

                    user_data_lastlocation = 'data/last-location-%s.json' % (
                        self.config.username)
                    if os.path.isfile(user_data_lastlocation):
                        with open(user_data_lastlocation, 'w') as outfile:
                            outfile.truncate()
                            json.dump({'lat': lat, 'lng': lng}, outfile)

        if response_dict and 'responses' in response_dict:
            if 'GET_MAP_OBJECTS' in response_dict['responses']:
                if 'status' in response_dict['responses']['GET_MAP_OBJECTS']:
                    if response_dict['responses']['GET_MAP_OBJECTS'][
                            'status'] is 1:
                        map_cells = response_dict['responses'][
                            'GET_MAP_OBJECTS']['map_cells']
                        position = (lat, lng, alt)
                    # Sort all by distance from current pos- eventually this should build graph & A* it
                    # print(map_cells)
                    #print( s2sphere.from_token(x['s2_cell_id']) )
                    map_cells.sort(
                        key=lambda x: distance(lat, lng, x['forts'][0][
                            'latitude'], x['forts'][0]['longitude'])
                        if 'forts' in x and x['forts'] != [] else 1e6)
                    for cell in map_cells:
                        self.bot.work_on_cell(cell, position, pokemon_only)
コード例 #11
0
    def get_forts(self, order_by_distance=False):
        forts = [
            fort for fort in self.cell['forts']
            if 'latitude' in fort and 'type' in fort
        ]

        if order_by_distance:
            forts.sort(key=lambda x: distance(self.position[0], self.position[
                1], x['latitude'], x['longitude']))

        return forts
コード例 #12
0
 def _work_on_wild_pokemon(self, map_cells):
     for cell in map_cells:
         if 'wild_pokemons' in cell and len(cell['wild_pokemons']) > 0:
             # Sort all by distance from current pos- eventually this should
             # build graph & A* it
             cell['wild_pokemons'].sort(
                 key=lambda x: distance(self.position[0], self.position[1], x['latitude'], x['longitude']))
             for pokemon in cell['wild_pokemons']:
                 worker = PokemonCatchWorker(pokemon, self)
                 if worker.work() == -1:
                     break
コード例 #13
0
    def take_step(self):
        point = self.points[self.ptr]
        self.cnt += 1

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

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

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

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

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

        return [point['lat'], point['lng']]
コード例 #14
0
ファイル: __init__.py プロジェクト: lyriccoder/PokemonGo-Bot
    def get_forts(self, order_by_distance=False):
        forts = [fort
             for fort in self.cell['forts']
             if 'latitude' in fort and 'type' in fort]

        if order_by_distance:
            forts.sort(key=lambda x: distance(
                self.position[0],
                self.position[1],
                x['latitude'],
                x['longitude']
            ))

        return forts
コード例 #15
0
 def _work_on_catchable_pokemon(self, map_cells):
     for cell in map_cells:
         if 'catchable_pokemons' in cell and len(cell['catchable_pokemons']) > 0:
             logger.log('[#] Something rustles nearby!')
             # Sort all by distance from current pos- eventually this should
             # build graph & A* it
             cell['catchable_pokemons'].sort(
                 key=lambda x: distance(self.position[0], self.position[1], x['latitude'], x['longitude']))
             for pokemon in cell['catchable_pokemons']:
                 with open('web/catchable-%s.json' % (self.config.username), 'w') as outfile:
                     json.dump(pokemon, outfile)
                 worker = PokemonCatchWorker(pokemon, self)
                 if worker.work() == -1:
                     break
                 with open('web/catchable-%s.json' % (self.config.username), 'w') as outfile:
                     json.dump({}, outfile)
コード例 #16
0
ファイル: stepper.py プロジェクト: effyroth/PokemonGo-Bot
    def _work_at_position(self, lat, lng, alt, pokemon_only=False):
        cellid = self._get_cellid(lat, lng)
        timestamp = [0, ] * len(cellid)
        self.api.get_map_objects(latitude=f2i(lat),
                                 longitude=f2i(lng),
                                 since_timestamp_ms=timestamp,
                                 cell_id=cellid)

        response_dict = self.api.call()
        # pprint.pprint(response_dict)
        # Passing Variables through a file
        if response_dict and 'responses' in response_dict:
            if 'GET_MAP_OBJECTS' in response_dict['responses']:
                if 'map_cells' in response_dict['responses'][
                        'GET_MAP_OBJECTS']:
                    user_web_location = 'web/location-%s.json' % (self.config.username)
                    if os.path.isfile(user_web_location):
                        with open(user_web_location, 'w') as outfile:
                            json.dump(
                                {'lat': lat,
                                'lng': lng,
                                'cells': response_dict[
                                    'responses']['GET_MAP_OBJECTS']['map_cells']},
                                outfile)

                    user_data_lastlocation = 'data/last-location-%s.json' % (self.config.username)
                    if os.path.isfile(user_data_lastlocation):
                        with open(user_data_lastlocation, 'w') as outfile:
                            outfile.truncate()
                            json.dump({'lat': lat, 'lng': lng}, outfile)

        if response_dict and 'responses' in response_dict:
            if 'GET_MAP_OBJECTS' in response_dict['responses']:
                if 'status' in response_dict['responses']['GET_MAP_OBJECTS']:
                    if response_dict['responses']['GET_MAP_OBJECTS'][
                            'status'] is 1:
                        map_cells = response_dict['responses'][
                            'GET_MAP_OBJECTS']['map_cells']
                        position = (lat, lng, alt)
                    # Sort all by distance from current pos- eventually this should build graph & A* it
                    # print(map_cells)
                    #print( s2sphere.from_token(x['s2_cell_id']) )
                    map_cells.sort(key=lambda x: distance(lat, lng, x['forts'][0]['latitude'], x[
                                   'forts'][0]['longitude']) if 'forts' in x and x['forts'] != [] else 1e6)
                    for cell in map_cells:
                        self.bot.work_on_cell(cell, position, pokemon_only)
コード例 #17
0
    def find_close_cells(self, lat, lng):
        cellid = get_cell_ids(lat, lng)
        timestamp = [
            0,
        ] * len(cellid)
        response_dict = self.get_map_objects(lat, lng, timestamp, cellid)
        map_objects = response_dict.get('responses',
                                        {}).get('GET_MAP_OBJECTS', {})
        status = map_objects.get('status', None)

        map_cells = []
        if status and status == 1:
            map_cells = map_objects['map_cells']
            position = (lat, lng, 0)
            map_cells.sort(
                key=lambda x: distance(lat, lng, x['forts'][0]['latitude'], x[
                    'forts'][0]['longitude']) if x.get('forts', []) else 1e6)
        return map_cells
コード例 #18
0
    def walk_to(self, speed, lat, lng, alt):
        dist = distance(i2f(self.api._position_lat), i2f(self.api._position_lng), lat, lng)
        steps = (dist / (self.AVERAGE_STRIDE_LENGTH_IN_METRES * speed))

        logger.log("[#] Walking from " + str((i2f(self.api._position_lat), i2f(self.api._position_lng))) + " to " + str(str((lat, lng))) + " for approx. " + str(format_time(ceil(steps))))
        if steps != 0:
            d_lat = (lat - i2f(self.api._position_lat)) / steps
            d_long = (lng - i2f(self.api._position_lng)) / steps

            for i in range(int(steps)):
                c_lat = i2f(self.api._position_lat) + d_lat + random_lat_long_delta()
                c_long = i2f(self.api._position_lng) + d_long + random_lat_long_delta()
                self.api.set_position(c_lat, c_long, alt)
                self.bot.heartbeat()
                sleep(1)  # sleep one second plus a random delta
                self._work_at_position(i2f(self.api._position_lat), i2f(self.api._position_lng), alt, False)

            self.api.set_position(lat, lng, alt)
            self.bot.heartbeat()
            logger.log("[#] Finished walking")
コード例 #19
0
    def _work_at_position(self, lat, lng, alt, pokemon_only=False):
        cellid = self._get_cellid(lat, lng)
        timestamp = [0, ] * len(cellid)
        self.api.get_map_objects(latitude=f2i(lat),
                                 longitude=f2i(lng),
                                 since_timestamp_ms=timestamp,
                                 cell_id=cellid)

        response_dict = self.api.call()
        if response_dict and 'responses' in response_dict:
            if 'GET_MAP_OBJECTS' in response_dict['responses']:
                if 'status' in response_dict['responses']['GET_MAP_OBJECTS']:
                    if response_dict['responses']['GET_MAP_OBJECTS'][
                            'status'] is 1:
                        map_cells = response_dict['responses'][
                            'GET_MAP_OBJECTS']['map_cells']
                        position = (lat, lng, alt)
                    # Sort all by distance from current pos- eventually this should build graph & A* it
                    # print(map_cells)
                    #print( s2sphere.from_token(x['s2_cell_id']) )
                    map_cells.sort(key=lambda x: distance(lat, lng, x['forts'][0]['latitude'], x[
                                   'forts'][0]['longitude']) if 'forts' in x and x['forts'] != [] else 1e6)
                    for cell in map_cells:
                        self.bot.work_on_cell(cell, position, pokemon_only)
コード例 #20
0
ファイル: __init__.py プロジェクト: Cryspart/PokemonGo-Bot
    def work_on_cell(self, cell, position, include_fort_on_path):
        """
        if self.config.evolve_all:
            # Run evolve all once. Flip the bit.
            print('[#] Attempting to evolve all pokemons ...')
            worker = EvolveAllWorker(self)
            worker.work()
            self.config.evolve_all = []
        """

        self._filter_ignored_pokemons(cell)

        if (
            (self.config.mode == "all" or self.config.mode == "poke")
            and "catchable_pokemons" in cell
            and len(cell["catchable_pokemons"]) > 0
        ):
            logger.log("[#] Something rustles nearby!")
            # Sort all by distance from current pos- eventually this should
            # build graph & A* it
            cell["catchable_pokemons"].sort(
                key=lambda x: distance(self.position[0], self.position[1], x["latitude"], x["longitude"])
            )

            user_web_catchable = "web/catchable-%s.json" % (self.config.username)
            for pokemon in cell["catchable_pokemons"]:
                with open(user_web_catchable, "w") as outfile:
                    json.dump(pokemon, outfile)

                if self.catch_pokemon(pokemon) == PokemonCatchWorker.NO_POKEBALLS:
                    break
                with open(user_web_catchable, "w") as outfile:
                    json.dump({}, outfile)

        if (
            (self.config.mode == "all" or self.config.mode == "poke")
            and "wild_pokemons" in cell
            and len(cell["wild_pokemons"]) > 0
        ):
            # Sort all by distance from current pos- eventually this should
            # build graph & A* it
            cell["wild_pokemons"].sort(
                key=lambda x: distance(self.position[0], self.position[1], x["latitude"], x["longitude"])
            )
            for pokemon in cell["wild_pokemons"]:
                if self.catch_pokemon(pokemon) == PokemonCatchWorker.NO_POKEBALLS:
                    break
        if (self.config.mode == "all" or self.config.mode == "farm") and include_fort_on_path:
            if "forts" in cell:
                # Only include those with a lat/long
                forts = [fort for fort in cell["forts"] if "latitude" in fort and "type" in fort]
                gyms = [gym for gym in cell["forts"] if "gym_points" in gym]

                # Sort all by distance from current pos- eventually this should
                # build graph & A* it
                forts.sort(key=lambda x: distance(self.position[0], self.position[1], x["latitude"], x["longitude"]))
                for fort in forts:
                    if not self.check_position_in_border((fort["latitude"], fort["longitude"])):
                        continue
                    worker = MoveToFortWorker(fort, self)
                    worker.work()

                    worker = SeenFortWorker(fort, self)
                    hack_chain = worker.work()
                    if hack_chain > 10:
                        # print('need a rest')
                        break
コード例 #21
0
    def work_on_cell(self, cell, position, include_fort_on_path):
        if self.config.evolve_all:
            # Run evolve all once. Flip the bit.
            print('[#] Attempting to evolve all pokemons ...')
            worker = EvolveAllWorker(self)
            worker.work()
            self.config.evolve_all = []

        self._filter_ignored_pokemons(cell)

        if (self.config.mode == "all" or self.config.mode ==
                "poke") and 'catchable_pokemons' in cell and len(cell[
                    'catchable_pokemons']) > 0:
            logger.log('[#] Something rustles nearby!')
            # Sort all by distance from current pos- eventually this should
            # build graph & A* it
            cell['catchable_pokemons'].sort(
                key=
                lambda x: distance(self.position[0], self.position[1], x['latitude'], x['longitude']))

            user_web_catchable = 'web/catchable-%s.json' % (self.config.username)
            for pokemon in cell['catchable_pokemons']:
                with open(user_web_catchable, 'w') as outfile:
                    json.dump(pokemon, outfile)

                if self.catch_pokemon(pokemon) == PokemonCatchWorker.NO_POKEBALLS:
                    break
                with open(user_web_catchable, 'w') as outfile:
                    json.dump({}, outfile)

        if (self.config.mode == "all" or self.config.mode == "poke"
            ) and 'wild_pokemons' in cell and len(cell['wild_pokemons']) > 0:
            # Sort all by distance from current pos- eventually this should
            # build graph & A* it
            cell['wild_pokemons'].sort(
                key=
                lambda x: distance(self.position[0], self.position[1], x['latitude'], x['longitude']))
            for pokemon in cell['wild_pokemons']:
                if self.catch_pokemon(pokemon) == PokemonCatchWorker.NO_POKEBALLS:
                    break
        if (self.config.mode == "all" or
                self.config.mode == "farm") and include_fort_on_path:
            if 'forts' in cell:
                # Only include those with a lat/long
                forts = [fort
                         for fort in cell['forts']
                         if 'latitude' in fort and 'type' in fort]
                gyms = [gym for gym in cell['forts'] if 'gym_points' in gym]

                # Sort all by distance from current pos- eventually this should
                # build graph & A* it
                forts.sort(key=lambda x: distance(self.position[
                           0], self.position[1], x['latitude'], x['longitude']))
                for fort in forts:
                    worker = MoveToFortWorker(fort, self)
                    worker.work()

                    worker = SeenFortWorker(fort, self)
                    hack_chain = worker.work()
                    if hack_chain > 10:
                        #print('need a rest')
                        break