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

Is there a way to get Pokemon by cp? #19

Closed
DragonStar01 opened this issue Jul 29, 2016 · 4 comments
Closed

Is there a way to get Pokemon by cp? #19

DragonStar01 opened this issue Jul 29, 2016 · 4 comments

Comments

@DragonStar01
Copy link

DragonStar01 commented Jul 29, 2016

$pokeBank = $inventory->getItems()->getPokeBank();
   // print_r($pokeBank);

    $pokemon = $pokeBank->getPokemonsByType(PokemonId::RATTATA);
    print_r($pokemon);

Prints that i have 2 Rattata
So i just want to print the Rattatas Cp
and transfer the lowest one.
How can i do?
Thank you for everything :)
I was having many errors in this script but when i updated my php version to php7 all the errors gone away
sorry for my bad English

@DragonStar01 DragonStar01 changed the title Is there anyway to get Pokemon by cp? Is there a way to get Pokemon by cp? Jul 29, 2016
@NicklasWallgren
Copy link
Owner

NicklasWallgren commented Jul 29, 2016

This should do it.

// Retrieve pokemons of type rattata
$pokemons = $pokeBank->getPokemonsByType(PokemonId::RATTATA);

printf('Found %s number of rattats' . PHP_EOL, count($pokemons));

// Sort the pokemons by combat points
  uasort($pokemons, function (\NicklasW\PkmGoApi\Api\Pokemon\Pokemon $pokemon1, \NicklasW\PkmGoApi\Api\Pokemon\Pokemon $pokemon2) {
            return $pokemon1->getPokemonData()->getCp() <=> $pokemon2->getPokemonData()->getCp();
        });

// Retrieve the lowest pokemon
$lowestPokemon = current($pokemons);

printf('Transfer rattata with cp of %s' . PHP_EOL, $lowestPokemon->getPokemonData()->getCp());

// Transfer the pokemon
$lowestPokemon->transfer();


@DragonStar01
Copy link
Author

Thank you very much :) BTW How can i change the response to json?

@NicklasWallgren
Copy link
Owner

What response? The list of pokemon?

@DragonStar01
Copy link
Author

Sorry my bad

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