[Bug] Tinted Pokeball for Pokemon with only 1 ability (#3174)

* Add hasSameAbilityInRootForm function to Pokemon class

* Add HA check

* Try not using a dependency
This commit is contained in:
Tempoanon 2024-07-28 00:22:51 -04:00 committed by GitHub
parent 4d87254001
commit 09e7192046
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 10 deletions

View File

@ -3097,6 +3097,17 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
getBattleInfo(): BattleInfo {
return this.battleInfo;
}
/**
* Checks whether or not the Pokemon's root form has the same ability
* @param abilityIndex the given ability index we are checking
* @returns true if the abilities are the same
*/
hasSameAbilityInRootForm(abilityIndex: number): boolean {
const currentAbilityIndex = this.abilityIndex;
const rootForm = getPokemonSpecies(this.species.getRootSpeciesId());
return rootForm.getAbility(abilityIndex) === rootForm.getAbility(currentAbilityIndex);
}
}
export default interface Pokemon {

View File

@ -346,18 +346,21 @@ export default class BattleInfo extends Phaser.GameObjects.Container {
// Check if Player owns all genders and forms of the Pokemon
const missingDexAttrs = ((dexEntry.caughtAttr & opponentPokemonDexAttr) < opponentPokemonDexAttr);
/**
* If the opposing Pokemon only has 1 normal ability and is using the hidden ability it should have the same behavior
* if it had 2 normal abilities. This code checks if that is the case and uses the correct opponent Pokemon abilityIndex (2)
* for calculations so it aligns with where the hidden ability is stored in the starter data's abilityAttr (4)
*/
const opponentPokemonOneNormalAbility = (pokemon.species.getAbilityCount() === 2);
const opponentPokemonAbilityIndex = (opponentPokemonOneNormalAbility && pokemon.abilityIndex === 1) ? 2 : pokemon.abilityIndex;
const opponentPokemonAbilityAttr = Math.pow(2, opponentPokemonAbilityIndex);
const ownedAbilityAttrs = pokemon.scene.gameData.starterData[pokemon.species.getRootSpeciesId()].abilityAttr;
const rootFormHasHiddenAbility = pokemon.scene.gameData.starterData[pokemon.species.getRootSpeciesId()].abilityAttr & opponentPokemonAbilityAttr;
let playerOwnsThisAbility = false;
// Check if the player owns ability for the root form
if ((ownedAbilityAttrs & 1) > 0 && pokemon.hasSameAbilityInRootForm(0)) {
playerOwnsThisAbility = true;
}
if ((ownedAbilityAttrs & 2) > 0 && pokemon.hasSameAbilityInRootForm(1)) {
playerOwnsThisAbility = true;
}
if ((ownedAbilityAttrs & 4) > 0 && pokemon.hasSameAbilityInRootForm(2)) {
playerOwnsThisAbility = true;
}
if (missingDexAttrs || !rootFormHasHiddenAbility) {
if (missingDexAttrs || !playerOwnsThisAbility) {
this.ownedIcon.setTint(0x808080);
}