Closed baskettcase closed 7 years ago
The getType2String
method has been added as of 2.0.4. Check the RetrievePokemonTraitExample
example, it outputs the type1, move1 and move2 attributes correctly.
Example on how to get hold on the type 1 and type 2 attributes via PokemonMetaRegistry
$pokemonmeta = PokemonMetaRegistry::getByPokemonId($id);
NicklasW\PkmGoApi\Api\Support\Enums\PokemonType::name($pokemonmeta->getType1())
NicklasW\PkmGoApi\Api\Support\Enums\PokemonType::name($pokemonmeta->getType2())
Ok Ill try those out. Happy New Year btw! :)
And that's quite a bit more code compared to just the $pokemon->getType1String() previously. I took a look at the examples and it looks the same as it has and doesn't have anything to do with meta.. it just updated to 2.0.5 also, so Im not sure why I wouldn't have the new example file.
Also there seems to be a problem with the $pokemon->getName() it used to retrieve the nickname and if that wasn't set then the name.. now if there is no nickname it just returns blank.
@baskettcase I can't reproduce the problem, if I run the RetrievePokemonTraitExample.php
the name is returned properly.
Pokemon MAGIKARP, Id: 1877587 Cp: 10, type: POKEMON_TYPE_WATER, attacks: SPLASH_FAST and STRUGGLE
Hmm.. I don't have your new version of the trait script. It says the last time it was updated was 5 months ago. Maybe that's my problem?
I don't think so, the RetrievePokemonTraitExample.php
example hasn't been updated in a while.
What does the RetrievePokemonTraitExample.php
example output when you run it?
Ok I was referring to your new class pokemonmeta and you referenced that file, which doesn't have those lines you mentioned in it.
$pokemonmeta = PokemonMetaRegistry::getByPokemonId($id);
Here Ill see what I have and post it. I have to edit it since there are some sensitive items in the file :) plus sorry, there are some testing items in place.
`require_once 'vendor/autoload.php';
use NicklasW\PkmGoApi\Authentication\AccessToken; use NicklasW\PkmGoApi\Authentication\Config\Config; use NicklasW\PkmGoApi\Authentication\Factory\Factory; use NicklasW\PkmGoApi\Authentication\Manager; use NicklasW\PkmGoApi\Kernels\ApplicationKernel; use NicklasW\PkmGoApi\Api\Support\PokemonId;
class RetrievePokemonTraitExample { public function run() { // Create the authentication config $config = new Config(); $config->setProvider(Factory::PROVIDER_GOOGLE); $config->setUser('email@email'); $config->setPassword('password');
// Create the authentication manager
$manager = Factory::create($config);
// Add a event listener,
$manager->addListener(function ($event, $value) {
if ($event === Manager::EVENT_ACCESS_TOKEN) {
/** @var AccessToken $accessToken */
$accessToken = $value;
// Persist the access token in session storage, cache or whatever.
}
});
// Initialize the pokemon go application
$application = new ApplicationKernel($manager);
// Retrieve the pokemon go api instance
$pokemonGoApi = $application->getPokemonGoApi();
// Retrieve the inventory
$inventory = $pokemonGoApi->getInventory();
// Retrieve the poke bank
$pokeBank = $inventory->getPokeBank();
// get all pokemons
$pokemons = $pokeBank->getPokemons()->sortByIVRatio(true);
#$pokemons = $pokeBank->getPokemons()->sortByName(true);
// Retrieve a pokemon by type
#$pokemons = $pokeBank->getPokemonsByType(PokemonId::MAGIKARP)->sortByIVRatio(true);
// Check if we retrieved a pokemon
if (!$pokemons) {
throw new Exception('Cannot find any pokemons in your PokeBank.');
}
#die('<pre>'.print_r($pokemons,1).'</pre>');
// /games/pokemongo/vendor/nicklasw/pkm-go-api/src/Api/Pokemon/Pokemon.php
$pokemon_array = array();
foreach ($pokemons as $pokemon) {
#echo sprintf("%s, Cp: %d, type: %s, attacks: %s and %s, IV: Attack: %s, Defense: %s, Stamina: %s = Ratio: %s<br />", $pokemon->getName(), $pokemon->getCp(), $pokemon->getType1String(), $pokemon->getMove1String(), $pokemon->getMove2String(), $pokemon->getIndividualAttack(), $pokemon->getIndividualDefense(), $pokemon->getIndividualStamina(), $pokemon->getIvRatio());
#echo sprintf("%s, Cp: %d, IV: Attack: %s, Defense: %s, Stamina: %s = Ratio: %s<br />", $pokemon->getName(), $pokemon->getCp(), $pokemon->getIndividualAttack(), $pokemon->getIndividualDefense(), $pokemon->getIndividualStamina(), $pokemon->getIvRatio());
$pokemonmeta = PokemonMetaRegistry::getByPokemonId($pokemon->getId());
$poke_info = array(
'name' => ucwords(strtolower($pokemon->getName())),
'cp' => $pokemon->getCp(),
'hp' => $pokemon->getStaminaMax(),
'type1' => ucwords(strtolower(str_replace('POKEMON_TYPE_', '', PokemonType::name($pokemonmeta->getType1())))),
'type2' => ucwords(strtolower(str_replace('POKEMON_TYPE_', '', PokemonType::name($pokemonmeta->getType2())))),
#'move1' => ucwords(strtolower(str_replace(array('_',' FAST'), array(' ',''), $pokemon->getMove1()))),
'move1' => $pokemon->getMove1String(),
#'move2' => ucwords(strtolower(str_replace('_', ' ', $pokemon->getMove2()))),
'move2' => $pokemon->getMove2String(),
'attack' => $pokemon->getIndividualAttack(),
'defense' => $pokemon->getIndividualDefense(),
'stamina' => $pokemon->getIndividualStamina(),
'ratio' => number_format($pokemon->getIvRatio(),2),
);
$pokemon_array[] = $poke_info;
}
return $pokemon_array;
}
}`
What isn't working in your example?
You can either access the pokemon details directly from the pokemon instance or via the PokemonMetaRegistry. In this case it's probably a better idea to retrieve the information directly from the pokemon instance.
Ok.. I basically reverted everything after looking at what you posted and now it works.. Im baffled, but.. I've been overtired.. so who knows. Thank you and sorry for wasting your time. I do appreciate the help!
Haha, no problem :)
Ok I think there are more problems with the API (also is there a way to tag this as a question, or do you need to do that?)
When I try
$pokemon->getType2String()
I am not getting anything even though Weedle's for example are type bug and poison.. so getType1String() seems to work, but not getType2String().Also movesets are still not working.
$pokemon->getMove1String()
is returning absolutely nothing, while getMove1() gets the move ID, but not the move name.Am I doing something wrong @NicklasWallgren ?