Esempio n. 1
0
    def get_family_ids(self, pokemon_id):
        family_id = inventory.pokemons().data_for(
            pokemon_id).first_evolution_id
        ids = [family_id]
        ids += inventory.pokemons().data_for(family_id).next_evolutions_all[:]

        return ids
    def transfer_pokemon(self, pokemon):
        if self.config_transfer and (not self.bot.config.test):
            response_dict = self.bot.api.release_pokemon(pokemon_id=pokemon.id)
        else:
            response_dict = {"responses": {"RELEASE_POKEMON": {"candy_awarded": 0}}}

        if not response_dict:
            return False

        self.emit_event("pokemon_release",
                        formatted="Exchanged {pokemon} [IV {iv}] [CP {cp}] [NCP {ncp}] [DPS {dps}]",
                        data={"pokemon": pokemon.name,
                              "iv": pokemon.iv,
                              "cp": pokemon.cp,
                              "ncp": round(pokemon.ncp, 2),
                              "dps": round(pokemon.dps, 2)})

        if self.config_transfer and (not self.bot.config.test):
            candy = response_dict.get("responses", {}).get("RELEASE_POKEMON", {}).get("candy_awarded", 0)

            inventory.candies().get(pokemon.pokemon_id).add(candy)
            inventory.pokemons().remove(pokemon.id)

            action_delay(self.transfer_wait_min, self.transfer_wait_max)

        return True
Esempio n. 3
0
 def get_family_ids(self, pokemon):
     family_id = inventory.pokemons().data_for(
         pokemon["pokemon_id"]).first_evolution_id
     ids = [family_id]
     ids += inventory.pokemons().data_for(family_id).next_evolutions_all[:]
     # ids have now all family ids
     return ids
    def upgrade_pokemon(self, pokemon):
        level = int(pokemon.level * 2) - 1
        candy = inventory.candies().get(pokemon.pokemon_id)

        for i in range(level, 80):
            upgrade_cost = self.pokemon_upgrade_cost[i - 1]
            upgrade_candy_cost = upgrade_cost[0]
            upgrade_stardust_cost = upgrade_cost[1]

            if self.config_upgrade and (not self.bot.config.test):
                response_dict = self.bot.api.upgrade_pokemon(
                    pokemon_id=pokemon.unique_id)
            else:
                response_dict = {
                    "responses": {
                        "UPGRADE_POKEMON": {
                            "result": SUCCESS
                        }
                    }
                }

            if not response_dict:
                return False

            result = response_dict.get("responses",
                                       {}).get("UPGRADE_POKEMON",
                                               {}).get("result", 0)

            if result != SUCCESS:
                return False

            upgrade = response_dict.get("responses", {}).get(
                "UPGRADE_POKEMON", {}).get("upgraded_pokemon", {})

            if self.config_upgrade and (not self.bot.config.test):
                candy.consume(upgrade_candy_cost)
                self.stardust_count -= upgrade_stardust_cost

            self.emit_event(
                "pokemon_upgraded",
                formatted=
                "Upgraded {pokemon} [IV {iv}] [CP {cp}] [{candy} candies] [{stardust} stardust]",
                data={
                    "pokemon": pokemon.name,
                    "iv": pokemon.iv,
                    "cp": pokemon.cp,
                    "candy": candy.quantity,
                    "stardust": self.stardust_count
                })

            if self.config_upgrade and (not self.bot.config.test):
                inventory.pokemons().remove(pokemon.unique_id)

                new_pokemon = inventory.Pokemon(upgrade)
                inventory.pokemons().add(new_pokemon)

                action_delay(self.config_transfer_wait_min,
                             self.config_transfer_wait_max)

        return True
Esempio n. 5
0
    def release_pokemon(self, pokemon):
        """

        :type pokemon: Pokemon
        """
        try:
            if self.bot.config.test:
                candy_awarded = 1
            else:
                response_dict = self.bot.api.release_pokemon(
                    pokemon_id=pokemon.id)
                candy_awarded = response_dict['responses']['RELEASE_POKEMON'][
                    'candy_awarded']
        except KeyError:
            return

        # We could refresh here too, but adding 1 saves a inventory request
        candy = inventory.candies().get(pokemon.pokemon_id)
        candy.add(candy_awarded)
        inventory.pokemons().remove(pokemon.id)
        self.bot.metrics.released_pokemon()
        self.emit_event(
            'pokemon_release',
            formatted='Exchanged {pokemon} [CP {cp}] [IV {iv}] for candy.',
            data={
                'pokemon': pokemon.name,
                'cp': pokemon.cp,
                'iv': pokemon.iv,
                'ncp': pokemon.cp_percent,
                'dps': pokemon.moveset.dps
            })
        action_delay(self.transfer_wait_min, self.transfer_wait_max)
Esempio n. 6
0
    def _execute_pokemon_evolve(self, pokemon, cache):
        if pokemon.name in cache:
            return False

        response_dict = self.api.evolve_pokemon(pokemon_id=pokemon.id)
        if response_dict.get("responses", {}).get("EVOLVE_POKEMON", {}).get("result", 0) == 1:
            self.emit_event(
                "pokemon_evolved",
                formatted="Successfully evolved {pokemon} with CP {cp} and IV {iv}!",
                data={"pokemon": pokemon.name, "iv": pokemon.iv, "cp": pokemon.cp, "ncp": "?", "dps": "?", "xp": "?"},
            )
            awarded_candies = response_dict.get("responses", {}).get("EVOLVE_POKEMON", {}).get("candy_awarded", 0)
            inventory.candies().get(pokemon.pokemon_id).consume(pokemon.evolution_cost - awarded_candies)
            inventory.pokemons().remove(pokemon.id)
            pokemon = Pokemon(
                response_dict.get("responses", {}).get("EVOLVE_POKEMON", {}).get("evolved_pokemon_data", {})
            )
            inventory.pokemons().add(pokemon)
            sleep(self.evolve_speed)
            return True
        else:
            # cache pokemons we can't evolve. Less server calls
            cache[pokemon.name] = 1
            sleep(0.7)
            return False
Esempio n. 7
0
    def release_pokemon(self, pokemon):
        """

        :type pokemon: Pokemon
        """
        try:
            if self.bot.config.test:
                candy_awarded = 1
            else:
                response_dict = self.bot.api.release_pokemon(pokemon_id=pokemon.id)
                candy_awarded = response_dict['responses']['RELEASE_POKEMON']['candy_awarded']
        except KeyError:
            return

        # We could refresh here too, but adding 1 saves a inventory request
        candy = inventory.candies().get(pokemon.pokemon_id)
        candy.add(candy_awarded)
        inventory.pokemons().remove(pokemon.id)
        self.bot.metrics.released_pokemon()
        self.emit_event(
            'pokemon_release',
            formatted='Exchanged {pokemon} [CP {cp}] [IV {iv}] for candy.',
            data={
                'pokemon': pokemon.name,
                'cp': pokemon.cp,
                'iv': pokemon.iv,
                'ncp': pokemon.cp_percent,
                'dps': pokemon.moveset.dps
            }
        )
        action_delay(self.bot.config.action_wait_min, self.bot.config.action_wait_max)
