Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I get a list of Pokemon a user has? #233

Open
cgrantdev opened this issue Aug 11, 2016 · 1 comment
Open

How can I get a list of Pokemon a user has? #233

cgrantdev opened this issue Aug 11, 2016 · 1 comment

Comments

@cgrantdev
Copy link

Just got this installed and working, curious how I could go about pulling the data for the current pokemon a user has kinda like:

Charizard - 1200 CP - 156 HP - 2500 Candy - 3 Candies - Move 1 (Damage) - Move 2 (Damage)

Or any of that information, is this possible?

Thanks

@cgrantdev cgrantdev changed the title How can I get a list of Pokemon a user has? ( How can I get a list of Pokemon a user has? Aug 11, 2016
@LemonDew
Copy link

LemonDew commented Aug 11, 2016

You need to call "GetInventory", like so:

api.GetInventory(function (err, inventory) {
        if (!err) {
            var cleanedInventory = { player_stats: null, eggs : [], pokemon: [], items: [] };
            for (var i = 0; i < inventory.inventory_delta.inventory_items.length; i++) {
                var inventory_item_data = inventory.inventory_delta.inventory_items[i].inventory_item_data;

                // Check for pokemon.
                if (inventory_item_data.pokemon) {
                    var pokemon = inventory_item_data.pokemon;
                    if (pokemon.is_egg) {
                        console.log('  [E] ' + pokemon.egg_km_walked_target + ' Egg');
                        cleanedInventory.eggs.push(pokemon);
                    } else {
                        var pokedexInfo = api.pokemonlist[parseInt(pokemon.pokemon_id) - 1];
                        console.log('  [P] ' + pokedexInfo.name + ' - ' + pokemon.cp + ' CP');
                        cleanedInventory.pokemon.push(pokemon);
                    }
                }

                // Check for player stats.
                if (inventory_item_data.player_stats) {
                    var player = inventory_item_data.player_stats;
                    console.log('  [PL] Level ' + player.level + ' - ' + player.unique_pokedex_entries + ' Unique Pokemon');

                    cleanedInventory.player_stats = player;
                }

                // Check for item.
                if (inventory_item_data.item) {
                    var item = inventory_item_data.item;
                    console.log('  [I] ' + item.item_id + ' - ' + item.count);

                    cleanedInventory.items.push(item);
                }
            }

            callback(cleanedInventory);
        }
    });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants