diff --git a/packages/pokemon/src/dex/learnsets.ts b/packages/pokemon/src/dex/learnsets.ts index d64c5f2c8..0f355e225 100644 --- a/packages/pokemon/src/dex/learnsets.ts +++ b/packages/pokemon/src/dex/learnsets.ts @@ -51,11 +51,33 @@ export async function getDefaultMoveset(speciesId: SpeciesId, level: number): Pr } /** Get the default ability for a species (first non-hidden ability) */ +/** Get the first non-hidden ability for a species */ export function getDefaultAbility(speciesId: SpeciesId): string { const species = Dex.species.get(speciesId) return species?.abilities?.['0']?.toLowerCase() ?? '' } +/** Get all available abilities for a species (including hidden) */ +export function getAbilities(speciesId: SpeciesId): { normal: string[]; hidden: string | null } { + const species = Dex.species.get(speciesId) + if (!species?.exists) return { normal: [], hidden: null } + const normal: string[] = [] + if (species.abilities['0']) normal.push(species.abilities['0'].toLowerCase()) + if (species.abilities['1']) normal.push(species.abilities['1'].toLowerCase()) + const hidden = species.abilities['H']?.toLowerCase() ?? null + return { normal, hidden } +} + +/** Randomly select an ability for a species. Hidden ability has ~5% chance. */ +export function randomAbility(speciesId: SpeciesId): string { + const { normal, hidden } = getAbilities(speciesId) + if (normal.length === 0 && !hidden) return '' + // 5% chance for hidden ability + if (hidden && Math.random() < 0.05) return hidden + // Otherwise pick from normal abilities + return normal[Math.floor(Math.random() * normal.length)] ?? hidden ?? '' +} + /** Get newly learnable moves when leveling up */ export async function getNewLearnableMoves(speciesId: SpeciesId, oldLevel: number, newLevel: number): Promise<{ id: string; name: string }[]> { const learnset = getLearnsetData(speciesId)