Skip to content

Commit

Permalink
[Bug] Tinted Pokeball for Pokemon with only 1 ability (#3174)
Browse files Browse the repository at this point in the history
* Add hasSameAbilityInRootForm function to Pokemon class

* Add HA check

* Try not using a dependency
  • Loading branch information
Tempo-anon authored Jul 28, 2024
1 parent 4d87254 commit 09e7192
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
11 changes: 11 additions & 0 deletions src/field/pokemon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
27 changes: 15 additions & 12 deletions src/ui/battle-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 rootFormHasHiddenAbility = pokemon.scene.gameData.starterData[pokemon.species.getRootSpeciesId()].abilityAttr & opponentPokemonAbilityAttr;

if (missingDexAttrs || !rootFormHasHiddenAbility) {
const ownedAbilityAttrs = pokemon.scene.gameData.starterData[pokemon.species.getRootSpeciesId()].abilityAttr;

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 || !playerOwnsThisAbility) {
this.ownedIcon.setTint(0x808080);
}

Expand Down

0 comments on commit 09e7192

Please sign in to comment.