Esempio n. 8
0
    def _execute_pokemon_evolve(self, pokemon, cache):
        if pokemon.name in cache:
            return False

        response_dict = self.api.evolve_pokemon(pokemon_id=pokemon.id)
        if response_dict.get('responses', {}).get('EVOLVE_POKEMON', {}).get('result', 0) == 1:
            self.emit_event(
                'pokemon_evolved',
                formatted="Successfully evolved {pokemon} with CP {cp} and IV {iv}!",
                data={
                    'pokemon': pokemon.name,
                    'iv': pokemon.iv,
                    'cp': pokemon.cp,
                    'ncp': '?',
                    'dps': '?',
                    'xp': '?'
                }
            )
            awarded_candies = response_dict.get('responses', {}).get('EVOLVE_POKEMON', {}).get('candy_awarded', 0)
            inventory.candies().get(pokemon.pokemon_id).consume(pokemon.evolution_cost - awarded_candies)
            inventory.pokemons().remove(pokemon.id)
            pokemon = Pokemon(response_dict.get('responses', {}).get('EVOLVE_POKEMON', {}).get('evolved_pokemon_data', {}))
            inventory.pokemons().add(pokemon)
            sleep(self.evolve_speed)
            return True
        else:
            # cache pokemons we can't evolve. Less server calls
            cache[pokemon.name] = 1
            sleep(0.7)
            return False
    def release_pokemon(self, pokemon):
        """

        :type pokemon: Pokemon
        """
        try:
            if self.bot.config.test:
                candy_awarded = 1
            else:
                request = self.bot.api.create_request()
                request.release_pokemon(pokemon_id=pokemon.unique_id)
                response_dict = request.call()
                
                candy_awarded = response_dict['responses'][
                    'RELEASE_POKEMON']['candy_awarded']
        except KeyError:
            return

        # We could refresh here too, but adding 1 saves a inventory request
        candy = inventory.candies().get(pokemon.pokemon_id)
        candy.add(candy_awarded)
        inventory.pokemons().remove(pokemon.unique_id)
        self.bot.metrics.released_pokemon()
        self.emit_event(
            'pokemon_release',
            data={
                'pokemon': pokemon.name,
                'iv': pokemon.iv,
                'cp': pokemon.cp,
                'ivcp': pokemon.ivcp,
                'candy': candy.quantity,
                'candy_type': candy.type
            },
            formatted="Released {} (CP: {}, IV: {}, IVCP: {:.2f}) You now have"
                      " {} {} candies".format(pokemon.name, pokemon.cp,
                                              pokemon.iv, pokemon.ivcp,
                                              candy.quantity, candy.type)
        )
        with self.bot.database as conn:
            c = conn.cursor()
            c.execute(
                "SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='transfer_log'")

        result = c.fetchone()

        while True:
            if result[0] == 1:
                conn.execute('''INSERT INTO transfer_log (pokemon, iv, cp) VALUES (?, ?, ?)''',
                             (pokemon.name, pokemon.iv, pokemon.cp))
                break
            else:
                self.emit_event(
                    'transfer_log',
                    sender=self,
                    level='info',
                    formatted="transfer_log table not found, skipping log"
                )
                break
        action_delay(self.transfer_wait_min, self.transfer_wait_max)
    def _execute_pokemon_evolve(self, pokemon, cache):
        if pokemon.name in cache:
            return False

        response_dict = self.api.evolve_pokemon(pokemon_id=pokemon.unique_id)
        if response_dict.get('responses', {}).get('EVOLVE_POKEMON', {}).get('result', 0) == 1:
            xp = response_dict.get("responses", {}).get("EVOLVE_POKEMON", {}).get("experience_awarded", 0)
            evolution = response_dict.get("responses", {}).get("EVOLVE_POKEMON", {}).get("evolved_pokemon_data", {})
            awarded_candies = response_dict.get('responses', {}).get('EVOLVE_POKEMON', {}).get('candy_awarded', 0)
            candy = inventory.candies().get(pokemon.pokemon_id)

            candy.consume(pokemon.evolution_cost - awarded_candies)

            self.emit_event(
                'pokemon_evolved',
                formatted="*Evolved {}* (IV {}) (CP {}) ({} candies) (+{} xp)".format(pokemon.name, pokemon.iv, pokemon.cp, candy.quantity, xp),
                data={
                    'pokemon': pokemon.name,
                    'iv': pokemon.iv,
                    'cp': pokemon.cp,
                    'candy': candy.quantity,
                    'xp': xp,
                }
            )

            inventory.pokemons().remove(pokemon.unique_id)
            new_pokemon = inventory.Pokemon(evolution)
            inventory.pokemons().add(new_pokemon)
            inventory.player().exp += xp

            action_delay(self.min_evolve_speed, self.max_evolve_speed)
            evolve_result = True
        else:
            # cache pokemons we can't evolve. Less server calls
            cache[pokemon.name] = 1
            sleep(0.7)
            evolve_result = False

        with self.bot.database as conn:
            c = conn.cursor()
            c.execute("SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='evolve_log'")

        result = c.fetchone()

        while True:
            if result[0] == 1:
                conn.execute('''INSERT INTO evolve_log (pokemon, iv, cp) VALUES (?, ?, ?)''', (pokemon.name, pokemon.iv, pokemon.cp))
                break
            else:
                self.emit_event(
                    'evolve_log',
                    sender=self,
                    level='info',
                    formatted="evolve_log table not found, skipping log"
                )
                break

        return evolve_result
Esempio n. 11
0
 def _hatch_eggs(self):
     response_dict = self.bot.api.get_hatched_eggs()
     log_color = 'green'
     try:
         result = reduce(dict.__getitem__, ["responses", "GET_HATCHED_EGGS"], response_dict)
     except KeyError:
         return
     pokemon_ids = []
     if 'pokemon_id' in result:
         pokemon_ids = [id for id in result['pokemon_id']]
     stardust = result.get('stardust_awarded', "error")
     candy = result.get('candy_awarded', "error")
     xp = result.get('experience_awarded', "error")
     sleep(self.hatching_animation_delay)
     try:
         pokemon_data = self._check_inventory(pokemon_ids)
         for pokemon in pokemon_data:
             # pokemon ids seem to be offset by one
             if pokemon['pokemon_id']!=-1:
                 pokemon['name'] = self.bot.pokemon_list[(pokemon.get('pokemon_id')-1)]['Name']
                 #remove as egg and add as pokemon
                 inventory.pokemons().remove(pokemon['id'])
                 inventory.pokemons().add(inventory.Pokemon(pokemon))
             else:
                 pokemon['name'] = "error"
     except:
         pokemon_data = [{"name":"error", "cp":"error", "iv":"error"}]
     if not pokemon_ids or not pokemon_data or pokemon_data[0]['name'] == "error":
         self.emit_event(
             'egg_hatched',
             data={
                 'pokemon': 'error',
                 'cp': 'error',
                 'iv': 'error',
                 'exp': 'error',
                 'stardust': 'error',
                 'candy': 'error',
             }
         )
         return
     for i in range(len(pokemon_data)):
         msg = "Egg hatched with a {pokemon} (CP {cp} - IV {iv}), {exp} exp, {stardust} stardust and {candy} candies."
         self.bot.metrics.hatched_eggs(1)
         self.emit_event(
             'egg_hatched',
             formatted=msg,
             data={
                 'pokemon': pokemon_data[i]['name'],
                 'cp': pokemon_data[i]['cp'],
                 'iv': "{} {}".format(
                     "/".join(map(str, pokemon_data[i]['iv'])),
                     round(sum(pokemon_data[i]['iv'])/self.max_iv, 2)
                 ),
                 'exp': xp[i],
                 'stardust': stardust[i],
                 'candy': candy[i],
             }
         )
