Exemple #1
0
 async def move_to_with_gmo(self, next_pos, is_fast_speed=True, seconds_threshold=25, at_location=None):
     player_position = self.travel_time.prev_position
     seconds_between_locations = self.travel_time.time_to_location(next_pos)
     if seconds_between_locations > seconds_threshold:
         self.travel_time.set_fast_speed(is_fast_speed)
         seconds_between_locations = self.travel_time.time_to_location(next_pos)
         self.log.info("{} seconds to next location using fast speed".format(str(seconds_between_locations)))
         map_objects = None
         remaining_distance = equi_rect_distance_m(player_position, next_pos)
         while remaining_distance > 1:
             available = self.travel_time.meters_available_until_gmo()
             player_position = move_towards(player_position, next_pos, available)
             map_objects = await self.get_map_objects(player_position)
             num_pokemons = len(catchable_pokemon(map_objects))
             self.log.info("Remaining distance is {}, {} meters available, {} pokemon at this pos".format(
                 str(remaining_distance), str(available), str(num_pokemons)))
             if at_location:
                 await at_location(player_position, map_objects)
             remaining_distance = equi_rect_distance_m(player_position, next_pos)
         self.travel_time.use_slow_speed()
     else:
         if seconds_between_locations > 0.1:
             self.log.info("{} seconds to next position {}".format(str(seconds_between_locations), str(next_pos)))
         map_objects = await self.get_map_objects(next_pos)
     return map_objects
Exemple #2
0
def find_optimal_location(stop_coords, SPIN_RANGE=38.5, CATCH_RANGE=20):
    global num_locs
    stop_box = box_around(stop_coords, SPIN_RANGE + CATCH_RANGE)
    sp = spawnpoints_in_box(stop_box)
    points = [SpawnPoint(x) for x in sp]
    in_range_of_stop = [
        p for p in points
        if p.is_within_range(stop_coords, SPIN_RANGE + CATCH_RANGE)
    ]
    for idx, x in enumerate(in_range_of_stop):
        for n in points[idx + 1:]:
            x.add_neighhbours(n, 60)

    z = 0
    curr = None
    for x in in_range_of_stop:
        num_neigh = x.collected_neighbours()
        if num_neigh > z:
            curr = x
            z = num_neigh
    if not curr:
        return ()
    neighbours = curr.collected_neighbours()
    max_spawns = center_geolocation([x.location() for x in neighbours])

    m = equi_rect_distance_m(max_spawns, stop_coords)
    if m > SPIN_RANGE:
        max_spawns = move_towards(max_spawns, stop_coords, m - SPIN_RANGE)

    distance = equi_rect_distance_m(max_spawns, stop_coords)

    return max_spawns, len(neighbours), distance
Exemple #3
0
def beh_spin_pokestop_raw(pogoservice, pokestop, player_position):
    pogoservice.do_pokestop_details(pokestop)
    spin_response = pogoservice.do_spin_pokestop(pokestop, player_position)
    result = spin_response['responses']['FORT_SEARCH'].result
    attempt = 0
    if result == 4:
        beh_aggressive_bag_cleaning(pogoservice)
        spin_response = pogoservice.do_spin_pokestop(pokestop, player_position)
        result = spin_response['responses']['FORT_SEARCH'].result

    while result == 2 and attempt < 6:
        stop_pos = (pokestop.latitude,pokestop.longitude)
        dist = vincenty(stop_pos, player_position).m
        if dist > 40:
            log.error("Too far away from stop, {}m. this should not happen".format(str(dist)))
            return result  # give up
        if attempt == 0:
            if player_position != stop_pos:
                player_position = move_towards(player_position, stop_pos, 1)
        if attempt == 2:
            objs = pogoservice.do_get_map_objects(player_position)
            log.info ("Extra gmo gave catchanble {}".format(str(len(catchable_pokemon(objs)))))
        time.sleep(1)  # investigate if really needed
        attempt += 1
        spin_response = pogoservice.do_spin_pokestop(pokestop, player_position)
        result = spin_response['responses']['FORT_SEARCH'].result
        log.info("{} attempt spinning gave result {}".format(str(attempt), str(result)))

    return result
