mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-12-24 02:29:25 +01:00
* Rename `Abilities` to `AbilityId` * Rename `abilities.ts` to `ability-id.ts` * Rename `Moves` to `MoveId` * Rename `moves.ts` to `move-id.ts` * Rename `Species` to `SpeciesId` * Rename `species.ts` to `species-id.ts` * Rename `Biome` to `BiomeId` * Rename `biome.ts` to `biome-id.ts` * Replace `Abilities` with `AbilityId` in comments * Replace `Biome` with `BiomeId` in comments * Replace `Moves` with `MoveId` in comments * Replace `Species` with `SpeciesId` in comments
94 lines
3.2 KiB
TypeScript
94 lines
3.2 KiB
TypeScript
import type { MoveId } from "#enums/move-id";
|
|
import type { PlayerPokemon } from "#app/field/pokemon";
|
|
import { PokemonMove } from "#app/field/pokemon";
|
|
import { isNullOrUndefined } from "#app/utils/common";
|
|
import { EncounterPokemonRequirement } from "#app/data/mystery-encounters/mystery-encounter-requirements";
|
|
import { globalScene } from "#app/global-scene";
|
|
|
|
/**
|
|
* {@linkcode CanLearnMoveRequirement} options
|
|
*/
|
|
export interface CanLearnMoveRequirementOptions {
|
|
excludeLevelMoves?: boolean;
|
|
excludeTmMoves?: boolean;
|
|
excludeEggMoves?: boolean;
|
|
includeFainted?: boolean;
|
|
minNumberOfPokemon?: number;
|
|
invertQuery?: boolean;
|
|
}
|
|
|
|
/**
|
|
* Requires that a pokemon can learn a specific move/moveset.
|
|
*/
|
|
export class CanLearnMoveRequirement extends EncounterPokemonRequirement {
|
|
private readonly requiredMoves: MoveId[];
|
|
private readonly excludeLevelMoves?: boolean;
|
|
private readonly excludeTmMoves?: boolean;
|
|
private readonly excludeEggMoves?: boolean;
|
|
private readonly includeFainted?: boolean;
|
|
|
|
constructor(requiredMoves: MoveId | MoveId[], options: CanLearnMoveRequirementOptions = {}) {
|
|
super();
|
|
this.requiredMoves = Array.isArray(requiredMoves) ? requiredMoves : [requiredMoves];
|
|
|
|
this.excludeLevelMoves = options.excludeLevelMoves ?? false;
|
|
this.excludeTmMoves = options.excludeTmMoves ?? false;
|
|
this.excludeEggMoves = options.excludeEggMoves ?? false;
|
|
this.includeFainted = options.includeFainted ?? false;
|
|
this.minNumberOfPokemon = options.minNumberOfPokemon ?? 1;
|
|
this.invertQuery = options.invertQuery ?? false;
|
|
}
|
|
|
|
override meetsRequirement(): boolean {
|
|
const partyPokemon = globalScene
|
|
.getPlayerParty()
|
|
.filter(pkm => (this.includeFainted ? pkm.isAllowedInChallenge() : pkm.isAllowedInBattle()));
|
|
|
|
if (isNullOrUndefined(partyPokemon) || this.requiredMoves?.length < 0) {
|
|
return false;
|
|
}
|
|
|
|
return this.queryParty(partyPokemon).length >= this.minNumberOfPokemon;
|
|
}
|
|
|
|
override queryParty(partyPokemon: PlayerPokemon[]): PlayerPokemon[] {
|
|
if (!this.invertQuery) {
|
|
return partyPokemon.filter(pokemon =>
|
|
// every required move should be included
|
|
this.requiredMoves.every(requiredMove => this.getAllPokemonMoves(pokemon).includes(requiredMove)),
|
|
);
|
|
}
|
|
return partyPokemon.filter(
|
|
pokemon =>
|
|
// none of the "required" moves should be included
|
|
!this.requiredMoves.some(requiredMove => this.getAllPokemonMoves(pokemon).includes(requiredMove)),
|
|
);
|
|
}
|
|
|
|
override getDialogueToken(__pokemon?: PlayerPokemon): [string, string] {
|
|
return ["requiredMoves", this.requiredMoves.map(m => new PokemonMove(m).getName()).join(", ")];
|
|
}
|
|
|
|
private getPokemonLevelMoves(pkm: PlayerPokemon): MoveId[] {
|
|
return pkm.getLevelMoves().map(([_level, move]) => move);
|
|
}
|
|
|
|
private getAllPokemonMoves(pkm: PlayerPokemon): MoveId[] {
|
|
const allPokemonMoves: MoveId[] = [];
|
|
|
|
if (!this.excludeLevelMoves) {
|
|
allPokemonMoves.push(...(this.getPokemonLevelMoves(pkm) ?? []));
|
|
}
|
|
|
|
if (!this.excludeTmMoves) {
|
|
allPokemonMoves.push(...(pkm.compatibleTms ?? []));
|
|
}
|
|
|
|
if (!this.excludeEggMoves) {
|
|
allPokemonMoves.push(...(pkm.getEggMoves() ?? []));
|
|
}
|
|
|
|
return allPokemonMoves;
|
|
}
|
|
}
|