Example #1
0
def catch(api, encounter_id, spawn_point_id, inventory):
    # Try to catch pokemon, but don't get stuck.
    rv = {
        'catch_status': 'fail',
        'reason': "Unknown reason.",
        'attempts': 1
    }
    while rv['attempts'] < 3:
        time.sleep(random.uniform(2, 3))
        try:
            # Randomize throwing parameters. Some stuff to read:
            # https://pokemongo.gamepress.gg/catch-mechanics
            # https://www.reddit.com/r/pokemongodev/comments/4vlnwj/pokemon_go_catch_mechanicsformula_discussion/
            normalized_reticle_size = 1.1 + 0.70 * random.random()
            spin_modifier = 0.4 + 0.4 * random.random()

            # Determine best ball - we know for sure that we have at least one
            ball = ITEM_ULTRA_BALL if inventory.get(ITEM_ULTRA_BALL, 0) > 0 else (
                ITEM_GREAT_BALL if inventory.get(ITEM_GREAT_BALL, 0) > 0 else ITEM_POKE_BALL)

            req = api.create_request()
            req.catch_pokemon(
                encounter_id=encounter_id,
                pokeball=ball,
                normalized_reticle_size=normalized_reticle_size,
                spawn_point_id=spawn_point_id,
                hit_pokemon=1,
                spin_modifier=spin_modifier,
                normalized_hit_position=1.0)
            req.check_challenge()
            req.get_hatched_eggs()
            req.get_inventory()
            req.check_awarded_badges()
            req.download_settings()
            req.get_buddy_walked()
            catch_result = req.call()

            # Inventory changed on throwing a ball.
            inventory.update(get_player_inventory(catch_result))

            if (catch_result is not None and 'CATCH_POKEMON' in catch_result['responses']):
                catch_status = catch_result['responses']['CATCH_POKEMON']['status']

                # Success!
                if catch_status == 1:
                    # Check inventory for caught Pokemon
                    capture_id = catch_result['responses']['CATCH_POKEMON']['captured_pokemon_id']
                    pid = get_captured_pokemon_id_from_inventory(capture_id, catch_result)
                    if pid:
                        # Set ID of caught Pokemon
                        rv['catch_status'] = 'success'
                        rv['pid'] = pid
                        rv['capture_id'] = capture_id
                    else:
                        rv['reason'] = "Could not find caught Pokemon in inventory."
                    return rv

                # Broke free!
                if catch_status == 2:
                    log.debug('Catch attempt %s failed. It broke free!', rv['attempts'])

                # Ran away!
                if catch_status == 3:
                    rv['reason'] = "Pokemon ran away!"
                    return rv

                # Dodged!
                if catch_status == 4:
                    log.debug('Catch attempt %s failed. It dodged the ball!', rv['attempts'])

            else:
                log.error('Catch attempt %s failed. The api response was empty!', rv['attempts'])

        except Exception as e:
            log.error('Catch attempt %s failed. API exception: %s', rv['attempts'], repr(e))

        rv['attempts'] += 1

    if rv['attempts'] >= 3:
        rv['attempts'] -= 1
        rv['reason'] = "Giving up."

    return rv
Example #2
0
def gxp_spin_stops(forts, pgacc, step_location):
    for f in forts:
        if f.type == 1 and pokestop_spinnable(f, step_location):
            time.sleep(random.uniform(0.8, 1.8))
            response = spin_pokestop_request(pgacc, f, step_location)
            time.sleep(random.uniform(2, 4))  # Don't let Niantic throttle.

            # Check for reCaptcha.
            if pgacc.has_captcha():
                log.debug('Account encountered a reCaptcha.')
                return

            spin_result = response['FORT_SEARCH'].result
            if spin_result is 1:
                awards = parse_awarded_items(
                    response['FORT_SEARCH'].items_awarded)
                log.info('GXP: Got {} items ({} balls) from Pokestop.'.format(
                    awards['total'], awards['balls']))
                cleanup_inventory(pgacc)
                return True
            elif spin_result is 2:
                log.debug('GXP: Pokestop was not in range to spin.')
            elif spin_result is 3:
                log.debug(
                    'GXP: Failed to spin Pokestop. Has recently been spun.')
            elif spin_result is 4:
                log.debug('GXP: Failed to spin Pokestop. Inventory is full.')
                cleanup_inventory(pgacc)
            elif spin_result is 5:
                log.debug(
                    'GXP: Maximum number of Pokestops spun for this day.')
            else:
                log.debug('GXP: Failed to spin a Pokestop. Unknown result %d.',
                          spin_result)