Esempio n. 12
0
    def release_pokemon(self, pokemon):
        """

        :type pokemon: Pokemon
        """
        try:
            if self.bot.config.test:
                candy_awarded = 1
            else:
                request = self.bot.api.create_request()
                request.release_pokemon(pokemon_id=pokemon.unique_id)
                response_dict = request.call()

                candy_awarded = response_dict['responses']['RELEASE_POKEMON'][
                    'candy_awarded']
        except KeyError:
            return

        # We could refresh here too, but adding 1 saves a inventory request
        candy = inventory.candies().get(pokemon.pokemon_id)
        candy.add(candy_awarded)
        inventory.pokemons().remove(pokemon.unique_id)
        self.bot.metrics.released_pokemon()
        self.emit_event(
            'pokemon_release',
            data={
                'pokemon': pokemon.name,
                'iv': pokemon.iv,
                'cp': pokemon.cp,
                'ivcp': pokemon.ivcp,
                'candy': candy.quantity,
                'candy_type': candy.type
            },
            formatted="Released {} (CP: {}, IV: {}, IVCP: {:.2f}) You now have"
            " {} {} candies".format(pokemon.name, pokemon.cp, pokemon.iv,
                                    pokemon.ivcp, candy.quantity, candy.type))
        with self.bot.database as conn:
            c = conn.cursor()
            c.execute(
                "SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='transfer_log'"
            )

        result = c.fetchone()

        while True:
            if result[0] == 1:
                conn.execute(
                    '''INSERT INTO transfer_log (pokemon, iv, cp) VALUES (?, ?, ?)''',
                    (pokemon.name, pokemon.iv, pokemon.cp))
                break
            else:
                self.emit_event(
                    'transfer_log',
                    sender=self,
                    level='info',
                    formatted="transfer_log table not found, skipping log")
                break
        action_delay(self.transfer_wait_min, self.transfer_wait_max)
Esempio n. 13
0
    def _execute_pokemon_evolve(self, pokemon, cache):
        if pokemon.name in cache:
            return False

        response_dict = self.bot.api.evolve_pokemon(pokemon_id=pokemon.unique_id)
        if response_dict.get('responses', {}).get('EVOLVE_POKEMON', {}).get('result', 0) == 1:
            xp = response_dict.get("responses", {}).get("EVOLVE_POKEMON", {}).get("experience_awarded", 0)
            evolution = response_dict.get("responses", {}).get("EVOLVE_POKEMON", {}).get("evolved_pokemon_data", {})
            awarded_candies = response_dict.get('responses', {}).get('EVOLVE_POKEMON', {}).get('candy_awarded', 0)
            candy = inventory.candies().get(pokemon.pokemon_id)

            candy.consume(pokemon.evolution_cost - awarded_candies)

            self.emit_event(
                'pokemon_evolved',
                formatted="*Evolved {}* (IV {}) (CP {}) ({} candies) (+{} xp)".format(pokemon.name, pokemon.iv, pokemon.cp, candy.quantity, xp),
                data={
                    'pokemon': pokemon.name,
                    'iv': pokemon.iv,
                    'cp': pokemon.cp,
                    'candy': candy.quantity,
                    'xp': xp,
                }
            )

            inventory.pokemons().remove(pokemon.unique_id)
            new_pokemon = inventory.Pokemon(evolution)
            inventory.pokemons().add(new_pokemon)
            inventory.player().exp += xp

            action_delay(self.min_evolve_speed, self.max_evolve_speed)
            evolve_result = True
        else:
            # cache pokemons we can't evolve. Less server calls
            cache[pokemon.name] = 1
            sleep(0.7)
            evolve_result = False

        with self.bot.database as conn:
            c = conn.cursor()
            c.execute("SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='evolve_log'")

        result = c.fetchone()

        while True:
            if result[0] == 1:
                conn.execute('''INSERT INTO evolve_log (pokemon, iv, cp) VALUES (?, ?, ?)''', (pokemon.name, pokemon.iv, pokemon.cp))
                break
            else:
                self.emit_event(
                    'evolve_log',
                    sender=self,
                    level='info',
                    formatted="evolve_log table not found, skipping log"
                )
                break

        return evolve_result
Esempio n. 14
0
    def get_nearby_pokemons(self):
        radius = self.config_max_distance

        pokemons = [
            p for p in self.bot.cell["nearby_pokemons"]
            if self.get_distance(self.bot.start_position, p) <= radius
        ]

        if 'wild_pokemons' in self.bot.cell:
            for pokemon in self.bot.cell['wild_pokemons']:
                if pokemon['encounter_id'] in map(
                        lambda pokemon: pokemon['encounter_id'], pokemons):
                    # Already added this Pokemon
                    continue
                if self.get_distance(self.bot.start_position,
                                     pokemon) <= radius:
                    pokemons.append(pokemon)

        if 'catchable_pokemons' in self.bot.cell:
            for pokemon in self.bot.cell['catchable_pokemons']:
                if pokemon['encounter_id'] in map(
                        lambda pokemon: pokemon['encounter_id'], pokemons):
                    # Already added this Pokemon
                    continue
                if self.get_distance(self.bot.start_position,
                                     pokemon) <= radius:
                    pokemons.append(pokemon)

        for pokemon in pokemons:
            if "pokemon_data" in pokemon:
                pokemon["pokemon_id"] = pokemon["pokemon_data"]["pokemon_id"]
                pokemon["name"] = inventory.pokemons().name_for(
                    pokemon["pokemon_id"])

            if "name" not in pokemon and "pokemon_id" not in pokemon:
                self.logger.warning("Strange result? %s" % pokemon)
                # Skip this one!
                continue

            pokemon["distance"] = self.get_distance(self.bot.position, pokemon)

            if "name" not in pokemon:
                pokemon["name"] = inventory.pokemons().name_for(
                    pokemon["pokemon_id"])
            if "pokemon_id" not in pokemon:
                pokemon["pokemon_id"] = inventory.pokemons().id_for(
                    pokemon["name"])

            pokemon["candies"] = inventory.candies().get(
                pokemon["pokemon_id"]).quantity
            # Pokemon also has a fort_id of the PokeStop the Pokemon is hiding at.
            # We should set our first destination at that Pokestop.

        pokemons.sort(key=lambda p: p["distance"])

        return pokemons
Esempio n. 15
0
    def transfer_pokemon(self, pokemon):
        if self.config_transfer and (not self.bot.config.test):
            response_dict = self.bot.api.release_pokemon(
                pokemon_id=pokemon.unique_id)
        else:
            response_dict = {
                "responses": {
                    "RELEASE_POKEMON": {
                        "candy_awarded": 0
                    }
                }
            }

        if not response_dict:
            return False

        candy_awarded = response_dict.get("responses",
                                          {}).get("RELEASE_POKEMON",
                                                  {}).get("candy_awarded", 0)
        candy = inventory.candies().get(pokemon.pokemon_id)

        if self.config_transfer and (not self.bot.config.test):
            candy.add(candy_awarded)

        self.emit_event(
            "pokemon_release",
            formatted=
            "Exchanged {pokemon} [IV {iv}] [CP {cp}] [{candy} candies]",
            data={
                "pokemon": pokemon.name,
                "iv": pokemon.iv,
                "cp": pokemon.cp,
                "candy": candy.quantity
            })

        if self.config_transfer and (not self.bot.config.test):
            inventory.pokemons().remove(pokemon.unique_id)

            with self.bot.database as db:
                cursor = db.cursor()
                cursor.execute(
                    "SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='transfer_log'"
                )

                db_result = cursor.fetchone()

                if db_result[0] == 1:
                    db.execute(
                        "INSERT INTO transfer_log (pokemon, iv, cp) VALUES (?, ?, ?)",
                        (pokemon.name, pokemon.iv, pokemon.cp))

            action_delay(self.config_action_wait_min,
                         self.config_action_wait_max)

        return True
