From 4f541a8dcebb642d67d0e40c9bd8efd52dd429f6 Mon Sep 17 00:00:00 2001 From: Lylian BALL <131535108+PyGaVS@users.noreply.github.com> Date: Tue, 6 May 2025 03:31:11 +0200 Subject: [PATCH] [Bug] Fix some moves using illusion type instead of real type (#5772) * fix revelation dance using the type of the illusion instead of the actual type * fix other move that might get the illusion type as well * fix other move that might get the illusion type as well * fix abilities that might get the illusion type as well * fix illusion icon in party ui handler * Fix TSDoc for `Pokemon#getTypes` * Remove now-unnecessary changes to `.getTypes()` calls Revert `overrides.ts` changes * Replace `|| false` with `!!` --------- Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> --- src/battle-scene.ts | 17 ++++--- src/data/abilities/ability.ts | 3 +- src/field/pokemon.ts | 92 +++++++++++++++++++++-------------- src/modifier/modifier.ts | 2 +- src/ui/battle-info.ts | 4 +- 5 files changed, 69 insertions(+), 49 deletions(-) diff --git a/src/battle-scene.ts b/src/battle-scene.ts index db036847994..39bd1dd64cf 100644 --- a/src/battle-scene.ts +++ b/src/battle-scene.ts @@ -1046,31 +1046,32 @@ export default class BattleScene extends SceneBase { originX = 0.5, originY = 0.5, ignoreOverride = false, + useIllusion = false, ): Phaser.GameObjects.Container { const container = this.add.container(x, y); container.setName(`${pokemon.name}-icon`); - const icon = this.add.sprite(0, 0, pokemon.getIconAtlasKey(ignoreOverride)); + const icon = this.add.sprite(0, 0, pokemon.getIconAtlasKey(ignoreOverride, useIllusion)); icon.setName(`sprite-${pokemon.name}-icon`); - icon.setFrame(pokemon.getIconId(true)); + icon.setFrame(pokemon.getIconId(true, useIllusion)); // Temporary fix to show pokemon's default icon if variant icon doesn't exist - if (icon.frame.name !== pokemon.getIconId(true)) { + if (icon.frame.name !== pokemon.getIconId(true, useIllusion)) { console.log(`${pokemon.name}'s variant icon does not exist. Replacing with default.`); const temp = pokemon.shiny; pokemon.shiny = false; - icon.setTexture(pokemon.getIconAtlasKey(ignoreOverride)); - icon.setFrame(pokemon.getIconId(true)); + icon.setTexture(pokemon.getIconAtlasKey(ignoreOverride, useIllusion)); + icon.setFrame(pokemon.getIconId(true, useIllusion)); pokemon.shiny = temp; } icon.setOrigin(0.5, 0); container.add(icon); - if (pokemon.isFusion(true)) { - const fusionIcon = this.add.sprite(0, 0, pokemon.getFusionIconAtlasKey(ignoreOverride)); + if (pokemon.isFusion(useIllusion)) { + const fusionIcon = this.add.sprite(0, 0, pokemon.getFusionIconAtlasKey(ignoreOverride, useIllusion)); fusionIcon.setName("sprite-fusion-icon"); fusionIcon.setOrigin(0.5, 0); - fusionIcon.setFrame(pokemon.getFusionIconId(true)); + fusionIcon.setFrame(pokemon.getFusionIconId(true, useIllusion)); const originalWidth = icon.width; const originalHeight = icon.height; diff --git a/src/data/abilities/ability.ts b/src/data/abilities/ability.ts index 705de6f242d..4609ff6ec1a 100644 --- a/src/data/abilities/ability.ts +++ b/src/data/abilities/ability.ts @@ -43,10 +43,9 @@ import { PokemonTransformPhase } from "#app/phases/pokemon-transform-phase"; import { allAbilities } from "#app/data/data-lists"; import { AbAttr } from "#app/data/abilities/ab-attrs/ab-attr"; import { Ability } from "#app/data/abilities/ability-class"; -import { TrainerVariant } from "#app/field/trainer"; // Enum imports -import { Stat, type BattleStat , BATTLE_STATS, EFFECTIVE_STATS, getStatKey, type EffectiveStat } from "#enums/stat"; +import { Stat, type BattleStat, BATTLE_STATS, EFFECTIVE_STATS, getStatKey, type EffectiveStat } from "#enums/stat"; import { PokemonType } from "#enums/pokemon-type"; import { PokemonAnimType } from "#enums/pokemon-anim-type"; import { StatusEffect } from "#enums/status-effect"; diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 5615f3844bd..13eb2990a17 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -1115,40 +1115,45 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { ); } - getIconAtlasKey(ignoreOverride?: boolean): string { - const formIndex = this.summonData.illusion?.formIndex ?? this.formIndex; - return this.getSpeciesForm(ignoreOverride, true).getIconAtlasKey( + getIconAtlasKey(ignoreOverride?: boolean, useIllusion: boolean = true): string { + const formIndex = useIllusion && this.summonData.illusion?.formIndex ? this.summonData.illusion?.formIndex : this.formIndex; + const variant = !useIllusion && !!this.summonData.illusion ? this.summonData.illusion?.basePokemon.variant : this.variant; + return this.getSpeciesForm(ignoreOverride, useIllusion).getIconAtlasKey( formIndex, - this.shiny, - this.variant + this.isBaseShiny(useIllusion), + variant ); } - getFusionIconAtlasKey(ignoreOverride?: boolean): string { - return this.getFusionSpeciesForm(ignoreOverride, true).getIconAtlasKey( - this.fusionFormIndex, - this.fusionShiny, - this.fusionVariant - ); - } - - getIconId(ignoreOverride?: boolean): string { - const formIndex = this.summonData.illusion?.formIndex ?? this.formIndex; - return this.getSpeciesForm(ignoreOverride, true).getIconId( - this.getGender(ignoreOverride, true) === Gender.FEMALE, - formIndex, - this.shiny, - this.variant - ); - } - - getFusionIconId(ignoreOverride?: boolean): string { - const fusionFormIndex = this.summonData.illusion?.fusionFormIndex ?? this.fusionFormIndex; - return this.getFusionSpeciesForm(ignoreOverride, true).getIconId( - this.getFusionGender(ignoreOverride, true) === Gender.FEMALE, + getFusionIconAtlasKey(ignoreOverride?: boolean, useIllusion: boolean = true): string { + const fusionFormIndex = useIllusion && this.summonData.illusion?.fusionFormIndex ? this.summonData.illusion?.fusionFormIndex : this.fusionFormIndex; + const fusionVariant = !useIllusion && !!this.summonData.illusion ? this.summonData.illusion?.basePokemon.fusionVariant : this.fusionVariant; + return this.getFusionSpeciesForm(ignoreOverride, useIllusion).getIconAtlasKey( fusionFormIndex, - this.fusionShiny, - this.fusionVariant + this.isFusionShiny(), + fusionVariant + ); + } + + getIconId(ignoreOverride?: boolean, useIllusion: boolean = true): string { + const formIndex = useIllusion && this.summonData.illusion?.formIndex ? this.summonData.illusion?.formIndex : this.formIndex; + const variant = !useIllusion && !!this.summonData.illusion ? this.summonData.illusion?.basePokemon.variant : this.variant; + return this.getSpeciesForm(ignoreOverride, useIllusion).getIconId( + this.getGender(ignoreOverride, useIllusion) === Gender.FEMALE, + formIndex, + this.isBaseShiny(), + variant + ); + } + + getFusionIconId(ignoreOverride?: boolean, useIllusion: boolean = true): string { + const fusionFormIndex = useIllusion && this.summonData.illusion?.fusionFormIndex ? this.summonData.illusion?.fusionFormIndex : this.fusionFormIndex; + const fusionVariant = !useIllusion && !!this.summonData.illusion ? this.summonData.illusion?.basePokemon.fusionVariant : this.fusionVariant; + return this.getFusionSpeciesForm(ignoreOverride, useIllusion).getIconId( + this.getFusionGender(ignoreOverride, useIllusion) === Gender.FEMALE, + fusionFormIndex, + this.isFusionShiny(), + fusionVariant ); } @@ -1885,6 +1890,22 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } } + isBaseShiny(useIllusion: boolean = false){ + if (!useIllusion && this.summonData.illusion) { + return !!this.summonData.illusion.basePokemon?.shiny; + } else { + return this.shiny; + } + } + + isFusionShiny(useIllusion: boolean = false){ + if (!useIllusion && this.summonData.illusion) { + return !!this.summonData.illusion.basePokemon?.fusionShiny; + } else { + return this.isFusion(useIllusion) && this.fusionShiny; + } + } + /** * * @param useIllusion - Whether we want the fake or real shininess (illusion ability). @@ -2053,14 +2074,14 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { * @param includeTeraType - `true` to include tera-formed type; Default: `false` * @param forDefend - `true` if the pokemon is defending from an attack; Default: `false` * @param ignoreOverride - If `true`, ignore ability changing effects; Default: `false` - * @param useIllusion - `true` to return the types of the illusion instead of the actual types; "AUTO" will depend on forDefend param; Default: "AUTO" + * @param useIllusion - `true` to return the types of the illusion instead of the actual types; Default: `false` * @returns array of {@linkcode PokemonType} */ public getTypes( includeTeraType = false, forDefend: boolean = false, - ignoreOverride?: boolean, - useIllusion: boolean | "AUTO" = "AUTO" + ignoreOverride: boolean = false, + useIllusion: boolean = false ): PokemonType[] { const types: PokemonType[] = []; @@ -2076,17 +2097,16 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } if (!types.length || !includeTeraType) { - const doIllusion: boolean = (useIllusion === "AUTO") ? !forDefend : useIllusion; if ( !ignoreOverride && this.summonData.types && this.summonData.types.length > 0 && - (!this.summonData.illusion || !doIllusion) + (!this.summonData.illusion || !useIllusion) ) { this.summonData.types.forEach(t => types.push(t)); } else { - const speciesForm = this.getSpeciesForm(ignoreOverride, doIllusion); - const fusionSpeciesForm = this.getFusionSpeciesForm(ignoreOverride, doIllusion); + const speciesForm = this.getSpeciesForm(ignoreOverride, useIllusion); + const fusionSpeciesForm = this.getFusionSpeciesForm(ignoreOverride, useIllusion); const customTypes = this.customPokemonData.types?.length > 0; // First type, checking for "permanently changed" types from ME diff --git a/src/modifier/modifier.ts b/src/modifier/modifier.ts index 9df7aa7813f..763b40c8555 100644 --- a/src/modifier/modifier.ts +++ b/src/modifier/modifier.ts @@ -710,7 +710,7 @@ export abstract class PokemonHeldItemModifier extends PersistentModifier { if (!forSummary) { const pokemon = this.getPokemon(); if (pokemon) { - const pokemonIcon = globalScene.addPokemonIcon(pokemon, -2, 10, 0, 0.5); + const pokemonIcon = globalScene.addPokemonIcon(pokemon, -2, 10, 0, 0.5, undefined, true); container.add(pokemonIcon); container.setName(pokemon.id.toString()); } diff --git a/src/ui/battle-info.ts b/src/ui/battle-info.ts index 839f0d62819..2822e8364ec 100644 --- a/src/ui/battle-info.ts +++ b/src/ui/battle-info.ts @@ -465,7 +465,7 @@ export default class BattleInfo extends Phaser.GameObjects.Container { this.shinyIcon.setVisible(pokemon.isShiny()); - const types = pokemon.getTypes(true); + const types = pokemon.getTypes(true, false, undefined, true); this.type1Icon.setTexture(`pbinfo_${this.player ? "player" : "enemy"}_type${types.length > 1 ? "1" : ""}`); this.type1Icon.setFrame(PokemonType[types[0]].toLowerCase()); this.type2Icon.setVisible(types.length > 1); @@ -685,7 +685,7 @@ export default class BattleInfo extends Phaser.GameObjects.Container { this.statusIndicator.setVisible(!!this.lastStatus); } - const types = pokemon.getTypes(true); + const types = pokemon.getTypes(true, false, undefined, true); this.type1Icon.setTexture(`pbinfo_${this.player ? "player" : "enemy"}_type${types.length > 1 ? "1" : ""}`); this.type1Icon.setFrame(PokemonType[types[0]].toLowerCase()); this.type2Icon.setVisible(types.length > 1);