def _evolve(self, trigger: str) -> NoReturn: """Evolve the Pokémon via ``trigger``. :param trigger: the event that triggers the evolution. Valid triggers are: level-up, trade, use-item, and shed. :return: Nothing. """ pokemon = _database.get_pokemon(species=self._species) for child_species in pokemon.species.child_species: if self._check_evolution_condition( trigger=trigger, evolution=child_species.evolutions[0]): evolved_species = child_species.identifier break else: return evolved_pokemon = _database.get_pokemon(species=evolved_species) self._ability = _database.get_ability( species=evolved_pokemon.species.identifier, personality=self._personality, ) self._form = evolved_pokemon.default_form # TODO: use the correct form self._height = evolved_pokemon.height self._national_id = evolved_pokemon.species.id self._species = evolved_pokemon.species.identifier self._species_strengths = Stats.make_species_strengths( species=evolved_pokemon.species.identifier) self._stats = self._calculate_stats() self._weight = evolved_pokemon.weight
def test_get_specific_pokemon_form(): """ A Pokémon's species and a form name is sufficient to get the exact Pokémon form for those who have multiple forms. """ castform_rainy = _database.get_pokemon(species='castform', form='rainy') assert 'castform-rainy' == castform_rainy.identifier
def test_get_default_pokemon_form(): """ The default form of a Pokémon is returned if the Pokémon has multiple forms. """ deoxys_normal = _database.get_pokemon(national_id=386) assert 'deoxys-normal' == deoxys_normal.identifier
def test_get_pokemon_by_species(): """ A Pokémon's species (kind) alone is enough to determine the exact Pokémon we want to get. """ bulbasaur = _database.get_pokemon(species='bulbasaur') assert 'bulbasaur' == bulbasaur.identifier
def test_get_pokemon_by_national_id(): """ A Pokémon's National Pokédex ID alone is enough to determine the exact Pokémon we want to get. """ bulbasaur = _database.get_pokemon(national_id=1) assert 'bulbasaur' == bulbasaur.identifier
def make_ev_yield(cls, species: str) -> 'Stats': """Create an EV instance from PokemonStats table. :param species: The identifier of a Pokémon species. :return: A ``Stats`` instance. """ pokemon = _database.get_pokemon(species=species) stats = pokemon.stats yields = {stat: stats[i].effort for i, stat in enumerate(cls._NAMES)} return cls(**yields)
def make_species_strengths(cls, species: str) -> 'Stats': """Create a Pokémon's species strengths stats. :param species: The identifier of a Pokémon species. :return: A ``Stats`` instance. """ pokemon = _database.get_pokemon(species=species) strengths = {} for i, stat in enumerate(cls._NAMES): strengths[stat] = pokemon.stats[i].base_stat return cls(**strengths)
def __init__( self, species: str = None, national_id: int = None, form: str = None, level: int = None, exp: int = None, gender: str = None, ability: str = None, nature: str = None, iv: Stats = None, ): """Instantiate a Pokémon. :param str species: The species of the Pokémon, in lowercase ASCII. :param int national_id: The Pokémon's index number in the National Pokédex. At least one of ``species`` and ``national_id`` must be specified to instantiate a Pokémon. If both are present, then they need to be consistent with each other. :param str form: The variant of the Pokémon, in lowercase ASCII. :param int level: The current level of the Pokémon. Must be an ``int`` between 1 and 100. Needs to be consistent with ``exp``, if specified. :param int exp: The current get_experience of the Pokémon. If the level is also specified, the level and the exp. points need to be consistent. At least one of ``level`` and ``exp`` must be specified to instantiate a Pokémon. Leaving this to None while having ``level`` set will automatically set the exp. points to the minimum amount required to be at the specified level. :param str gender: The Pokémon's gender. It needs to be consistent with the Pokémon's gender rate. If the gender is not set, a random gender will be assigned based on the Pokémon's gender rate and the personality ID. :param str ability: The Pokémon's ability. The ability needs to be consistent with the Pokémon's species. If this is not specified, a random ability will be determined from the personality ID. :param str nature: The Pokémon's nature. If this is not specified, a random nature will be determined from the personality ID. :param MutableMapping[str, int] iv: A dictionary of the Pokémon's individual values. The keys are the names of the statistics (hp, attack, defense, special-attack, special-defense, speed). Each individual value must not exceed 32. If it is not specified, a random set of IV's will be generated using the PRNG. """ _pokemon = _database.get_pokemon(national_id=national_id, species=species, form=form) _growth = _database.get_experience(national_id=national_id, species=species, level=level, exp=exp) _species = _pokemon.species self._national_id = _species.id self._species = _species.identifier self._form = form self._height = _pokemon.height / 10 # In meters self._weight = _pokemon.weight / 10 # In meters self._types = list(map(lambda x: x.identifier, _pokemon.types)) self._level = _growth.level self._exp = _growth.experience if exp is None else exp self._happiness = 0 if iv is None: _gene = self._prng.create_gene() self._iv = Stats.make_iv(_gene) elif isinstance(iv, Stats) and iv.validate_iv(): self._iv = iv else: raise TypeError(f"`iv` must be of type `pokemaster.Stats`.") self._personality = self._prng.create_personality() self._nature = (nature or _database.get_nature(self._personality).identifier) self._ability = (ability or _database.get_ability( species=self._species, personality=self._personality).identifier) self._gender = gender or _database.get_pokemon_gender( species=self.species, personality=self._personality) self._species_strengths = Stats.make_species_strengths(self._species) self._nature_modifiers = Stats.make_nature_modifiers(self._nature) self._ev = Stats() self._stats = self._calculate_stats() self._current_hp = self._stats.hp self._conditions = Conditions() _moves = _database.get_pokemon_default_moves(species=self._species, level=self._level) self._moves = deque(map(lambda x: x.identifier, _moves), maxlen=4) self._pp = list(map(lambda x: x.pp, _moves)) self._held_item = None self._battle_stats = BattleStats.from_stats(self._stats)