Esempio n. 1
0
    def capture_stats(self):
        try:
            uniq_pokemon_list = set()

            if self.bot.tick_count > 0:
                self.dust['latest'] = self.bot.stardust 
                if self.dust['start'] < 0:
                    self.dust['start'] = self.dust['latest']

            inventory.refresh_inventory()
            json_inventory = inventory.jsonify_inventory()
            for item in json_inventory:
                if 'inventory_item_data' in item:
                    if 'player_stats' in item['inventory_item_data']:
                        playerdata = item['inventory_item_data']['player_stats']
                        self.player_stats = playerdata

                        self.xp['latest'] = playerdata.get('experience', 0)
                        if self.xp['start'] < 0: self.xp['start'] = self.xp['latest']

                        self.visits['latest'] = playerdata.get('poke_stop_visits', 0)
                        if self.visits['start'] < 0: self.visits['start'] = self.visits['latest']

                        self.captures['latest'] = playerdata.get('pokemons_captured', 0)
                        if self.captures['start'] < 0: self.captures['start'] = self.captures['latest']

                        self.distance['latest'] = playerdata.get('km_walked', 0)
                        if self.distance['start'] < 0: self.distance['start'] = self.distance['latest']

                        self.encounters['latest'] = playerdata.get('pokemons_encountered', 0)
                        if self.encounters['start'] < 0: self.encounters['start'] = self.encounters['latest']

                        self.throws['latest'] = playerdata.get('pokeballs_thrown', 0)
                        if self.throws['start'] < 0: self.throws['start'] = self.throws['latest']

                        self.unique_mons['latest'] = playerdata.get('unique_pokedex_entries', 0)
                        if self.unique_mons['start'] < 0: self.unique_mons['start'] = self.unique_mons['latest']

                        self.visits['latest'] = playerdata.get('poke_stop_visits', 0)
                        if self.visits['start'] < 0: self.visits['start'] = self.visits['latest']

                        self.evolutions['latest'] = playerdata.get('evolutions', 0)
                        if self.evolutions['start'] < 0: self.evolutions['start'] = self.evolutions['latest']
                    elif 'pokedex_entry' in item['inventory_item_data']:
                        entry = item['inventory_item_data']['pokedex_entry'].get('pokemon_id')
                        if entry: uniq_pokemon_list.add(entry)

            if not self.uniq_pokemons_list:  # make set from pokedex entries on first run
                self.uniq_pokemons_list = uniq_pokemon_list
            else:
                # generate new entries for current bot session
                self.uniq_pokemons_caught = uniq_pokemon_list - self.uniq_pokemons_list

        except KeyError:
            # Nothing we can do if there's no player info.
            return
Esempio n. 2
0
    def _check_inventory(self, lookup_ids=[]):
        if lookup_ids:
            inventory.refresh_inventory()
        matched_pokemon = []
        temp_eggs = []
        temp_used_incubators = []
        temp_ready_breakable_incubators = []
        temp_ready_infinite_incubators = []
        inv = inventory.jsonify_inventory()
        for inv_data in inv:
            inv_data = inv_data.get("inventory_item_data", {})
            if "egg_incubators" in inv_data:
                incubators = inv_data.get("egg_incubators", {}).get("egg_incubator",[])
                if isinstance(incubators, basestring):  # checking for old response
                    incubators = [incubators]
                for incubator in incubators:
                    if 'pokemon_id' in incubator:
                        start_km = incubator.get('start_km_walked', 0)
                        km_walked = incubator.get('target_km_walked', 0)
                        temp_used_incubators.append({
                            "id": incubator.get('id', -1),
                            "km": km_walked,
                            "km_needed": (km_walked - start_km)
                        })
                    else:
                        if incubator.get('uses_remaining') is not None:
                            temp_ready_breakable_incubators.append({
                                "id": incubator.get('id', -1)
                            })
                        else:
                            temp_ready_infinite_incubators.append({
                                "id": incubator.get('id', -1)
                            })
                continue
            if "pokemon_data" in inv_data:
                pokemon = inv_data.get("pokemon_data", {})
                if pokemon.get("is_egg", False) and "egg_incubator_id" not in pokemon:
                    temp_eggs.append({
                        "id": pokemon.get("id", -1),
                        "km": pokemon.get("egg_km_walked_target", -1),
                        "used": False
                    })
                elif 'is_egg' not in pokemon and pokemon['id'] in lookup_ids:
                    matched_pokemon.append(pokemon)
                continue
            if "player_stats" in inv_data:
                self.km_walked = inv_data.get("player_stats", {}).get("km_walked", 0)

        self.used_incubators = temp_used_incubators
        if self.used_incubators:
            self.used_incubators.sort(key=lambda x: x.get("km"))
        self.ready_breakable_incubators = temp_ready_breakable_incubators
        self.ready_infinite_incubators = temp_ready_infinite_incubators
        self.eggs = temp_eggs
        return matched_pokemon
 def get_player_info(self):
     try:
         self.sio.emit(
             'bot:send_reply',
             {
                 'result': {'inventory': inventory.jsonify_inventory(), 'player': self.bot._player},
                 'command': 'get_player_info',
                 'account': self.bot.config.username
             }
         )
     except Exception as e:
         self.logger.error(e)
