From 06b6beab020d516b5128d2215097ef9b2db8ed4c Mon Sep 17 00:00:00 2001 From: Bertie690 Date: Sun, 25 May 2025 18:49:18 -0400 Subject: [PATCH 1/7] Split up Pokemon data types to own files --- src/@types/pokemon-data.ts | 210 +++++++++++++++++++++++++++ src/field/pokemon.ts | 203 +------------------------- src/system/pokemon-data.ts | 3 +- test/battlerTags/stockpiling.test.ts | 2 +- test/battlerTags/substitute.test.ts | 3 +- 5 files changed, 218 insertions(+), 203 deletions(-) create mode 100644 src/@types/pokemon-data.ts diff --git a/src/@types/pokemon-data.ts b/src/@types/pokemon-data.ts new file mode 100644 index 00000000000..a18e41558f0 --- /dev/null +++ b/src/@types/pokemon-data.ts @@ -0,0 +1,210 @@ +import { type BattlerTag, loadBattlerTag } from "#app/data/battler-tags"; +import type { Gender } from "#app/data/gender"; +import type PokemonSpecies from "#app/data/pokemon-species"; +import type { PokemonSpeciesForm } from "#app/data/pokemon-species"; +import type { TypeDamageMultiplier } from "#app/data/type"; +import type { Variant } from "#app/sprites/variant"; +import { isNullOrUndefined } from "#app/utils/common"; +import type { Abilities } from "#enums/abilities"; +import type { BerryType } from "#enums/berry-type"; +import type { Moves } from "#enums/moves"; +import type { PokeballType } from "#enums/pokeball"; +import type { PokemonType } from "#enums/pokemon-type"; +import type { Species } from "#enums/species"; +import { type TurnMove, PokemonMove, type AttackMoveResult } from "#app/field/pokemon"; + +/** + * Persistent in-battle data for a {@linkcode Pokemon}. + * Resets on switch or new battle. + */ + +export class PokemonSummonData { + /** [Atk, Def, SpAtk, SpDef, Spd, Acc, Eva] */ + public statStages: number[] = [0, 0, 0, 0, 0, 0, 0]; + public moveQueue: TurnMove[] = []; + public tags: BattlerTag[] = []; + public abilitySuppressed = false; + + // Overrides for transform. + // TODO: Move these into a separate class & add rage fist hit count + public speciesForm: PokemonSpeciesForm | null = null; + public fusionSpeciesForm: PokemonSpeciesForm | null = null; + public ability: Abilities | undefined; + public passiveAbility: Abilities | undefined; + public gender: Gender | undefined; + public fusionGender: Gender | undefined; + public stats: number[] = [0, 0, 0, 0, 0, 0]; + public moveset: PokemonMove[] | null; + + // If not initialized this value will not be populated from save data. + public types: PokemonType[] = []; + public addedType: PokemonType | null = null; + + /** Data pertaining to this pokemon's illusion. */ + public illusion: IllusionData | null = null; + public illusionBroken = false; + + /** Array containing all berries eaten in the last turn; used by {@linkcode Abilities.CUD_CHEW} */ + public berriesEatenLast: BerryType[] = []; + + /** + * An array of all moves this pokemon has used since entering the battle. + * Used for most moves and abilities that check prior move usage or copy already-used moves. + */ + public moveHistory: TurnMove[] = []; + + constructor(source?: PokemonSummonData | Partial) { + if (isNullOrUndefined(source)) { + return; + } + + // TODO: Rework this into an actual generic function for use elsewhere + for (const [key, value] of Object.entries(source)) { + if (isNullOrUndefined(value) && this.hasOwnProperty(key)) { + continue; + } + + if (key === "moveset") { + this.moveset = value?.map((m: any) => PokemonMove.loadMove(m)); + continue; + } + + if (key === "tags") { + // load battler tags + this.tags = value.map((t: BattlerTag) => loadBattlerTag(t)); + continue; + } + this[key] = value; + } + } +} +/** + * Illusion property + */ +export interface IllusionData { + basePokemon: { + /** The actual name of the Pokemon */ + name: string; + /** The actual nickname of the Pokemon */ + nickname: string; + /** Whether the base pokemon is shiny or not */ + shiny: boolean; + /** The shiny variant of the base pokemon */ + variant: Variant; + /** Whether the fusion species of the base pokemon is shiny or not */ + fusionShiny: boolean; + /** The variant of the fusion species of the base pokemon */ + fusionVariant: Variant; + }; + /** The species of the illusion */ + species: Species; + /** The formIndex of the illusion */ + formIndex: number; + /** The gender of the illusion */ + gender: Gender; + /** The pokeball of the illusion */ + pokeball: PokeballType; + /** The fusion species of the illusion if it's a fusion */ + fusionSpecies?: PokemonSpecies; + /** The fusionFormIndex of the illusion */ + fusionFormIndex?: number; + /** The fusionGender of the illusion if it's a fusion */ + fusionGender?: Gender; + /** The level of the illusion (not used currently) */ + level?: number; +} +// TODO: Merge this inside `summmonData` but exclude from save if/when a save data serializer is added + +export class PokemonTempSummonData { + /** + * The number of turns this pokemon has spent without switching out. + * Only currently used for positioning the battle cursor. + */ + turnCount = 1; + + /** + * The number of turns this pokemon has spent in the active position since the start of the wave + * without switching out. + * Reset on switch and new wave, but not stored in `SummonData` to avoid being written to the save file. + + * Used to evaluate "first turn only" conditions such as + * {@linkcode Moves.FAKE_OUT | Fake Out} and {@linkcode Moves.FIRST_IMPRESSION | First Impression}). + */ + waveTurnCount = 1; +} +/** + * Persistent data for a {@linkcode Pokemon}. + * Resets at the start of a new battle (but not on switch). + */ + +export class PokemonBattleData { + /** Counter tracking direct hits this Pokemon has received during this battle; used for {@linkcode Moves.RAGE_FIST} */ + public hitCount = 0; + /** Whether this Pokemon has eaten a berry this battle; used for {@linkcode Moves.BELCH} */ + public hasEatenBerry = false; + /** Array containing all berries eaten and not yet recovered during this current battle; used by {@linkcode Abilities.HARVEST} */ + public berriesEaten: BerryType[] = []; + + constructor(source?: PokemonBattleData | Partial) { + if (!isNullOrUndefined(source)) { + this.hitCount = source.hitCount ?? 0; + this.hasEatenBerry = source.hasEatenBerry ?? false; + this.berriesEaten = source.berriesEaten ?? []; + } + } +} +/** + * Temporary data for a {@linkcode Pokemon}. + * Resets on new wave/battle start (but not on switch). + */ + +export class PokemonWaveData { + /** Whether the pokemon has endured due to a {@linkcode BattlerTagType.ENDURE_TOKEN} */ + public endured = false; + /** + * A set of all the abilities this {@linkcode Pokemon} has used in this wave. + * Used to track once per battle conditions, as well as (hopefully) by the updated AI for move effectiveness. + */ + public abilitiesApplied: Set = new Set(); + /** Whether the pokemon's ability has been revealed or not */ + public abilityRevealed = false; +} +/** + * Temporary data for a {@linkcode Pokemon}. + * Resets at the start of a new turn, as well as on switch. + */ + +export class PokemonTurnData { + public flinched = false; + public acted = false; + /** How many times the current move should hit the target(s) */ + public hitCount = 0; + /** + * - `-1` = Calculate how many hits are left + * - `0` = Move is finished + */ + public hitsLeft = -1; + public totalDamageDealt = 0; + public singleHitDamageDealt = 0; + public damageTaken = 0; + public attacksReceived: AttackMoveResult[] = []; + public order: number; + public statStagesIncreased = false; + public statStagesDecreased = false; + public moveEffectiveness: TypeDamageMultiplier | null = null; + public combiningPledge?: Moves; + public switchedInThisTurn = false; + public failedRunAway = false; + public joinedRound = false; + /** + * Used to make sure multi-hits occur properly when the user is + * forced to act again in the same turn + */ + public extraTurns = 0; + /** + * All berries eaten by this pokemon in this turn. + * Saved into {@linkcode PokemonSummonData | SummonData} by {@linkcode Abilities.CUD_CHEW} on turn end. + * @see {@linkcode PokemonSummonData.berriesEatenLast} + */ + public berriesEaten: BerryType[] = []; +} diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 62ec8081c5d..df2179c2980 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -124,7 +124,6 @@ import { TarShotTag, AutotomizedTag, PowerTrickTag, - loadBattlerTag, type GrudgeTag, } from "../data/battler-tags"; import { WeatherType } from "#enums/weather-type"; @@ -260,6 +259,7 @@ import { MoveFlags } from "#enums/MoveFlags"; import { timedEventManager } from "#app/global-event-manager"; import { loadMoveAnimations } from "#app/sprites/pokemon-asset-loader"; import { ResetStatusPhase } from "#app/phases/reset-status-phase"; +import { PokemonBattleData, PokemonSummonData, PokemonTempSummonData, PokemonWaveData, PokemonTurnData, type IllusionData } from "../@types/pokemon-data"; export enum LearnMoveSituation { MISC, @@ -3719,7 +3719,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { // Status moves remain unchanged on weight, this encourages 1-2 movePool = baseWeights .filter(m => !this.moveset.some( - mo => + mo => m[0] === mo.moveId || (allMoves[m[0]].hasAttr(SacrificialAttr) && mo.getMove().hasAttr(SacrificialAttr)) // Only one self-KO move allowed )) @@ -3754,7 +3754,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } else { // Non-trainer pokemon just use normal weights movePool = baseWeights.filter(m => !this.moveset.some( - mo => + mo => m[0] === mo.moveId || (allMoves[m[0]].hasAttr(SacrificialAttr) && mo.getMove().hasAttr(SacrificialAttr)) // Only one self-KO move allowed )); @@ -7756,42 +7756,6 @@ export class EnemyPokemon extends Pokemon { } } -/** - * Illusion property - */ -interface IllusionData { - basePokemon: { - /** The actual name of the Pokemon */ - name: string; - /** The actual nickname of the Pokemon */ - nickname: string; - /** Whether the base pokemon is shiny or not */ - shiny: boolean; - /** The shiny variant of the base pokemon */ - variant: Variant; - /** Whether the fusion species of the base pokemon is shiny or not */ - fusionShiny: boolean; - /** The variant of the fusion species of the base pokemon */ - fusionVariant: Variant; - }; - /** The species of the illusion */ - species: Species; - /** The formIndex of the illusion */ - formIndex: number; - /** The gender of the illusion */ - gender: Gender; - /** The pokeball of the illusion */ - pokeball: PokeballType; - /** The fusion species of the illusion if it's a fusion */ - fusionSpecies?: PokemonSpecies; - /** The fusionFormIndex of the illusion */ - fusionFormIndex?: number; - /** The fusionGender of the illusion if it's a fusion */ - fusionGender?: Gender; - /** The level of the illusion (not used currently) */ - level?: number -} - export interface TurnMove { move: Moves; targets: BattlerIndex[]; @@ -7810,167 +7774,6 @@ export interface AttackMoveResult { sourceBattlerIndex: BattlerIndex; } -/** - * Persistent in-battle data for a {@linkcode Pokemon}. - * Resets on switch or new battle. - */ -export class PokemonSummonData { - /** [Atk, Def, SpAtk, SpDef, Spd, Acc, Eva] */ - public statStages: number[] = [0, 0, 0, 0, 0, 0, 0]; - public moveQueue: TurnMove[] = []; - public tags: BattlerTag[] = []; - public abilitySuppressed = false; - - // Overrides for transform. - // TODO: Move these into a separate class & add rage fist hit count - public speciesForm: PokemonSpeciesForm | null = null; - public fusionSpeciesForm: PokemonSpeciesForm | null = null; - public ability: Abilities | undefined; - public passiveAbility: Abilities | undefined; - public gender: Gender | undefined; - public fusionGender: Gender | undefined; - public stats: number[] = [0, 0, 0, 0, 0, 0]; - public moveset: PokemonMove[] | null; - - // If not initialized this value will not be populated from save data. - public types: PokemonType[] = []; - public addedType: PokemonType | null = null; - - /** Data pertaining to this pokemon's illusion. */ - public illusion: IllusionData | null = null; - public illusionBroken: boolean = false; - - /** Array containing all berries eaten in the last turn; used by {@linkcode Abilities.CUD_CHEW} */ - public berriesEatenLast: BerryType[] = []; - - /** - * An array of all moves this pokemon has used since entering the battle. - * Used for most moves and abilities that check prior move usage or copy already-used moves. - */ - public moveHistory: TurnMove[] = []; - - constructor(source?: PokemonSummonData | Partial) { - if (isNullOrUndefined(source)) { - return; - } - - // TODO: Rework this into an actual generic function for use elsewhere - for (const [key, value] of Object.entries(source)) { - if (isNullOrUndefined(value) && this.hasOwnProperty(key)) { - continue; - } - - if (key === "moveset") { - this.moveset = value?.map((m: any) => PokemonMove.loadMove(m)); - continue; - } - - if (key === "tags") { - // load battler tags - this.tags = value.map((t: BattlerTag) => loadBattlerTag(t)); - continue; - } - this[key] = value; - } - } -} - - // TODO: Merge this inside `summmonData` but exclude from save if/when a save data serializer is added -export class PokemonTempSummonData { - /** - * The number of turns this pokemon has spent without switching out. - * Only currently used for positioning the battle cursor. - */ - turnCount: number = 1; - - /** - * The number of turns this pokemon has spent in the active position since the start of the wave - * without switching out. - * Reset on switch and new wave, but not stored in `SummonData` to avoid being written to the save file. - - * Used to evaluate "first turn only" conditions such as - * {@linkcode Moves.FAKE_OUT | Fake Out} and {@linkcode Moves.FIRST_IMPRESSION | First Impression}). - */ - waveTurnCount = 1; - -} - -/** - * Persistent data for a {@linkcode Pokemon}. - * Resets at the start of a new battle (but not on switch). - */ -export class PokemonBattleData { - /** Counter tracking direct hits this Pokemon has received during this battle; used for {@linkcode Moves.RAGE_FIST} */ - public hitCount = 0; - /** Whether this Pokemon has eaten a berry this battle; used for {@linkcode Moves.BELCH} */ - public hasEatenBerry: boolean = false; - /** Array containing all berries eaten and not yet recovered during this current battle; used by {@linkcode Abilities.HARVEST} */ - public berriesEaten: BerryType[] = []; - - constructor(source?: PokemonBattleData | Partial) { - if (!isNullOrUndefined(source)) { - this.hitCount = source.hitCount ?? 0; - this.hasEatenBerry = source.hasEatenBerry ?? false; - this.berriesEaten = source.berriesEaten ?? []; - } - } -} - -/** - * Temporary data for a {@linkcode Pokemon}. - * Resets on new wave/battle start (but not on switch). - */ -export class PokemonWaveData { - /** Whether the pokemon has endured due to a {@linkcode BattlerTagType.ENDURE_TOKEN} */ - public endured = false; - /** - * A set of all the abilities this {@linkcode Pokemon} has used in this wave. - * Used to track once per battle conditions, as well as (hopefully) by the updated AI for move effectiveness. - */ - public abilitiesApplied: Set = new Set; - /** Whether the pokemon's ability has been revealed or not */ - public abilityRevealed = false; -} - -/** - * Temporary data for a {@linkcode Pokemon}. - * Resets at the start of a new turn, as well as on switch. - */ -export class PokemonTurnData { - public flinched = false; - public acted = false; - /** How many times the current move should hit the target(s) */ - public hitCount = 0; - /** - * - `-1` = Calculate how many hits are left - * - `0` = Move is finished - */ - public hitsLeft = -1; - public totalDamageDealt = 0; - public singleHitDamageDealt = 0; - public damageTaken = 0; - public attacksReceived: AttackMoveResult[] = []; - public order: number; - public statStagesIncreased = false; - public statStagesDecreased = false; - public moveEffectiveness: TypeDamageMultiplier | null = null; - public combiningPledge?: Moves; - public switchedInThisTurn = false; - public failedRunAway = false; - public joinedRound = false; - /** - * Used to make sure multi-hits occur properly when the user is - * forced to act again in the same turn - */ - public extraTurns = 0; - /** - * All berries eaten by this pokemon in this turn. - * Saved into {@linkcode PokemonSummonData | SummonData} by {@linkcode Abilities.CUD_CHEW} on turn end. - * @see {@linkcode PokemonSummonData.berriesEatenLast} - */ - public berriesEaten: BerryType[] = [] -} - export enum AiType { RANDOM, SMART_RANDOM, diff --git a/src/system/pokemon-data.ts b/src/system/pokemon-data.ts index 00169678ed0..cb45c7c8e50 100644 --- a/src/system/pokemon-data.ts +++ b/src/system/pokemon-data.ts @@ -5,7 +5,8 @@ import { Nature } from "#enums/nature"; import { PokeballType } from "#enums/pokeball"; import { getPokemonSpecies, getPokemonSpeciesForm } from "../data/pokemon-species"; import { Status } from "../data/status-effect"; -import Pokemon, { EnemyPokemon, PokemonBattleData, PokemonMove, PokemonSummonData } from "../field/pokemon"; +import Pokemon, { EnemyPokemon, PokemonMove } from "../field/pokemon"; +import { PokemonBattleData, PokemonSummonData } from "#app/@types/pokemon-data"; import { TrainerSlot } from "#enums/trainer-slot"; import type { Variant } from "#app/sprites/variant"; import type { Biome } from "#enums/biome"; diff --git a/test/battlerTags/stockpiling.test.ts b/test/battlerTags/stockpiling.test.ts index 20fade13d92..a42250b8f6f 100644 --- a/test/battlerTags/stockpiling.test.ts +++ b/test/battlerTags/stockpiling.test.ts @@ -1,6 +1,6 @@ import { StockpilingTag } from "#app/data/battler-tags"; import type Pokemon from "#app/field/pokemon"; -import { PokemonSummonData } from "#app/field/pokemon"; +import { PokemonSummonData } from "#app/@types/pokemon-data"; import * as messages from "#app/messages"; import { StatStageChangePhase } from "#app/phases/stat-stage-change-phase"; import { Stat } from "#enums/stat"; diff --git a/test/battlerTags/substitute.test.ts b/test/battlerTags/substitute.test.ts index 827b9f48f85..53a1d5755b1 100644 --- a/test/battlerTags/substitute.test.ts +++ b/test/battlerTags/substitute.test.ts @@ -1,5 +1,6 @@ import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; -import type { PokemonTurnData, TurnMove } from "#app/field/pokemon"; +import type { TurnMove } from "#app/field/pokemon"; +import type { PokemonTurnData } from "#app/@types/pokemon-data"; import type Pokemon from "#app/field/pokemon"; import { MoveResult } from "#app/field/pokemon"; import type BattleScene from "#app/battle-scene"; From 70dbabe281d8ea7a0f0a2ed99cfc90dd112fb0e3 Mon Sep 17 00:00:00 2001 From: Bertie690 Date: Sun, 25 May 2025 18:53:30 -0400 Subject: [PATCH 2/7] Moved `AttackMoveResult` and `TurnMove` to own files --- src/@types/attack-move-result.ts | 12 ++++++++++++ src/@types/pokemon-data.ts | 4 +++- src/@types/turn-move.ts | 12 ++++++++++++ src/battle.ts | 3 ++- src/data/moves/move.ts | 3 ++- src/field/pokemon.ts | 19 +------------------ src/phases/command-phase.ts | 3 ++- src/phases/move-effect-phase.ts | 7 ++++--- test/battlerTags/substitute.test.ts | 2 +- test/moves/spit_up.test.ts | 2 +- test/moves/stockpile.test.ts | 2 +- test/moves/swallow.test.ts | 2 +- 12 files changed, 42 insertions(+), 29 deletions(-) create mode 100644 src/@types/attack-move-result.ts create mode 100644 src/@types/turn-move.ts diff --git a/src/@types/attack-move-result.ts b/src/@types/attack-move-result.ts new file mode 100644 index 00000000000..e03c5009042 --- /dev/null +++ b/src/@types/attack-move-result.ts @@ -0,0 +1,12 @@ +import type { BattlerIndex } from "#app/battle"; +import type { Moves } from "#enums/moves"; +import type { DamageResult } from "#app/field/pokemon"; + +export interface AttackMoveResult { + move: Moves; + result: DamageResult; + damage: number; + critical: boolean; + sourceId: number; + sourceBattlerIndex: BattlerIndex; +} diff --git a/src/@types/pokemon-data.ts b/src/@types/pokemon-data.ts index a18e41558f0..cc137cdab9d 100644 --- a/src/@types/pokemon-data.ts +++ b/src/@types/pokemon-data.ts @@ -11,7 +11,9 @@ import type { Moves } from "#enums/moves"; import type { PokeballType } from "#enums/pokeball"; import type { PokemonType } from "#enums/pokemon-type"; import type { Species } from "#enums/species"; -import { type TurnMove, PokemonMove, type AttackMoveResult } from "#app/field/pokemon"; +import { PokemonMove } from "#app/field/pokemon"; +import type { TurnMove } from "#app/@types/turn-move"; +import type { AttackMoveResult } from "#app/@types/attack-move-result"; /** * Persistent in-battle data for a {@linkcode Pokemon}. diff --git a/src/@types/turn-move.ts b/src/@types/turn-move.ts new file mode 100644 index 00000000000..ad413dd6aca --- /dev/null +++ b/src/@types/turn-move.ts @@ -0,0 +1,12 @@ +import type { BattlerIndex } from "#app/battle"; +import type { Moves } from "#enums/moves"; +import type { MoveResult } from "#app/field/pokemon"; + +export interface TurnMove { + move: Moves; + targets: BattlerIndex[]; + result?: MoveResult; + virtual?: boolean; + turn?: number; + ignorePP?: boolean; +} diff --git a/src/battle.ts b/src/battle.ts index 07e520d6bc0..0c0f6fa44ea 100644 --- a/src/battle.ts +++ b/src/battle.ts @@ -15,7 +15,8 @@ import { MoneyMultiplierModifier, PokemonHeldItemModifier } from "./modifier/mod import type { PokeballType } from "#enums/pokeball"; import { trainerConfigs } from "#app/data/trainers/trainer-config"; import { SpeciesFormKey } from "#enums/species-form-key"; -import type { EnemyPokemon, PlayerPokemon, TurnMove } from "#app/field/pokemon"; +import type { EnemyPokemon, PlayerPokemon } from "#app/field/pokemon"; +import type { TurnMove } from "./@types/turn-move"; import type Pokemon from "#app/field/pokemon"; import { ArenaTagType } from "#enums/arena-tag-type"; import { BattleSpec } from "#enums/battle-spec"; diff --git a/src/data/moves/move.ts b/src/data/moves/move.ts index 31ad3337926..af96a52f6b0 100644 --- a/src/data/moves/move.ts +++ b/src/data/moves/move.ts @@ -12,7 +12,8 @@ import { TypeBoostTag, } from "../battler-tags"; import { getPokemonNameWithAffix } from "../../messages"; -import type { AttackMoveResult, TurnMove } from "../../field/pokemon"; +import type { TurnMove } from "#app/@types/turn-move"; +import type { AttackMoveResult } from "#app/@types/attack-move-result"; import type Pokemon from "../../field/pokemon"; import { EnemyPokemon, diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index df2179c2980..34e189db0ed 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -260,6 +260,7 @@ import { timedEventManager } from "#app/global-event-manager"; import { loadMoveAnimations } from "#app/sprites/pokemon-asset-loader"; import { ResetStatusPhase } from "#app/phases/reset-status-phase"; import { PokemonBattleData, PokemonSummonData, PokemonTempSummonData, PokemonWaveData, PokemonTurnData, type IllusionData } from "../@types/pokemon-data"; +import type { TurnMove } from "../@types/turn-move"; export enum LearnMoveSituation { MISC, @@ -7756,24 +7757,6 @@ export class EnemyPokemon extends Pokemon { } } -export interface TurnMove { - move: Moves; - targets: BattlerIndex[]; - result?: MoveResult; - virtual?: boolean; - turn?: number; - ignorePP?: boolean; -} - -export interface AttackMoveResult { - move: Moves; - result: DamageResult; - damage: number; - critical: boolean; - sourceId: number; - sourceBattlerIndex: BattlerIndex; -} - export enum AiType { RANDOM, SMART_RANDOM, diff --git a/src/phases/command-phase.ts b/src/phases/command-phase.ts index c3e558e1d86..fe060e9a65c 100644 --- a/src/phases/command-phase.ts +++ b/src/phases/command-phase.ts @@ -11,7 +11,8 @@ import { BattlerTagType } from "#app/enums/battler-tag-type"; import { Biome } from "#app/enums/biome"; import { Moves } from "#app/enums/moves"; import { PokeballType } from "#enums/pokeball"; -import type { PlayerPokemon, TurnMove } from "#app/field/pokemon"; +import type { PlayerPokemon } from "#app/field/pokemon"; +import type { TurnMove } from "#app/@types/turn-move"; import { FieldPosition } from "#app/field/pokemon"; import { getPokemonNameWithAffix } from "#app/messages"; import { Command } from "#app/ui/command-ui-handler"; diff --git a/src/phases/move-effect-phase.ts b/src/phases/move-effect-phase.ts index e3773952214..47780636181 100644 --- a/src/phases/move-effect-phase.ts +++ b/src/phases/move-effect-phase.ts @@ -48,7 +48,8 @@ import { MoveTarget } from "#enums/MoveTarget"; import { MoveCategory } from "#enums/MoveCategory"; import { SpeciesFormChangePostMoveTrigger } from "#app/data/pokemon-forms"; import { PokemonType } from "#enums/pokemon-type"; -import { DamageResult, PokemonMove, type TurnMove } from "#app/field/pokemon"; +import { type DamageResult, PokemonMove } from "#app/field/pokemon"; +import type { TurnMove } from "#app/@types/turn-move"; import type Pokemon from "#app/field/pokemon"; import { HitResult, MoveResult } from "#app/field/pokemon"; import { getPokemonNameWithAffix } from "#app/messages"; @@ -72,7 +73,7 @@ import { ShowAbilityPhase } from "./show-ability-phase"; import { MovePhase } from "./move-phase"; import { MoveEndPhase } from "./move-end-phase"; import { HideAbilityPhase } from "#app/phases/hide-ability-phase"; -import { TypeDamageMultiplier } from "#app/data/type"; +import type { TypeDamageMultiplier } from "#app/data/type"; import { HitCheckResult } from "#enums/hit-check-result"; import type Move from "#app/data/moves/move"; import { isFieldTargeted } from "#app/data/moves/move-utils"; @@ -809,7 +810,7 @@ export class MoveEffectPhase extends PokemonPhase { */ applyMoveAttrs(StatChangeBeforeDmgCalcAttr, user, target, this.move); - const { result: result, damage: dmg } = target.getAttackDamage({ + const { result, damage: dmg } = target.getAttackDamage({ source: user, move: this.move, ignoreAbility: false, diff --git a/test/battlerTags/substitute.test.ts b/test/battlerTags/substitute.test.ts index 53a1d5755b1..472a651cbe0 100644 --- a/test/battlerTags/substitute.test.ts +++ b/test/battlerTags/substitute.test.ts @@ -1,5 +1,5 @@ import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; -import type { TurnMove } from "#app/field/pokemon"; +import type { TurnMove } from "#app/@types/turn-move"; import type { PokemonTurnData } from "#app/@types/pokemon-data"; import type Pokemon from "#app/field/pokemon"; import { MoveResult } from "#app/field/pokemon"; diff --git a/test/moves/spit_up.test.ts b/test/moves/spit_up.test.ts index 7197d9b75c3..ec19d3e8c73 100644 --- a/test/moves/spit_up.test.ts +++ b/test/moves/spit_up.test.ts @@ -2,7 +2,7 @@ import { Stat } from "#enums/stat"; import { StockpilingTag } from "#app/data/battler-tags"; import { allMoves } from "#app/data/data-lists"; import { BattlerTagType } from "#app/enums/battler-tag-type"; -import type { TurnMove } from "#app/field/pokemon"; +import type { TurnMove } from "#app/@types/turn-move"; import { MoveResult } from "#app/field/pokemon"; import GameManager from "#test/testUtils/gameManager"; import { Abilities } from "#enums/abilities"; diff --git a/test/moves/stockpile.test.ts b/test/moves/stockpile.test.ts index 4b8f51c32b2..49d9c4c8441 100644 --- a/test/moves/stockpile.test.ts +++ b/test/moves/stockpile.test.ts @@ -1,6 +1,6 @@ import { Stat } from "#enums/stat"; import { StockpilingTag } from "#app/data/battler-tags"; -import type { TurnMove } from "#app/field/pokemon"; +import type { TurnMove } from "#app/@types/turn-move"; import { MoveResult } from "#app/field/pokemon"; import { CommandPhase } from "#app/phases/command-phase"; import { TurnInitPhase } from "#app/phases/turn-init-phase"; diff --git a/test/moves/swallow.test.ts b/test/moves/swallow.test.ts index d548522068b..96136ae4571 100644 --- a/test/moves/swallow.test.ts +++ b/test/moves/swallow.test.ts @@ -1,7 +1,7 @@ import { Stat } from "#enums/stat"; import { StockpilingTag } from "#app/data/battler-tags"; import { BattlerTagType } from "#app/enums/battler-tag-type"; -import type { TurnMove } from "#app/field/pokemon"; +import type { TurnMove } from "#app/@types/turn-move"; import { MoveResult } from "#app/field/pokemon"; import { MovePhase } from "#app/phases/move-phase"; import { TurnInitPhase } from "#app/phases/turn-init-phase"; From 95690be3c96369c5d9ffbc3c0d470d3dc9d7dafd Mon Sep 17 00:00:00 2001 From: Bertie690 Date: Sun, 25 May 2025 18:58:24 -0400 Subject: [PATCH 3/7] Moved `customPokemonData` into types folder + fixed comments --- src/@types/pokemon-data.ts | 39 ++++++++++++++++--- src/data/custom-pokemon-data.ts | 31 --------------- .../encounters/clowning-around-encounter.ts | 2 +- .../slumbering-snorlax-encounter.ts | 16 ++++---- .../encounters/the-strong-stuff-encounter.ts | 2 +- .../utils/encounter-phase-utils.ts | 2 +- .../utils/encounter-pokemon-utils.ts | 2 +- src/field/pokemon.ts | 2 +- src/system/pokemon-data.ts | 2 +- .../version_migration/versions/v1_0_4.ts | 2 +- test/field/pokemon.test.ts | 2 +- .../the-strong-stuff-encounter.test.ts | 2 +- 12 files changed, 50 insertions(+), 54 deletions(-) diff --git a/src/@types/pokemon-data.ts b/src/@types/pokemon-data.ts index cc137cdab9d..b2907112484 100644 --- a/src/@types/pokemon-data.ts +++ b/src/@types/pokemon-data.ts @@ -14,12 +14,40 @@ import type { Species } from "#enums/species"; import { PokemonMove } from "#app/field/pokemon"; import type { TurnMove } from "#app/@types/turn-move"; import type { AttackMoveResult } from "#app/@types/attack-move-result"; +import type { Nature } from "#enums/nature"; + +/** + * Permanent data that can customize a Pokemon in non-standard ways from its Species. + * Includes abilities, nature, changed types, etc. + */ +export class CustomPokemonData { + // TODO: Change the default value for all these from -1 to something a bit more sensible + /** + * The scale at which to render this Pokemon's sprite. + */ + public spriteScale = -1; + public ability: Abilities | -1; + public passive: Abilities | -1; + public nature: Nature | -1; + public types: PokemonType[]; + /** Deprecated but needed for session save migration */ + // TODO: Remove this once pre-session migration is implemented + public hitsRecCount: number | null = null; + + constructor(data?: CustomPokemonData | Partial) { + this.spriteScale = data?.spriteScale ?? -1; + this.ability = data?.ability ?? -1; + this.passive = data?.passive ?? -1; + this.nature = data?.nature ?? -1; + this.types = data?.types ?? []; + this.hitsRecCount = data?.hitsRecCount ?? null; + } +} /** * Persistent in-battle data for a {@linkcode Pokemon}. * Resets on switch or new battle. */ - export class PokemonSummonData { /** [Atk, Def, SpAtk, SpDef, Spd, Acc, Eva] */ public statStages: number[] = [0, 0, 0, 0, 0, 0, 0]; @@ -80,6 +108,7 @@ export class PokemonSummonData { } } } + /** * Illusion property */ @@ -115,8 +144,8 @@ export interface IllusionData { /** The level of the illusion (not used currently) */ level?: number; } -// TODO: Merge this inside `summmonData` but exclude from save if/when a save data serializer is added +// TODO: Merge this inside `summmonData` but exclude from save if/when a save data serializer is added export class PokemonTempSummonData { /** * The number of turns this pokemon has spent without switching out. @@ -134,11 +163,11 @@ export class PokemonTempSummonData { */ waveTurnCount = 1; } + /** * Persistent data for a {@linkcode Pokemon}. * Resets at the start of a new battle (but not on switch). */ - export class PokemonBattleData { /** Counter tracking direct hits this Pokemon has received during this battle; used for {@linkcode Moves.RAGE_FIST} */ public hitCount = 0; @@ -155,11 +184,11 @@ export class PokemonBattleData { } } } + /** * Temporary data for a {@linkcode Pokemon}. * Resets on new wave/battle start (but not on switch). */ - export class PokemonWaveData { /** Whether the pokemon has endured due to a {@linkcode BattlerTagType.ENDURE_TOKEN} */ public endured = false; @@ -171,11 +200,11 @@ export class PokemonWaveData { /** Whether the pokemon's ability has been revealed or not */ public abilityRevealed = false; } + /** * Temporary data for a {@linkcode Pokemon}. * Resets at the start of a new turn, as well as on switch. */ - export class PokemonTurnData { public flinched = false; public acted = false; diff --git a/src/data/custom-pokemon-data.ts b/src/data/custom-pokemon-data.ts index 20f6ea96174..e69de29bb2d 100644 --- a/src/data/custom-pokemon-data.ts +++ b/src/data/custom-pokemon-data.ts @@ -1,31 +0,0 @@ -import type { Abilities } from "#enums/abilities"; -import type { PokemonType } from "#enums/pokemon-type"; -import type { Nature } from "#enums/nature"; - -/** - * Data that can customize a Pokemon in non-standard ways from its Species. - * Includes abilities, nature, changed types, etc. - */ -export class CustomPokemonData { - // TODO: Change the default value for all these from -1 to something a bit more sensible - /** - * The scale at which to render this Pokemon's sprite. - */ - public spriteScale = -1; - public ability: Abilities | -1; - public passive: Abilities | -1; - public nature: Nature | -1; - public types: PokemonType[]; - /** Deprecated but needed for session save migration */ - // TODO: Remove this once pre-session migration is implemented - public hitsRecCount: number | null = null; - - constructor(data?: CustomPokemonData | Partial) { - this.spriteScale = data?.spriteScale ?? -1; - this.ability = data?.ability ?? -1; - this.passive = data?.passive ?? -1; - this.nature = data?.nature ?? -1; - this.types = data?.types ?? []; - this.hitsRecCount = data?.hitsRecCount ?? null; - } -} diff --git a/src/data/mystery-encounters/encounters/clowning-around-encounter.ts b/src/data/mystery-encounters/encounters/clowning-around-encounter.ts index ce5eb2cfdd1..761dd37aa4c 100644 --- a/src/data/mystery-encounters/encounters/clowning-around-encounter.ts +++ b/src/data/mystery-encounters/encounters/clowning-around-encounter.ts @@ -45,7 +45,7 @@ import { BattlerIndex } from "#app/battle"; import { Moves } from "#enums/moves"; import { EncounterBattleAnim } from "#app/data/battle-anims"; import { MoveCategory } from "#enums/MoveCategory"; -import { CustomPokemonData } from "#app/data/custom-pokemon-data"; +import { CustomPokemonData } from "#app/@types/pokemon-data"; import { CLASSIC_MODE_MYSTERY_ENCOUNTER_WAVES } from "#app/constants"; import { EncounterAnim } from "#enums/encounter-anims"; import { Challenges } from "#enums/challenges"; diff --git a/src/data/mystery-encounters/encounters/slumbering-snorlax-encounter.ts b/src/data/mystery-encounters/encounters/slumbering-snorlax-encounter.ts index 2654f6b18d8..eb7a1e8f712 100644 --- a/src/data/mystery-encounters/encounters/slumbering-snorlax-encounter.ts +++ b/src/data/mystery-encounters/encounters/slumbering-snorlax-encounter.ts @@ -29,7 +29,7 @@ import { MysteryEncounterOptionMode } from "#enums/mystery-encounter-option-mode import { PartyHealPhase } from "#app/phases/party-heal-phase"; import { BerryType } from "#enums/berry-type"; import { Stat } from "#enums/stat"; -import { CustomPokemonData } from "#app/data/custom-pokemon-data"; +import { CustomPokemonData } from "#app/@types/pokemon-data"; import { randSeedInt } from "#app/utils/common"; /** i18n namespace for the encounter */ @@ -133,14 +133,12 @@ export const SlumberingSnorlaxEncounter: MysteryEncounter = MysteryEncounterBuil guaranteedModifierTypeFuncs: [modifierTypes.LEFTOVERS], fillRemaining: true, }); - encounter.startOfBattleEffects.push( - { - sourceBattlerIndex: BattlerIndex.ENEMY, - targets: [BattlerIndex.PLAYER], - move: new PokemonMove(Moves.SNORE), - ignorePp: true, - }, - ); + encounter.startOfBattleEffects.push({ + sourceBattlerIndex: BattlerIndex.ENEMY, + targets: [BattlerIndex.PLAYER], + move: new PokemonMove(Moves.SNORE), + ignorePp: true, + }); await initBattleWithEnemyConfig(encounter.enemyPartyConfigs[0]); }, ) diff --git a/src/data/mystery-encounters/encounters/the-strong-stuff-encounter.ts b/src/data/mystery-encounters/encounters/the-strong-stuff-encounter.ts index 294f1a78b34..8bb68b1b4f8 100644 --- a/src/data/mystery-encounters/encounters/the-strong-stuff-encounter.ts +++ b/src/data/mystery-encounters/encounters/the-strong-stuff-encounter.ts @@ -25,7 +25,7 @@ import { BattlerIndex } from "#app/battle"; import { BattlerTagType } from "#enums/battler-tag-type"; import { BerryType } from "#enums/berry-type"; import { MysteryEncounterTier } from "#enums/mystery-encounter-tier"; -import { CustomPokemonData } from "#app/data/custom-pokemon-data"; +import { CustomPokemonData } from "#app/@types/pokemon-data"; import { Stat } from "#enums/stat"; import { StatStageChangePhase } from "#app/phases/stat-stage-change-phase"; import { CLASSIC_MODE_MYSTERY_ENCOUNTER_WAVES } from "#app/constants"; diff --git a/src/data/mystery-encounters/utils/encounter-phase-utils.ts b/src/data/mystery-encounters/utils/encounter-phase-utils.ts index 0215928bbe8..db176b9eb9a 100644 --- a/src/data/mystery-encounters/utils/encounter-phase-utils.ts +++ b/src/data/mystery-encounters/utils/encounter-phase-utils.ts @@ -49,7 +49,7 @@ import { TrainerSlot } from "#enums/trainer-slot"; import type PokemonSpecies from "#app/data/pokemon-species"; import type { IEggOptions } from "#app/data/egg"; import { Egg } from "#app/data/egg"; -import type { CustomPokemonData } from "#app/data/custom-pokemon-data"; +import type { CustomPokemonData } from "#app/@types/pokemon-data"; import type HeldModifierConfig from "#app/interfaces/held-modifier-config"; import { MovePhase } from "#app/phases/move-phase"; import { EggLapsePhase } from "#app/phases/egg-lapse-phase"; diff --git a/src/data/mystery-encounters/utils/encounter-pokemon-utils.ts b/src/data/mystery-encounters/utils/encounter-pokemon-utils.ts index a6a87b4ab9a..7e936ae738e 100644 --- a/src/data/mystery-encounters/utils/encounter-pokemon-utils.ts +++ b/src/data/mystery-encounters/utils/encounter-pokemon-utils.ts @@ -34,7 +34,7 @@ import { Gender } from "#app/data/gender"; import type { PermanentStat } from "#enums/stat"; import { VictoryPhase } from "#app/phases/victory-phase"; import { SummaryUiMode } from "#app/ui/summary-ui-handler"; -import { CustomPokemonData } from "#app/data/custom-pokemon-data"; +import { CustomPokemonData } from "#app/@types/pokemon-data"; import type { Abilities } from "#enums/abilities"; import type { PokeballType } from "#enums/pokeball"; import { StatusEffect } from "#enums/status-effect"; diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 34e189db0ed..42aa2b1a462 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -242,7 +242,7 @@ import { SwitchSummonPhase } from "#app/phases/switch-summon-phase"; import { Challenges } from "#enums/challenges"; import { PokemonAnimType } from "#enums/pokemon-anim-type"; import { PLAYER_PARTY_MAX_SIZE } from "#app/constants"; -import { CustomPokemonData } from "#app/data/custom-pokemon-data"; +import { CustomPokemonData } from "#app/@types/pokemon-data"; import { SwitchType } from "#enums/switch-type"; import { SpeciesFormKey } from "#enums/species-form-key"; import { getStatusEffectOverlapText } from "#app/data/status-effect"; diff --git a/src/system/pokemon-data.ts b/src/system/pokemon-data.ts index cb45c7c8e50..49f48913fae 100644 --- a/src/system/pokemon-data.ts +++ b/src/system/pokemon-data.ts @@ -12,7 +12,7 @@ import type { Variant } from "#app/sprites/variant"; import type { Biome } from "#enums/biome"; import type { Moves } from "#enums/moves"; import type { Species } from "#enums/species"; -import { CustomPokemonData } from "#app/data/custom-pokemon-data"; +import { CustomPokemonData } from "#app/@types/pokemon-data"; import type { PokemonType } from "#enums/pokemon-type"; export default class PokemonData { diff --git a/src/system/version_migration/versions/v1_0_4.ts b/src/system/version_migration/versions/v1_0_4.ts index 9e30ccdc2a7..a9732744b3a 100644 --- a/src/system/version_migration/versions/v1_0_4.ts +++ b/src/system/version_migration/versions/v1_0_4.ts @@ -2,7 +2,7 @@ import { SettingKeys } from "#app/system/settings/settings"; import type { SystemSaveData, SessionSaveData } from "#app/system/game-data"; import { AbilityAttr, defaultStarterSpecies, DexAttr } from "#app/system/game-data"; import { allSpecies } from "#app/data/pokemon-species"; -import { CustomPokemonData } from "#app/data/custom-pokemon-data"; +import { CustomPokemonData } from "#app/@types/pokemon-data"; import { isNullOrUndefined } from "#app/utils/common"; import type { SystemSaveMigrator } from "#app/@types/SystemSaveMigrator"; import type { SettingsSaveMigrator } from "#app/@types/SettingsSaveMigrator"; diff --git a/test/field/pokemon.test.ts b/test/field/pokemon.test.ts index f763ab2c401..3eade9f1498 100644 --- a/test/field/pokemon.test.ts +++ b/test/field/pokemon.test.ts @@ -5,7 +5,7 @@ import { PokeballType } from "#enums/pokeball"; import type BattleScene from "#app/battle-scene"; import { Moves } from "#app/enums/moves"; import { PokemonType } from "#enums/pokemon-type"; -import { CustomPokemonData } from "#app/data/custom-pokemon-data"; +import { CustomPokemonData } from "#app/@types/pokemon-data"; describe("Spec - Pokemon", () => { let phaserGame: Phaser.Game; diff --git a/test/mystery-encounter/encounters/the-strong-stuff-encounter.test.ts b/test/mystery-encounter/encounters/the-strong-stuff-encounter.test.ts index e3440aee9e0..621da5dca8a 100644 --- a/test/mystery-encounter/encounters/the-strong-stuff-encounter.test.ts +++ b/test/mystery-encounter/encounters/the-strong-stuff-encounter.test.ts @@ -24,7 +24,7 @@ import { BerryModifier, PokemonBaseStatTotalModifier } from "#app/modifier/modif import { MysteryEncounterOptionMode } from "#enums/mystery-encounter-option-mode"; import { MysteryEncounterTier } from "#enums/mystery-encounter-tier"; import { initSceneWithoutEncounterPhase } from "#test/testUtils/gameManagerUtils"; -import { CustomPokemonData } from "#app/data/custom-pokemon-data"; +import { CustomPokemonData } from "#app/@types/pokemon-data"; import { CommandPhase } from "#app/phases/command-phase"; import { MovePhase } from "#app/phases/move-phase"; import { SelectModifierPhase } from "#app/phases/select-modifier-phase"; From 4fa850d924d8a37cb7a5d75e9a7ef0697ceb04c9 Mon Sep 17 00:00:00 2001 From: Bertie690 Date: Thu, 29 May 2025 11:55:33 -0400 Subject: [PATCH 4/7] Moved files around + fixed stuff --- src/@types/illusion-data.ts | 41 +++++++++++++++++++ src/data/custom-pokemon-data.ts | 0 .../encounters/clowning-around-encounter.ts | 2 +- .../slumbering-snorlax-encounter.ts | 2 +- .../encounters/the-strong-stuff-encounter.ts | 2 +- .../utils/encounter-phase-utils.ts | 2 +- .../utils/encounter-pokemon-utils.ts | 2 +- src/{@types => data/pokemon}/pokemon-data.ts | 41 +------------------ src/field/pokemon.ts | 5 ++- src/system/pokemon-data.ts | 4 +- .../version_migration/versions/v1_0_4.ts | 2 +- test/battlerTags/stockpiling.test.ts | 2 +- test/battlerTags/substitute.test.ts | 2 +- test/field/pokemon.test.ts | 2 +- .../the-strong-stuff-encounter.test.ts | 2 +- 15 files changed, 57 insertions(+), 54 deletions(-) create mode 100644 src/@types/illusion-data.ts delete mode 100644 src/data/custom-pokemon-data.ts rename src/{@types => data/pokemon}/pokemon-data.ts (84%) diff --git a/src/@types/illusion-data.ts b/src/@types/illusion-data.ts new file mode 100644 index 00000000000..e00aaa78eb1 --- /dev/null +++ b/src/@types/illusion-data.ts @@ -0,0 +1,41 @@ +import type { Gender } from "#app/data/gender"; +import type PokemonSpecies from "#app/data/pokemon-species"; +import type { Variant } from "#app/sprites/variant"; +import type { PokeballType } from "#enums/pokeball"; +import type { Species } from "#enums/species"; + +/** + * Data pertaining to this Pokemon's Illusion. + */ +export interface IllusionData { + basePokemon: { + /** The actual name of the Pokemon */ + name: string; + /** The actual nickname of the Pokemon */ + nickname: string; + /** Whether the base pokemon is shiny or not */ + shiny: boolean; + /** The shiny variant of the base pokemon */ + variant: Variant; + /** Whether the fusion species of the base pokemon is shiny or not */ + fusionShiny: boolean; + /** The variant of the fusion species of the base pokemon */ + fusionVariant: Variant; + }; + /** The species of the illusion */ + species: Species; + /** The formIndex of the illusion */ + formIndex: number; + /** The gender of the illusion */ + gender: Gender; + /** The pokeball of the illusion */ + pokeball: PokeballType; + /** The fusion species of the illusion if it's a fusion */ + fusionSpecies?: PokemonSpecies; + /** The fusionFormIndex of the illusion */ + fusionFormIndex?: number; + /** The fusionGender of the illusion if it's a fusion */ + fusionGender?: Gender; + /** The level of the illusion (not used currently) */ + level?: number; +} diff --git a/src/data/custom-pokemon-data.ts b/src/data/custom-pokemon-data.ts deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/src/data/mystery-encounters/encounters/clowning-around-encounter.ts b/src/data/mystery-encounters/encounters/clowning-around-encounter.ts index 761dd37aa4c..73364bf0dfb 100644 --- a/src/data/mystery-encounters/encounters/clowning-around-encounter.ts +++ b/src/data/mystery-encounters/encounters/clowning-around-encounter.ts @@ -45,7 +45,7 @@ import { BattlerIndex } from "#app/battle"; import { Moves } from "#enums/moves"; import { EncounterBattleAnim } from "#app/data/battle-anims"; import { MoveCategory } from "#enums/MoveCategory"; -import { CustomPokemonData } from "#app/@types/pokemon-data"; +import { CustomPokemonData } from "#app/data/pokemon/pokemon-data"; import { CLASSIC_MODE_MYSTERY_ENCOUNTER_WAVES } from "#app/constants"; import { EncounterAnim } from "#enums/encounter-anims"; import { Challenges } from "#enums/challenges"; diff --git a/src/data/mystery-encounters/encounters/slumbering-snorlax-encounter.ts b/src/data/mystery-encounters/encounters/slumbering-snorlax-encounter.ts index eb7a1e8f712..1e16e1268d4 100644 --- a/src/data/mystery-encounters/encounters/slumbering-snorlax-encounter.ts +++ b/src/data/mystery-encounters/encounters/slumbering-snorlax-encounter.ts @@ -29,7 +29,7 @@ import { MysteryEncounterOptionMode } from "#enums/mystery-encounter-option-mode import { PartyHealPhase } from "#app/phases/party-heal-phase"; import { BerryType } from "#enums/berry-type"; import { Stat } from "#enums/stat"; -import { CustomPokemonData } from "#app/@types/pokemon-data"; +import { CustomPokemonData } from "#app/data/pokemon/pokemon-data"; import { randSeedInt } from "#app/utils/common"; /** i18n namespace for the encounter */ diff --git a/src/data/mystery-encounters/encounters/the-strong-stuff-encounter.ts b/src/data/mystery-encounters/encounters/the-strong-stuff-encounter.ts index 8bb68b1b4f8..627d167f5b7 100644 --- a/src/data/mystery-encounters/encounters/the-strong-stuff-encounter.ts +++ b/src/data/mystery-encounters/encounters/the-strong-stuff-encounter.ts @@ -25,7 +25,7 @@ import { BattlerIndex } from "#app/battle"; import { BattlerTagType } from "#enums/battler-tag-type"; import { BerryType } from "#enums/berry-type"; import { MysteryEncounterTier } from "#enums/mystery-encounter-tier"; -import { CustomPokemonData } from "#app/@types/pokemon-data"; +import { CustomPokemonData } from "#app/data/pokemon/pokemon-data"; import { Stat } from "#enums/stat"; import { StatStageChangePhase } from "#app/phases/stat-stage-change-phase"; import { CLASSIC_MODE_MYSTERY_ENCOUNTER_WAVES } from "#app/constants"; diff --git a/src/data/mystery-encounters/utils/encounter-phase-utils.ts b/src/data/mystery-encounters/utils/encounter-phase-utils.ts index db176b9eb9a..a486be3014d 100644 --- a/src/data/mystery-encounters/utils/encounter-phase-utils.ts +++ b/src/data/mystery-encounters/utils/encounter-phase-utils.ts @@ -49,7 +49,7 @@ import { TrainerSlot } from "#enums/trainer-slot"; import type PokemonSpecies from "#app/data/pokemon-species"; import type { IEggOptions } from "#app/data/egg"; import { Egg } from "#app/data/egg"; -import type { CustomPokemonData } from "#app/@types/pokemon-data"; +import type { CustomPokemonData } from "#app/data/pokemon/pokemon-data"; import type HeldModifierConfig from "#app/interfaces/held-modifier-config"; import { MovePhase } from "#app/phases/move-phase"; import { EggLapsePhase } from "#app/phases/egg-lapse-phase"; diff --git a/src/data/mystery-encounters/utils/encounter-pokemon-utils.ts b/src/data/mystery-encounters/utils/encounter-pokemon-utils.ts index 7e936ae738e..99bb5c521bc 100644 --- a/src/data/mystery-encounters/utils/encounter-pokemon-utils.ts +++ b/src/data/mystery-encounters/utils/encounter-pokemon-utils.ts @@ -34,7 +34,7 @@ import { Gender } from "#app/data/gender"; import type { PermanentStat } from "#enums/stat"; import { VictoryPhase } from "#app/phases/victory-phase"; import { SummaryUiMode } from "#app/ui/summary-ui-handler"; -import { CustomPokemonData } from "#app/@types/pokemon-data"; +import { CustomPokemonData } from "#app/data/pokemon/pokemon-data"; import type { Abilities } from "#enums/abilities"; import type { PokeballType } from "#enums/pokeball"; import { StatusEffect } from "#enums/status-effect"; diff --git a/src/@types/pokemon-data.ts b/src/data/pokemon/pokemon-data.ts similarity index 84% rename from src/@types/pokemon-data.ts rename to src/data/pokemon/pokemon-data.ts index b2907112484..cd4d93f35e0 100644 --- a/src/@types/pokemon-data.ts +++ b/src/data/pokemon/pokemon-data.ts @@ -1,20 +1,17 @@ import { type BattlerTag, loadBattlerTag } from "#app/data/battler-tags"; import type { Gender } from "#app/data/gender"; -import type PokemonSpecies from "#app/data/pokemon-species"; import type { PokemonSpeciesForm } from "#app/data/pokemon-species"; import type { TypeDamageMultiplier } from "#app/data/type"; -import type { Variant } from "#app/sprites/variant"; import { isNullOrUndefined } from "#app/utils/common"; import type { Abilities } from "#enums/abilities"; import type { BerryType } from "#enums/berry-type"; import type { Moves } from "#enums/moves"; -import type { PokeballType } from "#enums/pokeball"; import type { PokemonType } from "#enums/pokemon-type"; -import type { Species } from "#enums/species"; import { PokemonMove } from "#app/field/pokemon"; import type { TurnMove } from "#app/@types/turn-move"; import type { AttackMoveResult } from "#app/@types/attack-move-result"; import type { Nature } from "#enums/nature"; +import type { IllusionData } from "#app/@types/illusion-data"; /** * Permanent data that can customize a Pokemon in non-standard ways from its Species. @@ -109,42 +106,6 @@ export class PokemonSummonData { } } -/** - * Illusion property - */ -export interface IllusionData { - basePokemon: { - /** The actual name of the Pokemon */ - name: string; - /** The actual nickname of the Pokemon */ - nickname: string; - /** Whether the base pokemon is shiny or not */ - shiny: boolean; - /** The shiny variant of the base pokemon */ - variant: Variant; - /** Whether the fusion species of the base pokemon is shiny or not */ - fusionShiny: boolean; - /** The variant of the fusion species of the base pokemon */ - fusionVariant: Variant; - }; - /** The species of the illusion */ - species: Species; - /** The formIndex of the illusion */ - formIndex: number; - /** The gender of the illusion */ - gender: Gender; - /** The pokeball of the illusion */ - pokeball: PokeballType; - /** The fusion species of the illusion if it's a fusion */ - fusionSpecies?: PokemonSpecies; - /** The fusionFormIndex of the illusion */ - fusionFormIndex?: number; - /** The fusionGender of the illusion if it's a fusion */ - fusionGender?: Gender; - /** The level of the illusion (not used currently) */ - level?: number; -} - // TODO: Merge this inside `summmonData` but exclude from save if/when a save data serializer is added export class PokemonTempSummonData { /** diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 42aa2b1a462..d310822ef2e 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -242,7 +242,7 @@ import { SwitchSummonPhase } from "#app/phases/switch-summon-phase"; import { Challenges } from "#enums/challenges"; import { PokemonAnimType } from "#enums/pokemon-anim-type"; import { PLAYER_PARTY_MAX_SIZE } from "#app/constants"; -import { CustomPokemonData } from "#app/@types/pokemon-data"; +import { CustomPokemonData } from "#app/data/pokemon/pokemon-data"; import { SwitchType } from "#enums/switch-type"; import { SpeciesFormKey } from "#enums/species-form-key"; import { getStatusEffectOverlapText } from "#app/data/status-effect"; @@ -259,7 +259,8 @@ import { MoveFlags } from "#enums/MoveFlags"; import { timedEventManager } from "#app/global-event-manager"; import { loadMoveAnimations } from "#app/sprites/pokemon-asset-loader"; import { ResetStatusPhase } from "#app/phases/reset-status-phase"; -import { PokemonBattleData, PokemonSummonData, PokemonTempSummonData, PokemonWaveData, PokemonTurnData, type IllusionData } from "../@types/pokemon-data"; +import { PokemonBattleData, PokemonSummonData, PokemonTempSummonData, PokemonWaveData, PokemonTurnData } from "../data/pokemon/pokemon-data"; +import { type IllusionData } from "#app/@types/illusion-data"; import type { TurnMove } from "../@types/turn-move"; export enum LearnMoveSituation { diff --git a/src/system/pokemon-data.ts b/src/system/pokemon-data.ts index 49f48913fae..c411c28c960 100644 --- a/src/system/pokemon-data.ts +++ b/src/system/pokemon-data.ts @@ -6,13 +6,13 @@ import { PokeballType } from "#enums/pokeball"; import { getPokemonSpecies, getPokemonSpeciesForm } from "../data/pokemon-species"; import { Status } from "../data/status-effect"; import Pokemon, { EnemyPokemon, PokemonMove } from "../field/pokemon"; -import { PokemonBattleData, PokemonSummonData } from "#app/@types/pokemon-data"; +import { PokemonBattleData, PokemonSummonData } from "#app/data/pokemon/pokemon-data"; import { TrainerSlot } from "#enums/trainer-slot"; import type { Variant } from "#app/sprites/variant"; import type { Biome } from "#enums/biome"; import type { Moves } from "#enums/moves"; import type { Species } from "#enums/species"; -import { CustomPokemonData } from "#app/@types/pokemon-data"; +import { CustomPokemonData } from "#app/data/pokemon/pokemon-data"; import type { PokemonType } from "#enums/pokemon-type"; export default class PokemonData { diff --git a/src/system/version_migration/versions/v1_0_4.ts b/src/system/version_migration/versions/v1_0_4.ts index a9732744b3a..4c85b63a67a 100644 --- a/src/system/version_migration/versions/v1_0_4.ts +++ b/src/system/version_migration/versions/v1_0_4.ts @@ -2,7 +2,7 @@ import { SettingKeys } from "#app/system/settings/settings"; import type { SystemSaveData, SessionSaveData } from "#app/system/game-data"; import { AbilityAttr, defaultStarterSpecies, DexAttr } from "#app/system/game-data"; import { allSpecies } from "#app/data/pokemon-species"; -import { CustomPokemonData } from "#app/@types/pokemon-data"; +import { CustomPokemonData } from "#app/data/pokemon/pokemon-data"; import { isNullOrUndefined } from "#app/utils/common"; import type { SystemSaveMigrator } from "#app/@types/SystemSaveMigrator"; import type { SettingsSaveMigrator } from "#app/@types/SettingsSaveMigrator"; diff --git a/test/battlerTags/stockpiling.test.ts b/test/battlerTags/stockpiling.test.ts index a42250b8f6f..13ff7b15145 100644 --- a/test/battlerTags/stockpiling.test.ts +++ b/test/battlerTags/stockpiling.test.ts @@ -1,6 +1,6 @@ import { StockpilingTag } from "#app/data/battler-tags"; import type Pokemon from "#app/field/pokemon"; -import { PokemonSummonData } from "#app/@types/pokemon-data"; +import { PokemonSummonData } from "#app/data/pokemon/pokemon-data"; import * as messages from "#app/messages"; import { StatStageChangePhase } from "#app/phases/stat-stage-change-phase"; import { Stat } from "#enums/stat"; diff --git a/test/battlerTags/substitute.test.ts b/test/battlerTags/substitute.test.ts index 472a651cbe0..57c0b64acc2 100644 --- a/test/battlerTags/substitute.test.ts +++ b/test/battlerTags/substitute.test.ts @@ -1,6 +1,6 @@ import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; import type { TurnMove } from "#app/@types/turn-move"; -import type { PokemonTurnData } from "#app/@types/pokemon-data"; +import type { PokemonTurnData } from "#app/data/pokemon/pokemon-data"; import type Pokemon from "#app/field/pokemon"; import { MoveResult } from "#app/field/pokemon"; import type BattleScene from "#app/battle-scene"; diff --git a/test/field/pokemon.test.ts b/test/field/pokemon.test.ts index 3eade9f1498..8cb58f0f8de 100644 --- a/test/field/pokemon.test.ts +++ b/test/field/pokemon.test.ts @@ -5,7 +5,7 @@ import { PokeballType } from "#enums/pokeball"; import type BattleScene from "#app/battle-scene"; import { Moves } from "#app/enums/moves"; import { PokemonType } from "#enums/pokemon-type"; -import { CustomPokemonData } from "#app/@types/pokemon-data"; +import { CustomPokemonData } from "#app/data/pokemon/pokemon-data"; describe("Spec - Pokemon", () => { let phaserGame: Phaser.Game; diff --git a/test/mystery-encounter/encounters/the-strong-stuff-encounter.test.ts b/test/mystery-encounter/encounters/the-strong-stuff-encounter.test.ts index 621da5dca8a..bb34fb131a8 100644 --- a/test/mystery-encounter/encounters/the-strong-stuff-encounter.test.ts +++ b/test/mystery-encounter/encounters/the-strong-stuff-encounter.test.ts @@ -24,7 +24,7 @@ import { BerryModifier, PokemonBaseStatTotalModifier } from "#app/modifier/modif import { MysteryEncounterOptionMode } from "#enums/mystery-encounter-option-mode"; import { MysteryEncounterTier } from "#enums/mystery-encounter-tier"; import { initSceneWithoutEncounterPhase } from "#test/testUtils/gameManagerUtils"; -import { CustomPokemonData } from "#app/@types/pokemon-data"; +import { CustomPokemonData } from "#app/data/pokemon/pokemon-data"; import { CommandPhase } from "#app/phases/command-phase"; import { MovePhase } from "#app/phases/move-phase"; import { SelectModifierPhase } from "#app/phases/select-modifier-phase"; From d5ea58b4bb5d315f811bd7929ecf940e19d5eac9 Mon Sep 17 00:00:00 2001 From: Bertie690 Date: Mon, 16 Jun 2025 12:25:18 -0400 Subject: [PATCH 5/7] Moved `DamageResult` into new file --- src/@types/attack-move-result.ts | 2 +- src/@types/damage-result.ts | 21 +++++++++++++++++++++ src/field/damage-number-handler.ts | 2 +- src/field/pokemon.ts | 29 +++++++++-------------------- src/phases/damage-anim-phase.ts | 2 +- src/phases/move-effect-phase.ts | 2 +- src/system/pokemon-data.ts | 2 +- test/moves/steamroller.test.ts | 2 +- 8 files changed, 36 insertions(+), 26 deletions(-) create mode 100644 src/@types/damage-result.ts diff --git a/src/@types/attack-move-result.ts b/src/@types/attack-move-result.ts index ec79e761499..c6aedf8096d 100644 --- a/src/@types/attack-move-result.ts +++ b/src/@types/attack-move-result.ts @@ -1,5 +1,5 @@ import type { BattlerIndex } from "#enums/battler-index"; -import type { DamageResult } from "#app/field/pokemon"; +import type { DamageResult } from "#app/@types/damage-result"; import type { MoveId } from "#enums/move-id"; export interface AttackMoveResult { diff --git a/src/@types/damage-result.ts b/src/@types/damage-result.ts new file mode 100644 index 00000000000..b6eb6b82770 --- /dev/null +++ b/src/@types/damage-result.ts @@ -0,0 +1,21 @@ +import type { HitResult } from "#enums/hit-result"; + +/** Union type containing all damage-dealing {@linkcode HitResult}s. */ +export type DamageResult = + | HitResult.EFFECTIVE + | HitResult.SUPER_EFFECTIVE + | HitResult.NOT_VERY_EFFECTIVE + | HitResult.ONE_HIT_KO + | HitResult.CONFUSION + | HitResult.INDIRECT_KO + | HitResult.INDIRECT; + +/** Interface containing the results of a damage calculation for a given move. */ +export interface DamageCalculationResult { + /** `true` if the move was cancelled (thus suppressing "No Effect" messages) */ + cancelled: boolean; + /** The effectiveness of the move */ + result: HitResult; + /** The damage dealt by the move */ + damage: number; +} diff --git a/src/field/damage-number-handler.ts b/src/field/damage-number-handler.ts index b8b3ed76e18..24c5e107d15 100644 --- a/src/field/damage-number-handler.ts +++ b/src/field/damage-number-handler.ts @@ -1,5 +1,5 @@ import { TextStyle, addTextObject } from "../ui/text"; -import type { DamageResult } from "./pokemon"; +import type { DamageResult } from "../@types/damage-result"; import type Pokemon from "./pokemon"; import { HitResult } from "#enums/hit-result"; import { formatStat, fixedInt } from "#app/utils/common"; diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index e2d41427925..794cca5e6ac 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -169,7 +169,14 @@ import { getPokemonNameWithAffix } from "#app/messages"; import { Challenges } from "#enums/challenges"; import { PokemonAnimType } from "#enums/pokemon-anim-type"; import { PLAYER_PARTY_MAX_SIZE } from "#app/constants"; -import { CustomPokemonData, PokemonBattleData, PokemonSummonData, PokemonTempSummonData, PokemonTurnData, PokemonWaveData } from "#app/data/pokemon/pokemon-data"; +import { + CustomPokemonData, + PokemonBattleData, + PokemonSummonData, + PokemonTempSummonData, + PokemonTurnData, + PokemonWaveData, +} from "#app/data/pokemon/pokemon-data"; import { SwitchType } from "#enums/switch-type"; import { SpeciesFormKey } from "#enums/species-form-key"; import { getStatusEffectOverlapText } from "#app/data/status-effect"; @@ -193,6 +200,7 @@ import { PokemonMove } from "#app/data/moves/pokemon-move"; import type { AbAttrMap, AbAttrString } from "#app/@types/ability-types"; import type { IllusionData } from "#app/@types/illusion-data"; import type { TurnMove } from "#app/@types/turn-move"; +import type { DamageCalculationResult, DamageResult } from "#app/@types/damage-result"; /** Base typeclass for damage parameter methods, used for DRY */ type damageParams = { @@ -6690,22 +6698,3 @@ export class EnemyPokemon extends Pokemon { this.battleInfo.toggleFlyout(visible); } } - -export type DamageResult = - | HitResult.EFFECTIVE - | HitResult.SUPER_EFFECTIVE - | HitResult.NOT_VERY_EFFECTIVE - | HitResult.ONE_HIT_KO - | HitResult.CONFUSION - | HitResult.INDIRECT_KO - | HitResult.INDIRECT; - -/** Interface containing the results of a damage calculation for a given move */ -export interface DamageCalculationResult { - /** `true` if the move was cancelled (thus suppressing "No Effect" messages) */ - cancelled: boolean; - /** The effectiveness of the move */ - result: HitResult; - /** The damage dealt by the move */ - damage: number; -} diff --git a/src/phases/damage-anim-phase.ts b/src/phases/damage-anim-phase.ts index aa5a0a6c3e6..8dc377cdaf5 100644 --- a/src/phases/damage-anim-phase.ts +++ b/src/phases/damage-anim-phase.ts @@ -1,7 +1,7 @@ import { globalScene } from "#app/global-scene"; import type { BattlerIndex } from "#enums/battler-index"; import { BattleSpec } from "#enums/battle-spec"; -import type { DamageResult } from "#app/field/pokemon"; +import type { DamageResult } from "#app/@types/damage-result"; import { HitResult } from "#enums/hit-result"; import { fixedInt } from "#app/utils/common"; import { PokemonPhase } from "#app/phases/pokemon-phase"; diff --git a/src/phases/move-effect-phase.ts b/src/phases/move-effect-phase.ts index dc3e222da24..c9852016b17 100644 --- a/src/phases/move-effect-phase.ts +++ b/src/phases/move-effect-phase.ts @@ -27,7 +27,7 @@ import { MoveTarget } from "#enums/MoveTarget"; import { MoveCategory } from "#enums/MoveCategory"; import { SpeciesFormChangePostMoveTrigger } from "#app/data/pokemon-forms/form-change-triggers"; import { PokemonType } from "#enums/pokemon-type"; -import type { DamageResult } from "#app/field/pokemon"; +import type { DamageResult } from "#app/@types/damage-result"; import type { TurnMove } from "#app/@types/turn-move"; import { PokemonMove } from "#app/data/moves/pokemon-move"; import type Pokemon from "#app/field/pokemon"; diff --git a/src/system/pokemon-data.ts b/src/system/pokemon-data.ts index aabdee768d7..d1efedd86c3 100644 --- a/src/system/pokemon-data.ts +++ b/src/system/pokemon-data.ts @@ -12,7 +12,7 @@ import type { Variant } from "#app/sprites/variant"; import type { BiomeId } from "#enums/biome-id"; import type { MoveId } from "#enums/move-id"; import type { SpeciesId } from "#enums/species-id"; -import { CustomPokemonData, PokemonBattleData, PokemonSummonData} from "#app/data/pokemon/pokemon-data"; +import { CustomPokemonData, PokemonBattleData, PokemonSummonData } from "#app/data/pokemon/pokemon-data"; import type { PokemonType } from "#enums/pokemon-type"; export default class PokemonData { diff --git a/test/moves/steamroller.test.ts b/test/moves/steamroller.test.ts index 4eb011c47f5..67c63ff32e4 100644 --- a/test/moves/steamroller.test.ts +++ b/test/moves/steamroller.test.ts @@ -1,7 +1,7 @@ import { BattlerIndex } from "#enums/battler-index"; import { allMoves } from "#app/data/data-lists"; import { BattlerTagType } from "#app/enums/battler-tag-type"; -import type { DamageCalculationResult } from "#app/field/pokemon"; +import type { DamageCalculationResult } from "#app/@types/damage-result"; import { AbilityId } from "#enums/ability-id"; import { MoveId } from "#enums/move-id"; import { SpeciesId } from "#enums/species-id"; From 8fb07e25033fe687ae3100834d7e4fde7a1a93bc Mon Sep 17 00:00:00 2001 From: Bertie690 Date: Mon, 16 Jun 2025 12:50:53 -0400 Subject: [PATCH 6/7] Fixed imports --- src/system/version_migration/versions/v1_10_0.ts | 2 +- src/ui/party-ui-handler.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/system/version_migration/versions/v1_10_0.ts b/src/system/version_migration/versions/v1_10_0.ts index 4d1dedf701e..6ed3253a0c9 100644 --- a/src/system/version_migration/versions/v1_10_0.ts +++ b/src/system/version_migration/versions/v1_10_0.ts @@ -1,6 +1,6 @@ import type { SessionSaveMigrator } from "#app/@types/SessionSaveMigrator"; import type { BattlerIndex } from "#enums/battler-index"; -import type { TurnMove } from "#app/field/pokemon"; +import type { TurnMove } from "#app/@types/turn-move"; import type { MoveResult } from "#enums/move-result"; import type { SessionSaveData } from "#app/system/game-data"; import { MoveUseMode } from "#enums/move-use-mode"; diff --git a/src/ui/party-ui-handler.ts b/src/ui/party-ui-handler.ts index cf6333f4580..60e9e846859 100644 --- a/src/ui/party-ui-handler.ts +++ b/src/ui/party-ui-handler.ts @@ -1,4 +1,5 @@ -import type { PlayerPokemon, TurnMove } from "#app/field/pokemon"; +import type { PlayerPokemon } from "#app/field/pokemon"; +import type { TurnMove } from "#app/@types/turn-move"; import type { PokemonMove } from "#app/data/moves/pokemon-move"; import type Pokemon from "#app/field/pokemon"; import { MoveResult } from "#enums/move-result"; From efffc3c93abc9081bd045f7fd5c059eb582f4fa7 Mon Sep 17 00:00:00 2001 From: Bertie690 Date: Mon, 16 Jun 2025 12:53:03 -0400 Subject: [PATCH 7/7] ran biome --- src/data/pokemon/pokemon-data.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/data/pokemon/pokemon-data.ts b/src/data/pokemon/pokemon-data.ts index 483f9eadace..db60b4ce1b4 100644 --- a/src/data/pokemon/pokemon-data.ts +++ b/src/data/pokemon/pokemon-data.ts @@ -205,4 +205,4 @@ export class PokemonTurnData { * @see {@linkcode PokemonSummonData.berriesEatenLast} */ public berriesEaten: BerryType[] = []; -} \ No newline at end of file +}