Esempio n. 16
0
    def evolve_pokemon(self, pokemon):
        while pokemon.unique_id in self.evolution_map:
            pokemon = self.evolution_map[pokemon.unique_id]

        if self.config_evolve and (not self.bot.config.test):
            response_dict = self.bot.api.evolve_pokemon(pokemon_id=pokemon.unique_id)
        else:
            response_dict = {"responses": {"EVOLVE_POKEMON": {"result": SUCCESS}}}

        if not response_dict:
            return False

        result = response_dict.get("responses", {}).get("EVOLVE_POKEMON", {}).get("result", 0)

        if result != SUCCESS:
            return False

        xp = response_dict.get("responses", {}).get("EVOLVE_POKEMON", {}).get("experience_awarded", 0)
        candy_awarded = response_dict.get("responses", {}).get("EVOLVE_POKEMON", {}).get("candy_awarded", 0)
        candy = inventory.candies().get(pokemon.pokemon_id)
        evolution = response_dict.get("responses", {}).get("EVOLVE_POKEMON", {}).get("evolved_pokemon_data", {})

        if self.config_evolve and (not self.bot.config.test):
            candy.consume(pokemon.evolution_cost - candy_awarded)
            inventory.player().exp += xp

        self.emit_event("pokemon_evolved",
                        formatted="Evolved {pokemon} [IV {iv}] [CP {cp}] [{candy} candies] [+{xp} xp]",
                        data={"pokemon": pokemon.name,
                              "iv": pokemon.iv,
                              "cp": pokemon.cp,
                              "candy": candy.quantity,
                              "xp": xp})

        if self.config_evolve and (not self.bot.config.test):
            new_pokemon = inventory.Pokemon(evolution)

            self.evolution_map[pokemon.unique_id] = new_pokemon

            inventory.pokemons().remove(pokemon.unique_id)
            inventory.pokemons().add(new_pokemon)

            with self.bot.database as db:
                cursor = db.cursor()
                cursor.execute("SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='evolve_log'")

                db_result = cursor.fetchone()

                if db_result[0] == 1:
                    db.execute("INSERT INTO evolve_log (pokemon, iv, cp) VALUES (?, ?, ?)", (pokemon.name, pokemon.iv, pokemon.cp))

            sleep(self.config_evolve_time, 0.1)

        return True
Esempio n. 17
0
    def evolve_pokemon(self, pokemon):
        while pokemon.unique_id in self.evolution_map:
            pokemon = self.evolution_map[pokemon.unique_id]

        if self.config_evolve and (not self.bot.config.test):
            response_dict = self.bot.api.evolve_pokemon(pokemon_id=pokemon.unique_id)
        else:
            response_dict = {"responses": {"EVOLVE_POKEMON": {"result": SUCCESS}}}

        if not response_dict:
            return False

        result = response_dict.get("responses", {}).get("EVOLVE_POKEMON", {}).get("result", 0)

        if result != SUCCESS:
            return False

        xp = response_dict.get("responses", {}).get("EVOLVE_POKEMON", {}).get("experience_awarded", 0)
        candy_awarded = response_dict.get("responses", {}).get("EVOLVE_POKEMON", {}).get("candy_awarded", 0)
        candy = inventory.candies().get(pokemon.pokemon_id)
        evolution = response_dict.get("responses", {}).get("EVOLVE_POKEMON", {}).get("evolved_pokemon_data", {})

        if self.config_evolve and (not self.bot.config.test):
            candy.consume(pokemon.evolution_cost - candy_awarded)
            inventory.player().exp += xp

        self.emit_event("pokemon_evolved",
                        formatted="Evolved {pokemon} [IV {iv}] [CP {cp}] [{candy} candies] [+{xp} xp]",
                        data={"pokemon": pokemon.name,
                              "iv": pokemon.iv,
                              "cp": pokemon.cp,
                              "candy": candy.quantity,
                              "xp": xp})

        if self.config_evolve and (not self.bot.config.test):
            new_pokemon = inventory.Pokemon(evolution)

            self.evolution_map[pokemon.unique_id] = new_pokemon

            inventory.pokemons().remove(pokemon.unique_id)
            inventory.pokemons().add(new_pokemon)

            with self.bot.database as db:
                cursor = db.cursor()
                cursor.execute("SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='evolve_log'")

                db_result = cursor.fetchone()

                if db_result[0] == 1:
                    db.execute("INSERT INTO evolve_log (pokemon, iv, cp) VALUES (?, ?, ?)", (pokemon.name, pokemon.iv, pokemon.cp))

            sleep(self.config_evolve_time, 0.1)

        return True
    def upgrade_pokemon(self, pokemon):
        upgrade_level = min(self.config_upgrade_level, inventory.player().level + 1.5, 40)
        candy = inventory.candies().get(pokemon.pokemon_id)

        for i in range(int(pokemon.level * 2), int(upgrade_level * 2)):
            upgrade_cost = self.pokemon_upgrade_cost[i - 2]
            upgrade_candy_cost = upgrade_cost[0]
            upgrade_stardust_cost = upgrade_cost[1]

            if self.config_upgrade and (not self.bot.config.test):
                request = self.bot.api.create_request()
                request.upgrade_pokemon(pokemon_id=pokemon.unique_id)
                response_dict = request.call()
            else:
                response_dict = {"responses": {"UPGRADE_POKEMON": {"result": SUCCESS}}}

            if not response_dict:
                return False

            result = response_dict.get("responses", {}).get("UPGRADE_POKEMON", {}).get("result", 0)

            if result != SUCCESS:
                return False

            upgrade = response_dict.get("responses", {}).get("UPGRADE_POKEMON", {}).get("upgraded_pokemon", {})

            if self.config_upgrade and (not self.bot.config.test):
                candy.consume(upgrade_candy_cost)
                self.bot.stardust -= upgrade_stardust_cost

            new_pokemon = inventory.Pokemon(upgrade)
            self.emit_event("pokemon_upgraded",
                            formatted="Upgraded {pokemon} [IV {iv}] [CP {cp} -> {new_cp}] [{candy} candies] [{stardust} stardust]",
                            data={"pokemon": pokemon.name,
                                  "iv": pokemon.iv,
                                  "cp": pokemon.cp,
                                  "new_cp": new_pokemon.cp,
                                  "candy": candy.quantity,
                                  "stardust": self.bot.stardust})

            if self.config_upgrade and (not self.bot.config.test):
                inventory.pokemons().remove(pokemon.unique_id)

                new_pokemon = inventory.Pokemon(upgrade)
                inventory.pokemons().add(new_pokemon)
                pokemon = new_pokemon

                action_delay(self.config_action_wait_min, self.config_action_wait_max)

        return True
Esempio n. 19
0
 def _is_family_of_vip(self, pokemon):
     for fid in self.get_family_ids(pokemon):
         name = inventory.pokemons().name_for(fid)
         if self.bot.config.vips.get(name) == {}:
             return True
     # No, not a family member of the VIP
     return False
Esempio n. 20
0
 def work(self):
     """
     Iterate over all user pokemons and nickname if needed
     """
     for pokemon in pokemons().all():  # type: Pokemon
         if not pokemon.is_favorite or not self.ignore_favorites:
             self._nickname_pokemon(pokemon)
Esempio n. 21
0
    def check_buddy(self):
        self.buddy = self.bot.player_data.get("buddy_pokemon", {})
        self.buddyid = self._get_buddyid()

        if not self.buddy:
            self.lock_buddy = False
            return

        pokemon = next((p for p in inventory.pokemons().all() if p.unique_id == self.buddy["id"]), None)

        if not pokemon:
            return

        km_walked = inventory.player().player_stats.get("km_walked", 0)
        last_km_awarded = self.buddy.setdefault("last_km_awarded", km_walked)
        distance_walked = km_walked - last_km_awarded
        distance_needed = pokemon.buddy_distance_needed

        if distance_walked >= distance_needed:
            self.get_buddy_walked(pokemon)
            # self.buddy["start_km_walked"] can be empty here
            if 'start_km_walked' not in self.buddy:
                self.buddy["start_km_walked"] = 0
            self.buddy["last_km_awarded"] = self.buddy["start_km_walked"] + distance_needed * int(distance_walked / distance_needed)
            self.lock_buddy = False
        else:
            now = time.time()

            if self.no_log_until < now:
                self.no_log_until = now + LOG_TIME_INTERVAL
                self.emit_event("buddy_walked",
                                formatted="Buddy {pokemon} walking: {distance_walked:.2f} / {distance_needed:.2f} km",
                                data={"pokemon": pokemon.name,
                                      "distance_walked": distance_walked,
                                      "distance_needed": distance_needed})
