Ejemplo n.º 1
0
    def walkTo(self, olatitude, olongitude, epsilon=10, step=7.5):
        if step >= epsilon:
            raise GeneralPogoException("Walk may never converge")

        if self.location.noop:
            raise GeneralPogoException("Location not set")

        # Calculate distance to position
        latitude, longitude, _ = self.getCoordinates()
        dist = closest = Location.getDistance(latitude, longitude, olatitude,
                                              olongitude)

        # Run walk
        divisions = closest / step
        dLat = (latitude - olatitude) / divisions
        dLon = (longitude - olongitude) / divisions

        logging.info("Walking %f meters. This will take %f seconds..." %
                     (dist, dist / step))
        while dist > epsilon:
            logging.debug("%f m -> %f m away", closest - dist, closest)
            latitude -= dLat
            longitude -= dLon
            self.setCoordinates(latitude, longitude)
            time.sleep(1)
            dist = Location.getDistance(latitude, longitude, olatitude,
                                        olongitude)
Ejemplo n.º 2
0
    def setLocation(self, search):
        try:
            geo = self.locator.geocode(search)
        except:
            raise GeneralPogoException('Error in Geo Request')

        # 8 is arbitrary, but not as suspicious as 0
        return geo.latitude, geo.longitude, geo.altitude or 8
Ejemplo n.º 3
0
    def parseDefault(self, res):
        try:
            self._state.eggs.ParseFromString(res.returns[1])
            self._state.inventory.ParseFromString(res.returns[2])
            self._state.badges.ParseFromString(res.returns[3])
            self._state.settings.ParseFromString(res.returns[4])
        except Exception as e:
            logging.error(e)
            raise GeneralPogoException("Error parsing response. Malformed response")

        # Finally make inventory usable
        item = self._state.inventory.inventory_delta.inventory_items
        self.inventory = Inventory(item)
Ejemplo n.º 4
0
    def walkTo(self, olatitude, olongitude, epsilon=10, step=7.5):
        if step >= epsilon:
            raise GeneralPogoException("Walk may never converge")

        # Calculate distance to position
        latitude, longitude, _ = self.getCoordinates()
        dist = closest = Location.getDistance(
            latitude,
            longitude,
            olatitude,
            olongitude
        )

        # Run walk
        divisions = closest / step
        dLat = (latitude - olatitude) / divisions
        dLon = (longitude - olongitude) / divisions

        logging.info("Walking %f meters. This will take %f seconds..." % (dist, dist / step))
        print '~'*5,round((dist/(dist / step))*3.6,3),'km/h','~'*5
        dist_max = dist
        p = ProgressBar(max_value=dist_max)
        while dist > epsilon:
            logging.debug("%f m -> %f m away", closest - dist, closest)
            latitude -= dLat
            longitude -= dLon
            self.setCoordinates(
                latitude,
                longitude
            )
            time.sleep(1)
            dist = Location.getDistance(
                latitude,
                longitude,
                olatitude,
                olongitude
            )
            p.update(dist_max-dist)
        p.update(dist_max)
Ejemplo n.º 5
0
 def request(self, req, url=None):
     try:
         return self.requestOrThrow(req, url)
     except Exception as e:
         logging.error(e)
         raise GeneralPogoException('Probably server fires.')
Ejemplo n.º 6
0
def encounterAndCatch(session, pokemon, thresholdP=0.5, limit=5, delay=2):
    # Start encounter
    encounter = session.encounterPokemon(pokemon)

    # Grab needed data from proto
    chances = encounter.capture_probability.capture_probability
    balls = encounter.capture_probability.pokeball_type
    bag = session.checkInventory().bag

    # Have we used a razz berry yet?
    berried = False

    # Make sure we aren't oer limit
    count = 0

    # Attempt catch
    while True:
        bestBall = items.UNKNOWN
        altBall = items.UNKNOWN

        # Check for balls and see if we pass
        # wanted threshold
        for i in range(len(balls)):
            if balls[i] in bag and bag[balls[i]] > 0:
                altBall = balls[i]
                if chances[i] > thresholdP:
                    bestBall = balls[i]
                    break

        # If we can't determine a ball, try a berry
        # or use a lower class ball
        if bestBall == items.UNKNOWN:
            if not berried and items.RAZZ_BERRY in bag and bag[items.RAZZ_BERRY]:
                logging.info("Using a RAZZ_BERRY")
                session.useItemCapture(items.RAZZ_BERRY, pokemon)
                berried = True
                time.sleep(delay)
                continue

            # if no alt ball, there are no balls
            elif altBall == items.UNKNOWN:
                raise GeneralPogoException("Out of usable balls")
            else:
                bestBall = altBall

        # Try to catch it!!
        logging.info("Using a %s" % items[bestBall])
        attempt = session.catchPokemon(pokemon, bestBall)
        time.sleep(delay)

        # Success or run away
        if attempt.status == 1:
            return attempt

        # CATCH_FLEE is bad news
        if attempt.status == 3:
            if count == 0:
                logging.info("Possible soft ban.")
            else:
                logging.info("Pokemon fleed at %dth attempt" % (count + 1))
            return attempt

        # Only try up to x attempts
        count += 1
        if count >= limit:
            logging.info("Over catch limit")
            return None
