diff --git a/src/data/abilities/ability-class.ts b/src/data/abilities/ability-class.ts index 7759dd959af..b4cda2482d4 100644 --- a/src/data/abilities/ability-class.ts +++ b/src/data/abilities/ability-class.ts @@ -2,6 +2,8 @@ import { Abilities } from "#enums/abilities"; import type { AbAttrCondition } from "#app/@types/ability-types"; import type { AbAttr } from "#app/data/abilities/ab-attrs/ab-attr"; import i18next from "i18next"; +import type { Localizable } from "#app/interfaces/locales"; +import type { Constructor } from "#app/utils"; export class Ability implements Localizable { public id: Abilities; diff --git a/src/data/abilities/ability.ts b/src/data/abilities/ability.ts index b05676b1a36..4b26beb89f8 100644 --- a/src/data/abilities/ability.ts +++ b/src/data/abilities/ability.ts @@ -1,29 +1,28 @@ import type { EnemyPokemon, PokemonMove } from "../../field/pokemon"; -import type Pokemon from "../../field/pokemon"; +import type Pokemon from "#app/field/pokemon"; import { HitResult, MoveResult, PlayerPokemon } from "../../field/pokemon"; import { PokemonType } from "#enums/pokemon-type"; import { BooleanHolder, NumberHolder, toDmgValue, isNullOrUndefined, randSeedItem, randSeedInt, type Constructor } from "#app/utils"; import { getPokemonNameWithAffix } from "../../messages"; import type { Weather } from "#app/data/weather"; -import type { BattlerTag } from "../battler-tags"; -import { BattlerTagLapseType, GroundedTag } from "../battler-tags"; +import type { BattlerTag } from "#app/data/battler-tags"; +import { BattlerTagLapseType, GroundedTag } from "#app/data/battler-tags"; import { getNonVolatileStatusEffects, getStatusEffectDescriptor, getStatusEffectHealText } from "#app/data/status-effect"; -import { Gender } from "../gender"; -import type Move from "../moves/move"; +import { Gender } from "#app/data/gender"; +import type Move from "#app/data/moves/move"; import { AttackMove, FlinchAttr, OneHitKOAttr, HitHealAttr, allMoves, StatusMove, SelfStatusMove, VariablePowerAttr, applyMoveAttrs, VariableMoveTypeAttr, RandomMovesetMoveAttr, RandomMoveAttr, NaturePowerAttr, CopyMoveAttr, NeutralDamageAgainstFlyingTypeMultiplierAttr, FixedDamageAttr } from "../moves/move"; import { MoveFlags } from "#enums/MoveFlags"; import { MoveTarget } from "#enums/MoveTarget"; import { MoveCategory } from "#enums/MoveCategory"; import type { ArenaTrapTag, SuppressAbilitiesTag } from "../arena-tag"; -import { ArenaTagSide } from "../arena-tag"; +import { ArenaTagSide } from "#app/data/arena-tag"; import { BerryModifier, HitHealModifier, PokemonHeldItemModifier } from "../../modifier/modifier"; -import { TerrainType } from "../terrain"; +import { TerrainType } from "#app/data/terrain"; import { SpeciesFormChangeAbilityTrigger, SpeciesFormChangeRevertWeatherFormTrigger, SpeciesFormChangeWeatherTrigger } from "../pokemon-forms"; import i18next from "i18next"; -import type { Localizable } from "#app/interfaces/locales"; -import { Command } from "../../ui/command-ui-handler"; +import { Command } from "#app/ui/command-ui-handler"; import { BerryModifierType } from "#app/modifier/modifier-type"; -import { getPokeballName } from "../pokeball"; +import { getPokeballName } from "#app/data/pokeball"; import type { BattlerIndex } from "#app/battle"; import { BattleType } from "#app/battle"; import { Abilities } from "#enums/abilities"; @@ -46,179 +45,13 @@ import { PokemonAnimType } from "#enums/pokemon-anim-type"; import { StatusEffect } from "#enums/status-effect"; import { WeatherType } from "#enums/weather-type"; import { PokemonTransformPhase } from "#app/phases/pokemon-transform-phase"; -import { allAbilities } from "../data-lists"; +import { allAbilities } from "#app/data/data-lists"; import type { AbAttrCondition, PokemonDefendCondition, PokemonStatStageChangeCondition, PokemonAttackCondition, AbAttrApplyFunc, AbAttrSuccessFunc } from "#app/@types/ability-types"; import { AbAttr } from "./ab-attrs/ab-attr"; import {Ability} from "./ability-class"; // Type imports - -<<<<<<< HEAD - constructor(id: Abilities, generation: number) { - this.id = id; - - this.nameAppend = ""; - this.generation = generation; - this.attrs = []; - this.conditions = []; - - this.isSuppressable = true; - this.isCopiable = true; - this.isReplaceable = true; - - this.localize(); - } - - public get isSwappable(): boolean { - return this.isCopiable && this.isReplaceable; - } - localize(): void { - const i18nKey = Abilities[this.id].split("_").filter(f => f).map((f, i) => i ? `${f[0]}${f.slice(1).toLowerCase()}` : f.toLowerCase()).join("") as string; - - this.name = this.id ? `${i18next.t(`ability:${i18nKey}.name`) as string}${this.nameAppend}` : ""; - this.description = this.id ? i18next.t(`ability:${i18nKey}.description`) as string : ""; - } - - /** - * Get all ability attributes that match `attrType` - * @param attrType any attribute that extends {@linkcode AbAttr} - * @returns Array of attributes that match `attrType`, Empty Array if none match. - */ - getAttrs(attrType: Constructor ): T[] { - return this.attrs.filter((a): a is T => a instanceof attrType); - } - - /** - * Check if an ability has an attribute that matches `attrType` - * @param attrType any attribute that extends {@linkcode AbAttr} - * @returns true if the ability has attribute `attrType` - */ - hasAttr(attrType: Constructor): boolean { - return this.attrs.some((attr) => attr instanceof attrType); - } - - attr>(AttrType: T, ...args: ConstructorParameters): Ability { - const attr = new AttrType(...args); - this.attrs.push(attr); - - return this; - } - - conditionalAttr>(condition: AbAttrCondition, AttrType: T, ...args: ConstructorParameters): Ability { - const attr = new AttrType(...args); - attr.addCondition(condition); - this.attrs.push(attr); - - return this; - } - - bypassFaint(): Ability { - this.isBypassFaint = true; - return this; - } - - ignorable(): Ability { - this.isIgnorable = true; - return this; - } - - unsuppressable(): Ability { - this.isSuppressable = false; - return this; - } - - uncopiable(): Ability { - this.isCopiable = false; - return this; - } - - unreplaceable(): Ability { - this.isReplaceable = false; - return this; - } - - condition(condition: AbAttrCondition): Ability { - this.conditions.push(condition); - - return this; - } - - partial(): this { - this.nameAppend += " (P)"; - return this; - } - - unimplemented(): this { - this.nameAppend += " (N)"; - return this; - } - - /** - * Internal flag used for developers to document edge cases. When using this, please be sure to document the edge case. - * @returns the ability - */ - edgeCase(): this { - return this; - } -} - -type AbAttrApplyFunc = (attr: TAttr, passive: boolean) => void; -type AbAttrSuccessFunc = (attr: TAttr, passive: boolean) => boolean; -type AbAttrCondition = (pokemon: Pokemon) => boolean; - -// TODO: Can this be improved? -type PokemonAttackCondition = (user: Pokemon | null, target: Pokemon | null, move: Move) => boolean; -type PokemonDefendCondition = (target: Pokemon, user: Pokemon, move: Move) => boolean; -type PokemonStatStageChangeCondition = (target: Pokemon, statsChanged: BattleStat[], stages: number) => boolean; - -export abstract class AbAttr { - public showAbility: boolean; - private extraCondition: AbAttrCondition; - - constructor(showAbility = true) { - this.showAbility = showAbility; - } - - /** - * Applies ability effects without checking conditions - * @param pokemon - The pokemon to apply this ability to - * @param passive - Whether or not the ability is a passive - * @param simulated - Whether the call is simulated - * @param args - Extra args passed to the function. Handled by child classes. - * @see {@linkcode canApply} - */ - apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: BooleanHolder | null, args: any[]): void {} - - getTriggerMessage(_pokemon: Pokemon, _abilityName: string, ..._args: any[]): string | null { - return null; - } - - getCondition(): AbAttrCondition | null { - return this.extraCondition || null; - } - - addCondition(condition: AbAttrCondition): AbAttr { - this.extraCondition = condition; - return this; - } - - /** - * Returns a boolean describing whether the ability can be applied under current conditions - * @param pokemon - The pokemon to apply this ability to - * @param passive - Whether or not the ability is a passive - * @param simulated - Whether the call is simulated - * @param args - Extra args passed to the function. Handled by child classes. - * @returns `true` if the ability can be applied, `false` otherwise - * @see {@linkcode apply} - */ - canApply(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean { - return true; - } -} -======= ->>>>>>> 6ba1a7036 (Extract types out of ability.ts) - export class BlockRecoilDamageAttr extends AbAttr { constructor() { super(false); diff --git a/src/data/data-lists.ts b/src/data/data-lists.ts index 8b8cd97293e..d3c31abc851 100644 --- a/src/data/data-lists.ts +++ b/src/data/data-lists.ts @@ -1,3 +1,3 @@ -import type { Ability } from "./abilities/ability"; +import type { Ability } from "./abilities/ability-class"; export const allAbilities: Ability[] = [];