Esempio n. 22
0
    def save_web_inventory(self):
        web_inventory = os.path.join(_base_dir, "web", "inventory-%s.json" % self.bot.config.username)

        with open(web_inventory, "r") as infile:
            ii = json.load(infile)

        ii = [x for x in ii if not x.get("inventory_item_data", {}).get("pokedex_entry", None)]
        ii = [x for x in ii if not x.get("inventory_item_data", {}).get("candy", None)]
        ii = [x for x in ii if not x.get("inventory_item_data", {}).get("item", None)]
        ii = [x for x in ii if not x.get("inventory_item_data", {}).get("pokemon_data", None)]

        for pokedex in inventory.pokedex().all():
            ii.append({"inventory_item_data": {"pokedex_entry": pokedex}})

        for family_id, candy in inventory.candies()._data.items():
            ii.append({"inventory_item_data": {"candy": {"family_id": family_id, "candy": candy.quantity}}})

        for item_id, item in inventory.items()._data.items():
            ii.append({"inventory_item_data": {"item": {"item_id": item_id, "count": item.count}}})

        for pokemon in inventory.pokemons().all():
            ii.append({"inventory_item_data": {"pokemon_data": pokemon._data}})

        with open(web_inventory, "w") as outfile:
            json.dump(ii, outfile)
Esempio n. 23
0
    def check_buddy(self):
        self.buddy = self.bot.player_data.get("buddy_pokemon", {})
        self.buddyid = self._get_buddyid()

        if not self.buddy:
            self.lock_buddy = False
            return

        pokemon = next((p for p in inventory.pokemons().all() if p.unique_id == self.buddy["id"]), None)

        if not pokemon:
            return

        km_walked = inventory.player().player_stats.get("km_walked", 0)
        last_km_awarded = self.buddy.setdefault("last_km_awarded", km_walked)
        distance_walked = km_walked - last_km_awarded
        distance_needed = pokemon.buddy_distance_needed

        if distance_walked >= distance_needed:
            self.get_buddy_walked(pokemon)
            # self.buddy["start_km_walked"] can be empty here
            if 'start_km_walked' not in self.buddy:
                self.buddy["start_km_walked"] = 0
            self.buddy["last_km_awarded"] = self.buddy["start_km_walked"] + distance_needed * int(distance_walked / distance_needed)
            self.lock_buddy = False
        else:
            now = time.time()

            if self.no_log_until < now:
                self.no_log_until = now + LOG_TIME_INTERVAL
                self.emit_event("buddy_walked",
                                formatted="Buddy {pokemon} walking: {distance_walked:.2f} / {distance_needed:.2f} km",
                                data={"pokemon": pokemon.name,
                                      "distance_walked": distance_walked,
                                      "distance_needed": distance_needed})
Esempio n. 24
0
    def _get_pokemon_by_name(self, name):
        pokemons = inventory.pokemons().all()
        pokemon = None
        for p in pokemons:
            if p.name.lower() == name.lower():
                pokemon = p
                break

        if pokemon is None:
            self.emit_event(
                'buddy_not_available',
                formatted='{name} was not found',
                data={
                    'name': name
                }
            )
            return None

        fam_id = pokemon.family_id
        poke_id = pokemon.pokemon_id
        if self.best_in_family:
            poke_list = [p for p in pokemons if p.family_id == fam_id]
        else:
            poke_list = [p for p in pokemons if p.pokemon_id == poke_id]
        poke_list.sort(key=lambda p: p.cp, reverse=True)
        return poke_list[0]
Esempio n. 25
0
 def _is_family_of_vip(self, pokemon_id):
     for fid in self.get_family_ids(pokemon_id):
         name = inventory.pokemons().name_for(fid)
         if self.bot.config.vips.get(name) == {}:
             return True
     # No, not a family member of the VIP
     return False
    def initialize(self):
        self.max_pokemon_storage = inventory.get_pokemon_inventory_size()
        self.last_pokemon_count = 0
        self.pokemon_names = [p.name for p in inventory.pokemons().STATIC_DATA]
        self.stardust_count = 0
        self.ongoing_stardust_count = 0

        pokemon_upgrade_cost_file = os.path.join(_base_dir, "data", "pokemon_upgrade_cost.json")

        with open(pokemon_upgrade_cost_file, "r") as fd:
            self.pokemon_upgrade_cost = json.load(fd)

        self.config_transfer = self.config.get("transfer", False)
        self.config_transfer_wait_min = self.config.get("transfer_wait_min", 3)
        self.config_transfer_wait_max = self.config.get("transfer_wait_max", 5)
        self.config_evolve = self.config.get("evolve", False)
        self.config_evolve_time = self.config.get("evolve_time", 25)
        self.config_evolve_for_xp = self.config.get("evolve_for_xp", True)
        self.config_evolve_only_with_lucky_egg = self.config.get("evolve_only_with_lucky_egg", False)
        self.config_evolve_count_for_lucky_egg = self.config.get("evolve_count_for_lucky_egg", 80)
        self.config_may_use_lucky_egg = self.config.get("may_use_lucky_egg", False)
        self.config_upgrade = self.config.get("upgrade", False)
        self.config_upgrade_level = self.config.get("upgrade_level", 60)
        self.config_groups = self.config.get("groups", {"gym": ["Dragonite", "Snorlax", "Lapras", "Arcanine"]})
        self.config_keep = self.config.get("keep", [{"mode": "by_family", "top": 1, "sort": [{"iv": 0.9}], "evolve": True, "upgrade": False},
                                                    {"mode": "by_family", "top": 1, "sort": [{"ncp": 0.9}], "evolve": True, "upgrade": False},
                                                    {"mode": "by_family", "top": 1, "sort": ["cp"], "evolve": False, "upgrade": False},
                                                    {"mode": "by_family", "top": 3, "names": ["gym"], "sort": [{"iv": 0.9}, {"ncp": 0.9}], "evolve": True, "upgrade": True}])

        if (not self.config_may_use_lucky_egg) and self.config_evolve_only_with_lucky_egg:
            self.config_evolve = False
    def initialize(self):
        self.max_pokemon_storage = inventory.get_pokemon_inventory_size()
        self.last_pokemon_count = 0
        self.pokemon_names = [p.name for p in inventory.pokemons().STATIC_DATA]
        self.ongoing_stardust_count = 0

        pokemon_upgrade_cost_file = os.path.join(_base_dir, "data", "pokemon_upgrade_cost.json")

        with open(pokemon_upgrade_cost_file, "r") as fd:
            self.pokemon_upgrade_cost = json.load(fd)

        if self.config.get("keep", None) is not None:
            raise ConfigException("Pokemon Optimizer configuration has changed. See docs/pokemon_optimized.md or configs/config.json.optimizer.example")

        self.config_min_slots_left = self.config.get("min_slots_left", 5)
        self.config_transfer = self.config.get("transfer", False)
        self.config_transfer_wait_min = self.config.get("transfer_wait_min", 3)
        self.config_transfer_wait_max = self.config.get("transfer_wait_max", 5)
        self.config_evolve = self.config.get("evolve", False)
        self.config_evolve_time = self.config.get("evolve_time", 25)
        self.config_evolve_for_xp = self.config.get("evolve_for_xp", True)
        self.config_evolve_only_with_lucky_egg = self.config.get("evolve_only_with_lucky_egg", False)
        self.config_evolve_count_for_lucky_egg = self.config.get("evolve_count_for_lucky_egg", 80)
        self.config_may_use_lucky_egg = self.config.get("may_use_lucky_egg", False)
        self.config_upgrade = self.config.get("upgrade", False)
        self.config_upgrade_level = self.config.get("upgrade_level", 60)
        self.config_groups = self.config.get("groups", {"gym": ["Dragonite", "Snorlax", "Lapras", "Arcanine"]})
        self.config_rules = self.config.get("rules", [{"mode": "by_family", "top": 1, "sort": ["iv"], "evolve": {"iv": 0.9}},
                                                      {"mode": "by_family", "top": 1, "sort": ["ncp"], "evolve": {"ncp": 0.9}},
                                                      {"mode": "by_family", "top": 1, "sort": ["cp"]},
                                                      {"mode": "by_family", "top": 3, "names": ["gym"], "sort": ["iv", "ncp"], "evolve": {"iv": 0.9, "ncp": 0.9}, "upgrade": {"iv": 0.9, "ncp": 0.9}}])

        if (not self.config_may_use_lucky_egg) and self.config_evolve_only_with_lucky_egg:
            self.config_evolve = False