Ejemplo n.º 7
0
def snipeABitch(session,
                pokemon,
                encounter,
                thresholdP=0.5,
                limit=25,
                delay=2):
    # Start encounter

    # Grab needed data from proto
    chances = encounter.capture_probability.capture_probability
    balls = encounter.capture_probability.pokeball_type
    bag = session.checkInventory().bag

    # Have we used a razz berry yet?
    berried = False

    # Make sure we aren't oer limit
    count = 0

    # Attempt catch
    while True:
        bestBall = items.UNKNOWN
        altBall = items.UNKNOWN
        #logging.info("Poke Balls: " + str(pokeBalls) + " Great Balls: " + str(greatBalls) + " Ultra Balls: " + str(ultraBalls))
        # Check for balls and see if we pass
        # wanted threshold

        bag = session.checkInventory().bag

        ballTypes = {1: 'Poke Ball', 2: 'Great Ball', 3: 'Ultra Ball'}
        for i in range(1, len(balls) + 1):
            if i in bag and bag[i] > 0:
                if i == 1:
                    #PokeBalls
                    pokeBalls = bag[i]
                    logging.info("We have " + str(bag[i]) + " Poke Balls")
                    if chances[i] > thresholdP:
                        bestBall = i
                        logging.info(
                            "Poke Ball catch probability is above threshold of .5."
                        )
                        break
                    else:
                        bestBall = i
                        altBall = i
                elif i == 2:
                    #GreatBalls
                    greatBalls = bag[i]
                    logging.info("We have " + str(bag[i]) + " Great Balls")
                    if float(chances[i]) > float(thresholdP):
                        bestBall = i
                        logging.info(
                            "Great Ball catch probability is above threshold of .5."
                        )
                        break
                    else:
                        if i - 1 in bag and bag[i - 1] > 0:
                            altBall = i - 1
                            bestBall = i

                elif i == 3:
                    #UltraBalls
                    ultraBalls = bag[i]
                    bestBall = i
                    logging.info(
                        "No ball's catch probability is above threshold of .5, defaulting to Ultra Ball."
                    )
                    logging.info("We have " + str(bag[i]) + " Ultra Balls")
                    if i - 1 in bag and bag[i - 1] > 0:
                        altBall = i - 1

        if bestBall != items.UNKNOWN and altBall != items.UNKNOWN:
            logging.critical("Best ball: " + ballTypes[bestBall] +
                             " Alt Ball: " + ballTypes[altBall])
        elif bestBall != items.UNKNOWN:
            logging.critical("Best ball: " + ballTypes[bestBall] +
                             " Alt Ball: NONE!")
        # If we can't determine a ball, try a berry
        # or use a lower class ball

        if int(encounter.wild_pokemon.pokemon_data.cp) >= int(
                useBerryThreshold):

            if not berried and items.RAZZ_BERRY in bag and bag[
                    items.RAZZ_BERRY]:
                logging.info("Using a RAZZ_BERRY")
                session.useItemCapture(items.RAZZ_BERRY, pokemon)
                berried = True
                time.sleep(delay)
                continue

            # if no alt ball, there are no balls
            elif altBall == items.UNKNOWN:
                data = [{'status': 'fail', 'message': 'Out of usable balls'}]
                json.dump(data, open('static/catch_data.json', 'w'))
                time.sleep(1)
                raise GeneralPogoException("Out of usable balls")

        # Try to catch it!!
        logging.info("Using a %s" % items[bestBall])
        attempt = session.catchPokemon(pokemon, bestBall)
        time.sleep(delay)

        # Success or run away
        if attempt.status == 1:

            logging.critical("Congrats! We caught it!\n")
            return attempt
        if attempt.status == 2:
            logging.critical("Escaped ball, retry!")

        # CATCH_FLEE is bad news
        if attempt.status == 3:
            logging.info("Pokemon fled - possible soft ban.")
            return attempt

        # Only try up to x attempts
        count += 1
        if count >= limit:
            logging.info("Over catch limit")
            return None
Ejemplo n.º 8
0
 def setLocation(self, search):
     try:
         geo = self.locator.geocode(search)
     except:
         raise GeneralPogoException('Error in Geo Request')
     return geo.latitude, geo.longitude, geo.altitude