From 09e719204677134ab2880e642271fa13825a4a17 Mon Sep 17 00:00:00 2001 From: Tempoanon <163687446+Tempo-anon@users.noreply.github.com> Date: Sun, 28 Jul 2024 00:22:51 -0400 Subject: [PATCH] [Bug] Tinted Pokeball for Pokemon with only 1 ability (#3174) * Add hasSameAbilityInRootForm function to Pokemon class * Add HA check * Try not using a dependency --- src/field/pokemon.ts | 11 +++++++++++ src/ui/battle-info.ts | 23 +++++++++++++---------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 78433ece72b..f630cc16a48 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -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 { diff --git a/src/ui/battle-info.ts b/src/ui/battle-info.ts index 2ac350e2b14..d78b05a569f 100644 --- a/src/ui/battle-info.ts +++ b/src/ui/battle-info.ts @@ -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); }