Esempio n. 28
0
    def initialize(self):
        self.max_pokemon_storage = inventory.get_pokemon_inventory_size()
        self.last_pokemon_count = 0
        self.pokemon_names = [p.name for p in inventory.pokemons().STATIC_DATA]
        self.stardust_count = 0
        self.ongoing_stardust_count = 0

        pokemon_upgrade_cost_file = os.path.join(_base_dir, "data", "pokemon_upgrade_cost.json")

        with open(pokemon_upgrade_cost_file, "r") as fd:
            self.pokemon_upgrade_cost = json.load(fd)

        self.config_min_slots_left = self.config.get("min_slots_left", 5)
        self.config_transfer = self.config.get("transfer", False)
        self.config_transfer_wait_min = self.config.get("transfer_wait_min", 3)
        self.config_transfer_wait_max = self.config.get("transfer_wait_max", 5)
        self.config_evolve = self.config.get("evolve", False)
        self.config_evolve_time = self.config.get("evolve_time", 25)
        self.config_evolve_for_xp = self.config.get("evolve_for_xp", True)
        self.config_evolve_only_with_lucky_egg = self.config.get("evolve_only_with_lucky_egg", False)
        self.config_evolve_count_for_lucky_egg = self.config.get("evolve_count_for_lucky_egg", 80)
        self.config_may_use_lucky_egg = self.config.get("may_use_lucky_egg", False)
        self.config_upgrade = self.config.get("upgrade", False)
        self.config_upgrade_level = self.config.get("upgrade_level", 60)
        self.config_groups = self.config.get("groups", {"gym": ["Dragonite", "Snorlax", "Lapras", "Arcanine"]})
        self.config_keep = self.config.get("keep", [{"mode": "by_family", "top": 1, "sort": [{"iv": 0.9}], "evolve": True, "upgrade": False},
                                                    {"mode": "by_family", "top": 1, "sort": [{"ncp": 0.9}], "evolve": True, "upgrade": False},
                                                    {"mode": "by_family", "top": 1, "sort": ["cp"], "evolve": False, "upgrade": False},
                                                    {"mode": "by_family", "top": 3, "names": ["gym"], "sort": [{"iv": 0.9}, {"ncp": 0.9}], "evolve": True, "upgrade": True}])

        if (not self.config_may_use_lucky_egg) and self.config_evolve_only_with_lucky_egg:
            self.config_evolve = False
Esempio n. 29
0
    def _get_pokemon_by_name(self, name):
        pokemons = inventory.pokemons().all()
        pokemon = None
        for p in pokemons:
            if p.name.lower() == name.lower():
                pokemon = p
                break

        if pokemon is None:
            self.emit_event(
                'buddy_not_available',
                formatted='{name} was not found',
                data={
                    'name': name
                }
            )
            return None

        fam_id = pokemon.family_id
        poke_id = pokemon.pokemon_id
        if self.best_in_family:
            poke_list = [p for p in pokemons if p.family_id == fam_id]
        else:
            poke_list = [p for p in pokemons if p.pokemon_id == poke_id]
        poke_list.sort(key=lambda p: p.cp, reverse=True)
        return poke_list[0]
Esempio n. 30
0
    def work(self):

        if not self.enabled:
            return WorkerResult.SUCCESS

        # Check for pokemon to heal or revive
        to_revive = []
        self.to_heal = []
        pokemons = inventory.pokemons().all()
        pokemons.sort(key=lambda p: p.hp)
        for pokemon in pokemons:
            if pokemon.hp < 1.0:
                self.logger.info("Dead: %s (%s CP| %s/%s )" % (pokemon.name, pokemon.cp, pokemon.hp, pokemon.hp_max))
                to_revive += [pokemon]
            elif pokemon.hp < pokemon.hp_max:
                self.logger.info("Heal: %s (%s CP| %s/%s )" % (pokemon.name, pokemon.cp, pokemon.hp, pokemon.hp_max))
                self.to_heal += [pokemon]

        if len(self.to_heal) == 0 and len(to_revive) == 0:
            if self._should_print:
                self.next_update = datetime.now() + timedelta(seconds=120)
                #self.logger.info("No pokemon to heal or revive")
            return WorkerResult.SUCCESS
        # Okay, start reviving pokemons
        # Check revives and potions
        revives = inventory.items().get(Item.ITEM_REVIVE.value).count
        max_revives = inventory.items().get(Item.ITEM_MAX_REVIVE.value).count
        normal = inventory.items().get(Item.ITEM_POTION.value).count
        super_p = inventory.items().get(Item.ITEM_SUPER_POTION.value).count
        hyper = inventory.items().get(Item.ITEM_HYPER_POTION.value).count
        max_p = inventory.items().get(Item.ITEM_MAX_POTION.value).count

        self.logger.info("Healing %s pokemon" % len(self.to_heal))
        self.logger.info("Reviving %s pokemon" % len(to_revive))

        if self.revive_pokemon:
            if len(to_revive) > 0 and revives == 0 and max_revives == 0:
                if not self.warned_about_no_revives:
                    self.logger.info("No revives left! Can't revive %s pokemons." % len(to_revive))
                    self.warned_about_no_revives = True
            elif len(to_revive) > 0:
                self.logger.info("Reviving %s pokemon..." % len(to_revive))
                self.warned_about_no_revives = False
                for pokemon in to_revive:
                    self._revive_pokemon(pokemon)

        if self.heal_pokemon:
            if len(self.to_heal) > 0 and (normal + super_p + hyper + max_p) == 0:
                if not self.warned_about_no_potions:
                    self.logger.info("No potions left! Can't heal %s pokemon" % len(self.to_heal))
                    self.warned_about_no_potions = True
            elif len(self.to_heal) > 0:
                self.logger.info("Healing %s pokemon" % len(self.to_heal))
                self.warned_about_no_potions = False
                for pokemon in self.to_heal:
                    self._heal_pokemon(pokemon)

        if self._should_print:
            self.next_update = datetime.now() + timedelta(seconds=120)
            self.logger.info("Done healing/reviving pokemon")
Esempio n. 31
0
 def work(self):
     """
     Iterate over all user pokemons and nickname if needed
     """
     for pokemon in pokemons().all():  # type: Pokemon
         if not pokemon.is_favorite or not self.ignore_favorites:
             self._nickname_pokemon(pokemon)