Exemple #4
0
def beh_spin_nearby_pokestops(pogoservice, map_objects, position, range_m=39, blacklist=None, exclusions = {}):
    spun = []
    spinning_distance_m = 39
    travel_time = pogoservice.getlayer(TravelTime)
    old_speed = travel_time.get_speed()
    if map_objects:
        pokestops = inrange_pokstops_and_gyms(map_objects, position, range_m)
        for idx, pokestop in enumerate(pokestops):
            if blacklist and pokestop.id in blacklist:
                pass
            if exclusions and pokestop.id in exclusions:
                pass
            elif pokestop.cooldown_complete_timestamp_ms > 0:
                log.debug('Pokestop is in cooldown, ignoring')
            else:
                dist_to_stop = distance_to_fort( position, pokestop )
                if dist_to_stop > spinning_distance_m:
                    m_to_move = dist_to_stop - spinning_distance_m
                    log.info("Stop is {}m away, moving {}m closer".format(str(dist_to_stop), str(m_to_move)))
                    travel_time.use_slow_speed()
                    position = move_towards(position, fort_as_coordinate(pokestop), m_to_move)
                elif idx > 0:
                    idx_ = min(idx, 2) * 200
                    log.info("Random sleeping at least {}ms for additional stops".format(idx_))
                    random_sleep_z(idx_, idx_ + 100, "pokestop_details")  # Do not let Niantic throttle
                res = beh_spin_pokestop_raw(pogoservice, pokestop, position)
                if res == 1:
                    spun.append(pokestop.id)
    travel_time.set_fast_speed(old_speed)
    return spun
Exemple #5
0
async def beh_spin_pokestop_raw(pogoservice,
                                pokestop,
                                player_position,
                                item_limits=None):
    await pogoservice.do_pokestop_details(pokestop)
    spin_response = await pogoservice.do_spin_pokestop(pokestop,
                                                       player_position)
    result = spin_response['FORT_SEARCH'].result
    attempt = 0
    if result == 6:
        print(str(pokestop))

    if result == 4:
        await beh_aggressive_bag_cleaning(pogoservice, item_limits)
        spin_response = await pogoservice.do_spin_pokestop(
            pokestop, player_position)
        result = spin_response['FORT_SEARCH'].result

    while result == 2 and attempt < 6:
        stop_pos = (pokestop.latitude, pokestop.longitude)
        dist = equi_rect_distance_m(stop_pos, player_position)
        if dist > 40:
            pogoservice.log.error(
                "Too far away from stop, {}m. this should not happen".format(
                    str(dist)))
            return result  # give up
        if attempt == 0:
            if player_position != stop_pos:
                player_position = move_towards(player_position, stop_pos, 1)
        if attempt == 2:
            objs = await pogoservice.do_get_map_objects(player_position)
            pogoservice.log.info(u"Extra gmo gave catchanble {}".format(
                str(len(catchable_pokemon(objs)))))
        await asyncio.sleep(1)  # investigate if really needed
        attempt += 1
        spin_response = await pogoservice.do_spin_pokestop(
            pokestop, player_position)
        result = spin_response['FORT_SEARCH'].result
        pogoservice.log.info(u"{} attempt spinning gave result {}".format(
            str(attempt), str(result)))

    return result