Esempio n. 4
0
 def get_player_info(self):
     try:
         self.sio.emit(
             'bot:send_reply', {
                 'result': {
                     'inventory': inventory.jsonify_inventory(),
                     'player': self.bot._player
                 },
                 'command': 'get_player_info',
                 'account': self.bot.config.username
             })
     except Exception as e:
         self.logger.error(e)
 def _get_player_stats(self):
     json_inventory = inventory.jsonify_inventory()
     return next((x["inventory_item_data"]["player_stats"]
                  for x in json_inventory
                  if x.get("inventory_item_data", {}).get("player_stats", {})),
                 None)
Esempio n. 6
0
 def _get_player_stats(self):
     json_inventory = inventory.jsonify_inventory()
     return next(
         (x["inventory_item_data"]["player_stats"] for x in json_inventory
          if x.get("inventory_item_data", {}).get("player_stats", {})),
         None)
Esempio n. 7
0
    def capture_stats(self):
        try:
            uniq_pokemon_list = set()

            if self.bot.tick_count > 0:
                self.dust['latest'] = self.bot.stardust
                if self.dust['start'] < 0:
                    self.dust['start'] = self.dust['latest']

            inventory.refresh_inventory()
            json_inventory = inventory.jsonify_inventory()
            for item in json_inventory:
                if 'inventory_item_data' in item:
                    if 'player_stats' in item['inventory_item_data']:
                        playerdata = item['inventory_item_data'][
                            'player_stats']
                        self.player_stats = playerdata

                        self.xp['latest'] = playerdata.get('experience', 0)
                        if self.xp['start'] < 0:
                            self.xp['start'] = self.xp['latest']

                        self.visits['latest'] = playerdata.get(
                            'poke_stop_visits', 0)
                        if self.visits['start'] < 0:
                            self.visits['start'] = self.visits['latest']

                        self.captures['latest'] = playerdata.get(
                            'pokemons_captured', 0)
                        if self.captures['start'] < 0:
                            self.captures['start'] = self.captures['latest']

                        self.distance['latest'] = playerdata.get(
                            'km_walked', 0)
                        if self.distance['start'] < 0:
                            self.distance['start'] = self.distance['latest']

                        self.encounters['latest'] = playerdata.get(
                            'pokemons_encountered', 0)
                        if self.encounters['start'] < 0:
                            self.encounters['start'] = self.encounters[
                                'latest']

                        self.throws['latest'] = playerdata.get(
                            'pokeballs_thrown', 0)
                        if self.throws['start'] < 0:
                            self.throws['start'] = self.throws['latest']

                        self.unique_mons['latest'] = playerdata.get(
                            'unique_pokedex_entries', 0)
                        if self.unique_mons['start'] < 0:
                            self.unique_mons['start'] = self.unique_mons[
                                'latest']

                        self.visits['latest'] = playerdata.get(
                            'poke_stop_visits', 0)
                        if self.visits['start'] < 0:
                            self.visits['start'] = self.visits['latest']

                        self.evolutions['latest'] = playerdata.get(
                            'evolutions', 0)
                        if self.evolutions['start'] < 0:
                            self.evolutions['start'] = self.evolutions[
                                'latest']
                    elif 'pokedex_entry' in item['inventory_item_data']:
                        entry = item['inventory_item_data'][
                            'pokedex_entry'].get('pokemon_id')
                        if entry: uniq_pokemon_list.add(entry)

            if not self.uniq_pokemons_list:  # make set from pokedex entries on first run
                self.uniq_pokemons_list = uniq_pokemon_list
            else:
                # generate new entries for current bot session
                self.uniq_pokemons_caught = uniq_pokemon_list - self.uniq_pokemons_list

        except KeyError:
            # Nothing we can do if there's no player info.
            return