Esempio n. 32
0
    def get_nearby_pokemons(self):
        radius = self.config_max_distance

        pokemons = [p for p in self.bot.cell["nearby_pokemons"] if self.get_distance(self.bot.start_position, p) <= radius]

        if 'wild_pokemons' in self.bot.cell:
            for pokemon in self.bot.cell['wild_pokemons']:
                if pokemon['encounter_id'] in map(lambda pokemon: pokemon['encounter_id'], pokemons):
                    # Already added this Pokemon
                    continue
                if self.get_distance(self.bot.start_position, pokemon) <= radius:
                    pokemons.append(pokemon)
        
        if 'catchable_pokemons' in self.bot.cell:
            for pokemon in self.bot.cell['catchable_pokemons']:
                if pokemon['encounter_id'] in map(lambda pokemon: pokemon['encounter_id'], pokemons):
                    # Already added this Pokemon
                    continue
                if self.get_distance(self.bot.start_position, pokemon) <= radius:
                    pokemons.append(pokemon)

        for pokemon in pokemons:
            if "pokemon_data" in pokemon:
                pokemon["pokemon_id"] = pokemon["pokemon_data"]["pokemon_id"]
                pokemon["name"] = inventory.pokemons().name_for(pokemon["pokemon_id"])

            if "name" not in pokemon and "pokemon_id" not in pokemon:
                self.logger.warning("Strange result? %s" % pokemon)
                # Skip this one!
                continue

            pokemon["distance"] = self.get_distance(self.bot.position, pokemon)
            
            if "name" not in pokemon:
                pokemon["name"] = inventory.pokemons().name_for(pokemon["pokemon_id"])
            if "pokemon_id" not in pokemon:
                pokemon["pokemon_id"] = inventory.pokemons().id_for(pokemon["name"])

            pokemon["candies"] = inventory.candies().get(pokemon["pokemon_id"]).quantity
            # Pokemon also has a fort_id of the PokeStop the Pokemon is hiding at.
            # We should set our first destination at that Pokestop.

        pokemons.sort(key=lambda p: p["distance"])

        return pokemons
Esempio n. 33
0
    def open_inventory(self):
        for pokemon in inventory.pokemons().all():
            setattr(pokemon, "ncp", pokemon.cp_percent)
            setattr(pokemon, "dps", pokemon.moveset.dps)
            setattr(pokemon, "dps_attack", pokemon.moveset.dps_attack)
            setattr(pokemon, "dps_defense", pokemon.moveset.dps_defense)

        self.stardust_count = self.get_stardust_count()
        self.ongoing_stardust_count = self.stardust_count
Esempio n. 34
0
    def get_pokemon_slot_left(self):
        pokemon_count = len(inventory.pokemons()._data)
        self.max_pokemon_storage = self.bot.player_data["max_pokemon_storage"]

        if pokemon_count != self.last_pokemon_count:
            self.last_pokemon_count = pokemon_count
            self.logger.info("Pokemon Bag: %s/%s", pokemon_count, self.max_pokemon_storage)

        return self.max_pokemon_storage - pokemon_count
Esempio n. 35
0
 def work(self):
     """
     Iterate over all user pokemons and nickname if needed
     """
     for pokemon in pokemons().all():  # type: Pokemon
         if not pokemon.is_favorite or not self.ignore_favorites:
             if pokemon.iv >= self.nickname_above_iv:
                 if self._nickname_pokemon(pokemon):
                     # Make the bot appears more human
                     action_delay(self.nickname_wait_min, self.nickname_wait_max)
Esempio n. 36
0
 def work(self):
     """
     Iterate over all user pokemons and nickname if needed
     """
     for pokemon in pokemons().all():  # type: Pokemon
         if not pokemon.is_favorite or not self.ignore_favorites:
             if pokemon.iv >= self.nickname_above_iv:
                 if self._nickname_pokemon(pokemon):
                     # Make the bot appears more human
                     action_delay(self.nickname_wait_min, self.nickname_wait_max)
Esempio n. 37
0
    def open_inventory(self):
        self.family_by_family_id.clear()

        for pokemon in inventory.pokemons(True).all():
            family_id = pokemon.first_evolution_id
            setattr(pokemon, "ncp", pokemon.cp_percent)
            setattr(pokemon, "dps", pokemon.moveset.dps)
            setattr(pokemon, "dps_attack", pokemon.moveset.dps_attack)
            setattr(pokemon, "dps_defense", pokemon.moveset.dps_defense)

            self.family_by_family_id.setdefault(family_id, []).append(pokemon)
Esempio n. 38
0
    def open_inventory(self):
        for pokemon in inventory.pokemons().all():
            setattr(pokemon, "ncp", pokemon.cp_percent)
            setattr(pokemon, "dps", pokemon.moveset.dps)
            setattr(pokemon, "dps1", pokemon.fast_attack.dps)
            setattr(pokemon, "dps2", pokemon.charged_attack.dps)
            setattr(pokemon, "dps_attack", pokemon.moveset.dps_attack)
            setattr(pokemon, "dps_defense", pokemon.moveset.dps_defense)

        self.stardust_count = self.get_stardust_count()
        self.ongoing_stardust_count = self.stardust_count
Esempio n. 39
0
    def work(self):
        if not self._should_work():
            return

        pokemon_groups = self._release_pokemon_get_groups()
        for pokemon_id, group in pokemon_groups.iteritems():
            pokemon_name = Pokemons.name_for(pokemon_id)
            self._release_pokemon_worst_in_group(group, pokemon_name)

        group = [p for p in inventory.pokemons().all()
                 if p.in_fort is False and p.is_favorite is False]
        self._release_pokemon_worst_in_group(group, 'all')
Esempio n. 40
0
  def work(self):
    bad_pokemons = [p for p in inventory.pokemons().all() if p.is_bad]
    
    if len(bad_pokemons) > 0:
      if self._should_print():
          self.logger.warning("You have %s bad (slashed) Pokemon!" % len(bad_pokemons))
          self._compute_next_update()
          sleep(1)
      if self.config_transfer:
        self.transfer_pokemon(bad_pokemons)

    return WorkerResult.SUCCESS
Esempio n. 41
0
    def get_nearby_pokemons(self):
        radius = self.config_max_distance

        pokemons = [p for p in self.bot.cell["nearby_pokemons"] if self.get_distance(self.bot.start_position, p) <= radius]

        for pokemon in pokemons:
            pokemon["distance"] = self.get_distance(self.bot.position, p)
            pokemon["name"] = inventory.pokemons().name_for(pokemon["pokemon_id"])

        pokemons.sort(key=lambda p: p["distance"])

        return pokemons
Esempio n. 42
0
    def _get_closest_name(self, name):
        if not name:
            return

        pokemon_names = [p.name for p in inventory.pokemons().STATIC_DATA]
        closest_names = difflib.get_close_matches(name, pokemon_names, 1)

        if closest_names:
            closest_name = closest_names[0]
            return closest_name

        return name
Esempio n. 43
0
    def save_web_inventory(self):
        web_inventory = os.path.join(
            _base_dir, "web", "inventory-%s.json" % self.bot.config.username)

        with open(web_inventory, "r") as infile:
            ii = json.load(infile)

        ii = [
            x for x in ii
            if not x.get("inventory_item_data", {}).get("pokedex_entry", None)
        ]
        ii = [
            x for x in ii
            if not x.get("inventory_item_data", {}).get("candy", None)
        ]
        ii = [
            x for x in ii
            if not x.get("inventory_item_data", {}).get("item", None)
        ]
        ii = [
            x for x in ii
            if not x.get("inventory_item_data", {}).get("pokemon_data", None)
        ]

        for pokedex in inventory.pokedex().all():
            ii.append({"inventory_item_data": {"pokedex_entry": pokedex}})

        for family_id, candy in inventory.candies()._data.items():
            ii.append({
                "inventory_item_data": {
                    "candy": {
                        "family_id": family_id,
                        "candy": candy.quantity
                    }
                }
            })

        for item_id, item in inventory.items()._data.items():
            ii.append({
                "inventory_item_data": {
                    "item": {
                        "item_id": item_id,
                        "count": item.count
                    }
                }
            })

        for pokemon in inventory.pokemons().all():
            ii.append({"inventory_item_data": {"pokemon_data": pokemon._data}})

        with open(web_inventory, "w") as outfile:
            json.dump(ii, outfile)