Exemple #6
0
    async def do_catch_moving(self, map_objects, player_pos, next_pos,
                              catch_condition, is_egg_active):
        all_caught = {}
        if not self.is_within_catch_limit():
            self.worker.log.info(
                u"Catch limit {} exceeeded, not catching any more".format(
                    str(self.catch_limit)))
            return
        catch_list = catchable_pokemon_by_distance(map_objects, next_pos)
        names = pokemon_names([x[1] for x in catch_list])
        self.worker.log.info(u"{} pokemon in map_objects: {}".format(
            str(len(catch_list)), names))
        while len(catch_list) > 0:
            to_catch = catch_list[0][1]
            # print str(to_catch)
            encounter_id = to_catch.encounter_id
            pokemon_id = to_catch.pokemon_id

            unseen_catch = catch_condition.only_unseen and (
                pokemon_id not in self.caught_pokemon_ids)
            candy_catch = catch_condition.is_candy_catch(pokemon_id)
            candy_12_catch = catch_condition.is_candy_12_catch(pokemon_id)
            encountered_previously = self.is_encountered_previously(
                encounter_id)
            candy_50_catch = catch_condition.is_candy_50_catch(pokemon_id)

            will_catch = (is_egg_active or catch_condition.catch_anything
                          or unseen_catch or candy_catch or candy_12_catch
                          or candy_50_catch)

            if encountered_previously:
                self.worker.log.info(u"{} {} encountered previously".format(
                    str(pokemon_name(pokemon_id)), str(encounter_id)))
            elif will_catch:
                # log.debug("To_catch={}".format(str(to_catch)))
                pokemon_distance_to_next_position = catch_list[0][0]
                player_distance_to_next_position = equi_rect_distance_m(
                    player_pos, next_pos)
                map_pokemon = catch_list[0][1]
                on_other_side = (
                    player_pos[1] < next_pos[1] < map_pokemon.longitude) or (
                        player_pos[1] > next_pos[1] > map_pokemon.longitude)

                if on_other_side:
                    available_mobility = self.travel_time.meters_available_right_now(
                    )
                    actual_meters = min(available_mobility,
                                        player_distance_to_next_position)
                    self.worker.log.info(
                        u"Moving closer {} metres. {} meters_available right now"
                        .format(str(actual_meters), str(available_mobility)))
                    player_pos = move_towards(player_pos, next_pos,
                                              actual_meters)
                if pokemon_distance_to_next_position < player_distance_to_next_position:
                    m_to_move = player_distance_to_next_position - pokemon_distance_to_next_position
                    available_mobility = self.travel_time.meters_available_right_now(
                    )
                    actual_meters = min(available_mobility, m_to_move)
                    self.worker.log.info(
                        u"player_distance_to_next_position={},pokemon_distance_to_next_position={}"
                        .format(str(player_distance_to_next_position),
                                str(pokemon_distance_to_next_position)))
                    self.worker.log.info(
                        u"Could move towards next position {} meters. {} meters_available, {}m by pokemon!"
                        .format(str(actual_meters), str(available_mobility),
                                str(m_to_move)))
                    player_pos = move_towards(player_pos, next_pos,
                                              actual_meters)

                if self.travel_time.must_gmo():
                    await self.worker.do_get_map_objects(player_pos)

                self.processed_encounters.add(
                    encounter_id)  # leaks memory. fix todo
                self.worker.log.info(
                    u"Catching {} because catch_all={} unseen={} candy_catch={} candy_12_catch={}"
                    .format(pokemon_name(pokemon_id),
                            str(catch_condition.catch_anything),
                            str(unseen_catch), str(candy_catch),
                            str(candy_12_catch)))
                caught = await self.catch_it(player_pos, to_catch, fast=True)
                if caught:
                    self.caught_pokemon_ids.add(pokemon_id)
                    if isinstance(caught, numbers.Number):
                        all_caught[caught] = pokemon_id
                    else:
                        self.worker.log.warning(
                            "Did not caEtch because {}".format(str(caught)))
            else:
                self.worker.log.info(
                    u"{} {} will not catch, is_catch_anything={}, is_unseen_catch={}, is_candy_catch={}, is_candy12_catch={}"
                    .format(str(pokemon_name(pokemon_id)), str(encounter_id),
                            str(catch_condition.catch_anything),
                            str(unseen_catch), str(candy_catch),
                            str(candy_12_catch)))
            del catch_list[0]

        self.pokemon_caught += len(all_caught)
        self.process_evolve_transfer_list(all_caught)

        return player_pos