Example #3
0
def spin_pokestop_update_inventory(api, fort, step_location, inventory):
    time.sleep(random.uniform(0.8, 1.8))  # Do not let Niantic throttle
    spin_response = spin_pokestop_request(api, fort, step_location)
    time.sleep(random.uniform(2, 4))  # Do not let Niantic throttle
    if not spin_response:
        return False

    # Check for reCaptcha
    captcha_url = spin_response['responses']['CHECK_CHALLENGE']['challenge_url']
    if len(captcha_url) > 1:
        log.debug('Account encountered a reCaptcha.')
        return False

    spin_result = spin_response['responses']['FORT_SEARCH']['result']
    if spin_result is 1:
        awards = get_awarded_items(spin_response['responses']['FORT_SEARCH']['items_awarded'])
        log.info('Got {} items ({} balls) from Pokestop.'.format(awards['total'], awards['balls']))
        inventory.update(get_player_inventory(spin_response))
        return True
    elif spin_result is 2:
        log.debug('Pokestop was not in range to spin.')
    elif spin_result is 3:
        log.debug('Failed to spin Pokestop. Has recently been spun.')
    elif spin_result is 4:
        log.debug('Failed to spin Pokestop. Inventory is full.')
    elif spin_result is 5:
        log.debug('Maximum number of Pokestops spun for this day.')
    else:
        log.debug(
            'Failed to spin a Pokestop. Unknown result %d.',
            spin_result)
    return False
Example #4
0
def catch(pgacc, encounter_id, spawn_point_id):
    # Try to catch pokemon, but don't get stuck.
    rv = {'catch_status': 'fail', 'reason': "Unknown reason.", 'attempts': 1}
    while rv['attempts'] < 3 and pgacc.inventory_balls > 0:
        time.sleep(random.uniform(2, 3))
        try:
            # Randomize throwing parameters. Some stuff to read:
            # https://pokemongo.gamepress.gg/catch-mechanics
            # https://www.reddit.com/r/pokemongodev/comments/4vlnwj/pokemon_go_catch_mechanicsformula_discussion/
            normalized_reticle_size = 1.1 + 0.70 * random.random()
            spin_modifier = 0.4 + 0.4 * random.random()

            # Determine best ball - we know for sure that we have at least one
            inventory = pgacc.inventory
            ball = ITEM_ULTRA_BALL if inventory.get(
                ITEM_ULTRA_BALL, 0) > 0 else (ITEM_GREAT_BALL if inventory.get(
                    ITEM_GREAT_BALL, 0) > 0 else ITEM_POKE_BALL)

            catch_result = pgacc.req_catch_pokemon(encounter_id,
                                                   spawn_point_id, ball,
                                                   normalized_reticle_size,
                                                   spin_modifier)

            if (catch_result is not None and 'CATCH_POKEMON' in catch_result):
                catch_status = catch_result['CATCH_POKEMON'].status

                # Success!
                if catch_status == 1:
                    rv['catch_status'] = 'success'
                    if pgacc.last_caught_pokemon:
                        # Set ID of caught Pokemon
                        rv['pid'] = pgacc.last_caught_pokemon['pokemon_id']
                    return rv

                # Broke free!
                if catch_status == 2:
                    log.debug('GXP: Catch attempt %s failed. It broke free!',
                              rv['attempts'])

                # Ran away!
                if catch_status == 3:
                    rv['reason'] = "Pokemon ran away!"
                    return rv

                # Dodged!
                if catch_status == 4:
                    log.debug(
                        'GXP: Catch attempt %s failed. It dodged the ball!',
                        rv['attempts'])

            else:
                log.error(
                    'GXP: Catch attempt %s failed. The api response was empty!',
                    rv['attempts'])

        except Exception as e:
            log.error('GXP: Catch attempt %s failed. API exception: %s',
                      rv['attempts'], repr(e))

        rv['attempts'] += 1

    if rv['attempts'] >= 3:
        rv['attempts'] -= 1
        rv['reason'] = "Giving up."

    return rv