Esempio n. 44
0
    def work(self):
        bad_pokemons = [p for p in inventory.pokemons().all() if p.is_bad]

        if len(bad_pokemons) > 0:
            if self._should_print():
                self.logger.warning("You have %s bad (slashed) Pokemon!" %
                                    len(bad_pokemons))
                self._compute_next_update()
                sleep(1)
            if self.config_transfer:
                self.transfer_pokemon(bad_pokemons)

        return WorkerResult.SUCCESS
    def work(self):
        if not self._should_work():
            return

        pokemon_groups = self._release_pokemon_get_groups()
        for pokemon_id, group in pokemon_groups.iteritems():
            pokemon_name = Pokemons.name_for(pokemon_id)
            self._release_pokemon_worst_in_group(group, pokemon_name)

        if self.bot.config.release.get('all'):
            group = [p for p in inventory.pokemons().all()
                     if p.in_fort is False and p.is_favorite is False]
            self._release_pokemon_worst_in_group(group, 'all')
    def _release_pokemon_get_groups(self):
        pokemon_groups = {}
        for pokemon in inventory.pokemons().all():
            if pokemon.in_fort or pokemon.is_favorite:
                continue

            group_id = pokemon.pokemon_id

            if group_id not in pokemon_groups:
                pokemon_groups[group_id] = []

            pokemon_groups[group_id].append(pokemon)

        return pokemon_groups
Esempio n. 47
0
    def open_inventory(self):
        for pokemon in inventory.pokemons().all():
            setattr(pokemon, "ncp", pokemon.cp_percent)
            setattr(pokemon, "dps", pokemon.moveset.dps)
            setattr(pokemon, "dps1", pokemon.fast_attack.dps)
            setattr(pokemon, "dps2", pokemon.charged_attack.dps)
            setattr(pokemon, "dps_attack", pokemon.moveset.dps_attack)
            setattr(pokemon, "dps_defense", pokemon.moveset.dps_defense)
            setattr(pokemon, "attack_perfection",
                    pokemon.moveset.attack_perfection)
            setattr(pokemon, "defense_perfection",
                    pokemon.moveset.defense_perfection)

        self.ongoing_stardust_count = self.bot.stardust
Esempio n. 48
0
    def transfer_pokemon(self, pokemon):
        if self.config_transfer and (not self.bot.config.test):
            response_dict = self.bot.api.release_pokemon(pokemon_id=pokemon.unique_id)
        else:
            response_dict = {"responses": {"RELEASE_POKEMON": {"candy_awarded": 0}}}

        if not response_dict:
            return False

        candy_awarded = response_dict.get("responses", {}).get("RELEASE_POKEMON", {}).get("candy_awarded", 0)
        candy = inventory.candies().get(pokemon.pokemon_id)

        if self.config_transfer and (not self.bot.config.test):
            candy.add(candy_awarded)

        self.emit_event("pokemon_release",
                        formatted="Exchanged {pokemon} [IV {iv}] [CP {cp}] [{candy} candies]",
                        data={"pokemon": pokemon.name,
                              "iv": pokemon.iv,
                              "cp": pokemon.cp,
                              "candy": candy.quantity})

        if self.config_transfer and (not self.bot.config.test):
            inventory.pokemons().remove(pokemon.unique_id)

            with self.bot.database as db:
                cursor = db.cursor()
                cursor.execute("SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='transfer_log'")

                db_result = cursor.fetchone()

                if db_result[0] == 1:
                    db.execute("INSERT INTO transfer_log (pokemon, iv, cp) VALUES (?, ?, ?)", (pokemon.name, pokemon.iv, pokemon.cp))

            action_delay(self.config_action_wait_min, self.config_action_wait_max)

        return True
Esempio n. 49
0
    def evolve_pokemon(self, pokemon):
        if self.config_evolve and (not self.bot.config.test):
            response_dict = self.bot.api.evolve_pokemon(pokemon_id=pokemon.id)
        else:
            response_dict = {"responses": {"EVOLVE_POKEMON": {"result": 1}}}

        if not response_dict:
            return False

        result = response_dict.get("responses", {}).get("EVOLVE_POKEMON", {}).get("result", 0)

        if result != SUCCESS:
            return False

        xp = response_dict.get("responses", {}).get("EVOLVE_POKEMON", {}).get("experience_awarded", 0)
        candy = response_dict.get("responses", {}).get("EVOLVE_POKEMON", {}).get("candy_awarded", 0)
        evolution = response_dict.get("responses", {}).get("EVOLVE_POKEMON", {}).get("evolved_pokemon_data", {})

        self.emit_event("pokemon_evolved",
                        formatted="Evolved {pokemon} [IV {iv}] [CP {cp}] [NCP {ncp}] [DPS {dps}] [+{xp} xp]",
                        data={"pokemon": pokemon.name,
                              "iv": pokemon.iv,
                              "cp": pokemon.cp,
                              "ncp": round(pokemon.ncp, 2),
                              "dps": round(pokemon.dps, 2),
                              "xp": xp})

        if self.config_evolve and (not self.bot.config.test):
            inventory.candies().get(pokemon.pokemon_id).consume(pokemon.evolution_cost - candy)
            inventory.pokemons().remove(pokemon.id)

            new_pokemon = inventory.Pokemon(evolution)
            inventory.pokemons().add(new_pokemon)

            sleep(self.config_evolve_time)

        return True
    def showtop(self, chatid, num, order):
        if not num.isnumeric():
            num = 10
        else:
            num = int(num)

        if order not in ["cp", "iv"]:
            order = "iv"

        pkmns = sorted(inventory.pokemons().all(), key=lambda p: getattr(p, order), reverse=True)[:num]

        outMsg = "\n".join(["<b>{}</b> \nCP: {} \nIV: {} \nCandy: {}\n".format(p.name, p.cp, p.iv, inventory.candies().get(p.pokemon_id).quantity) for p in pkmns])
        self.sendMessage(chat_id=chatid, parse_mode='HTML', text=outMsg)

        return
Esempio n. 51
0
    def _release_pokemon_get_groups(self):
        pokemon_groups = {}
        # TODO: Use new inventory everywhere and then remove the inventory update
        for pokemon in inventory.pokemons(True).all():
            if pokemon.in_fort or pokemon.is_favorite:
                continue

            group_id = pokemon.pokemon_id

            if group_id not in pokemon_groups:
                pokemon_groups[group_id] = []

            pokemon_groups[group_id].append(pokemon)

        return pokemon_groups
Esempio n. 52
0
    def get_nearby_pokemons(self):
        radius = self.config_max_distance

        pokemons = [p for p in self.bot.cell["nearby_pokemons"] if self.get_distance(self.bot.start_position, p) <= radius]

        for pokemon in pokemons:
            pokemon["distance"] = self.get_distance(self.bot.position, pokemon)
            pokemon["name"] = inventory.pokemons().name_for(pokemon["pokemon_id"])
            pokemon["candies"] = inventory.candies().get(pokemon["pokemon_id"]).quantity
            # Pokemon also has a fort_id of the PokeStop the Pokemon is hiding at.
            # We should set our first destination at that Pokestop.

        pokemons.sort(key=lambda p: p["distance"])

        return pokemons
    def _sort_and_filter(self):
        pokemons = []
        pokemon_count = Counter()

        for pokemon in inventory.pokemons().all():
            if self._should_evolve(pokemon):
                pokemons.append(pokemon)
                pokemon_count[pokemon.pokemon_id] += 1

        if self.first_evolve_by == "cp":
            pokemons.sort(key=lambda x: (x.pokemon_id, x.cp, x.iv), reverse=True)
        else:
            pokemons.sort(key=lambda x: (x.pokemon_id, x.iv, x.cp), reverse=True)

        return pokemons, pokemon_count