mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-07-01 05:52:17 +02:00
Refactor evo conditions and descriptions
This commit is contained in:
parent
eef8367caf
commit
8e61d20384
File diff suppressed because it is too large
Load Diff
@ -838,72 +838,6 @@ export class CanFormChangeWithItemRequirement extends EncounterPokemonRequiremen
|
||||
}
|
||||
}
|
||||
|
||||
export class CanEvolveWithItemRequirement extends EncounterPokemonRequirement {
|
||||
requiredEvolutionItem: EvolutionItem[];
|
||||
minNumberOfPokemon: number;
|
||||
invertQuery: boolean;
|
||||
|
||||
constructor(evolutionItems: EvolutionItem | EvolutionItem[], minNumberOfPokemon = 1, invertQuery = false) {
|
||||
super();
|
||||
this.minNumberOfPokemon = minNumberOfPokemon;
|
||||
this.invertQuery = invertQuery;
|
||||
this.requiredEvolutionItem = Array.isArray(evolutionItems) ? evolutionItems : [evolutionItems];
|
||||
}
|
||||
|
||||
override meetsRequirement(): boolean {
|
||||
const partyPokemon = globalScene.getPlayerParty();
|
||||
if (isNullOrUndefined(partyPokemon) || this.requiredEvolutionItem?.length < 0) {
|
||||
return false;
|
||||
}
|
||||
return this.queryParty(partyPokemon).length >= this.minNumberOfPokemon;
|
||||
}
|
||||
|
||||
filterByEvo(pokemon, evolutionItem) {
|
||||
if (
|
||||
pokemonEvolutions.hasOwnProperty(pokemon.species.speciesId) &&
|
||||
pokemonEvolutions[pokemon.species.speciesId].filter(
|
||||
e => e.item === evolutionItem && (!e.condition || e.condition.predicate(pokemon)),
|
||||
).length &&
|
||||
pokemon.getFormKey() !== SpeciesFormKey.GIGANTAMAX
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
if (
|
||||
pokemon.isFusion() &&
|
||||
pokemonEvolutions.hasOwnProperty(pokemon.fusionSpecies.speciesId) &&
|
||||
pokemonEvolutions[pokemon.fusionSpecies.speciesId].filter(
|
||||
e => e.item === evolutionItem && (!e.condition || e.condition.predicate(pokemon)),
|
||||
).length &&
|
||||
pokemon.getFusionFormKey() !== SpeciesFormKey.GIGANTAMAX
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
override queryParty(partyPokemon: PlayerPokemon[]): PlayerPokemon[] {
|
||||
if (!this.invertQuery) {
|
||||
return partyPokemon.filter(
|
||||
pokemon =>
|
||||
this.requiredEvolutionItem.filter(evolutionItem => this.filterByEvo(pokemon, evolutionItem)).length > 0,
|
||||
);
|
||||
}
|
||||
// for an inverted query, we only want to get the pokemon that don't have ANY of the listed evolutionItemss
|
||||
return partyPokemon.filter(
|
||||
pokemon =>
|
||||
this.requiredEvolutionItem.filter(evolutionItems => this.filterByEvo(pokemon, evolutionItems)).length === 0,
|
||||
);
|
||||
}
|
||||
|
||||
override getDialogueToken(pokemon?: PlayerPokemon): [string, string] {
|
||||
const requiredItems = this.requiredEvolutionItem.filter(evoItem => this.filterByEvo(pokemon, evoItem));
|
||||
if (requiredItems.length > 0) {
|
||||
return ["evolutionItem", EvolutionItem[requiredItems[0]]];
|
||||
}
|
||||
return ["evolutionItem", ""];
|
||||
}
|
||||
}
|
||||
|
||||
export class HeldItemRequirement extends EncounterPokemonRequirement {
|
||||
requiredHeldItemModifiers: string[];
|
||||
minNumberOfPokemon: number;
|
||||
|
@ -97,7 +97,6 @@ import { Gender } from "#app/data/gender";
|
||||
import { Status, getRandomStatus } from "#app/data/status-effect";
|
||||
import type {
|
||||
SpeciesFormEvolution,
|
||||
SpeciesEvolutionCondition,
|
||||
} from "#app/data/balance/pokemon-evolutions";
|
||||
import {
|
||||
pokemonEvolutions,
|
||||
@ -2874,18 +2873,8 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
|
||||
if (pokemonEvolutions.hasOwnProperty(this.species.speciesId)) {
|
||||
const evolutions = pokemonEvolutions[this.species.speciesId];
|
||||
for (const e of evolutions) {
|
||||
if (
|
||||
!e.item &&
|
||||
this.level >= e.level &&
|
||||
(isNullOrUndefined(e.preFormKey) ||
|
||||
this.getFormKey() === e.preFormKey)
|
||||
) {
|
||||
if (
|
||||
e.condition === null ||
|
||||
(e.condition as SpeciesEvolutionCondition).predicate(this)
|
||||
) {
|
||||
return e;
|
||||
}
|
||||
if (e.validate(this)) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2899,18 +2888,8 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
|
||||
this.fusionSpecies.speciesId
|
||||
].map(e => new FusionSpeciesFormEvolution(this.species.speciesId, e));
|
||||
for (const fe of fusionEvolutions) {
|
||||
if (
|
||||
!fe.item &&
|
||||
this.level >= fe.level &&
|
||||
(isNullOrUndefined(fe.preFormKey) ||
|
||||
this.getFusionFormKey() === fe.preFormKey)
|
||||
) {
|
||||
if (
|
||||
fe.condition === null ||
|
||||
(fe.condition as SpeciesEvolutionCondition).predicate(this)
|
||||
) {
|
||||
return fe;
|
||||
}
|
||||
if (fe.validate(this)) {
|
||||
return fe;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -6843,7 +6822,7 @@ export class PlayerPokemon extends Pokemon {
|
||||
) {
|
||||
const newEvolution = pokemonEvolutions[evoSpecies.speciesId][1];
|
||||
|
||||
if (newEvolution.condition?.predicate(this)) {
|
||||
if (newEvolution.validate(this, evoSpecies.speciesId === this.species.speciesId)) {
|
||||
const newPokemon = globalScene.addPlayerPokemon(
|
||||
this.species,
|
||||
this.level,
|
||||
@ -7144,9 +7123,6 @@ export class EnemyPokemon extends Pokemon {
|
||||
pe.speciesId === speciesId &&
|
||||
(!pe.evoFormKey || pe.evoFormKey === this.getFormKey()),
|
||||
);
|
||||
if (evolution?.condition?.enforceFunc) {
|
||||
evolution.condition.enforceFunc(this);
|
||||
}
|
||||
speciesId = prevolution;
|
||||
}
|
||||
}
|
||||
|
@ -1214,9 +1214,7 @@ export class EvolutionItemModifierType extends PokemonModifierType implements Ge
|
||||
pokemonEvolutions.hasOwnProperty(pokemon.species.speciesId) &&
|
||||
pokemonEvolutions[pokemon.species.speciesId].filter(
|
||||
e =>
|
||||
e.item === this.evolutionItem &&
|
||||
(!e.condition || e.condition.predicate(pokemon)) &&
|
||||
(e.preFormKey === null || e.preFormKey === pokemon.getFormKey()),
|
||||
e.validate(pokemon, false, this.evolutionItem),
|
||||
).length &&
|
||||
pokemon.getFormKey() !== SpeciesFormKey.GIGANTAMAX
|
||||
) {
|
||||
@ -1228,9 +1226,7 @@ export class EvolutionItemModifierType extends PokemonModifierType implements Ge
|
||||
pokemonEvolutions.hasOwnProperty(pokemon.fusionSpecies.speciesId) &&
|
||||
pokemonEvolutions[pokemon.fusionSpecies.speciesId].filter(
|
||||
e =>
|
||||
e.item === this.evolutionItem &&
|
||||
(!e.condition || e.condition.predicate(pokemon)) &&
|
||||
(e.preFormKey === null || e.preFormKey === pokemon.getFusionFormKey()),
|
||||
e.validate(pokemon, true, this.evolutionItem),
|
||||
).length &&
|
||||
pokemon.getFusionFormKey() !== SpeciesFormKey.GIGANTAMAX
|
||||
) {
|
||||
@ -1566,9 +1562,7 @@ class EvolutionItemModifierTypeGenerator extends ModifierTypeGenerator {
|
||||
const evolutions = pokemonEvolutions[p.species.speciesId];
|
||||
return evolutions.filter(
|
||||
e =>
|
||||
e.item !== EvolutionItem.NONE &&
|
||||
(e.evoFormKey === null || (e.preFormKey || "") === p.getFormKey()) &&
|
||||
(!e.condition || e.condition.predicate(p)),
|
||||
e.isValidItemEvolution(p),
|
||||
);
|
||||
}),
|
||||
party
|
||||
@ -1585,14 +1579,12 @@ class EvolutionItemModifierTypeGenerator extends ModifierTypeGenerator {
|
||||
const evolutions = pokemonEvolutions[p.fusionSpecies!.speciesId];
|
||||
return evolutions.filter(
|
||||
e =>
|
||||
e.item !== EvolutionItem.NONE &&
|
||||
(e.evoFormKey === null || (e.preFormKey || "") === p.getFusionFormKey()) &&
|
||||
(!e.condition || e.condition.predicate(p)),
|
||||
e.validate(p, true),
|
||||
);
|
||||
}),
|
||||
]
|
||||
.flat()
|
||||
.flatMap(e => e.item)
|
||||
.flatMap(e => e.evoItem)
|
||||
.filter(i => (!!i && i > 50) === rare);
|
||||
|
||||
if (!evolutionItemPool.length) {
|
||||
|
@ -2378,18 +2378,14 @@ export class EvolutionItemModifier extends ConsumablePokemonModifier {
|
||||
let matchingEvolution = pokemonEvolutions.hasOwnProperty(playerPokemon.species.speciesId)
|
||||
? pokemonEvolutions[playerPokemon.species.speciesId].find(
|
||||
e =>
|
||||
e.item === this.type.evolutionItem &&
|
||||
(e.evoFormKey === null || (e.preFormKey || "") === playerPokemon.getFormKey()) &&
|
||||
(!e.condition || e.condition.predicate(playerPokemon)),
|
||||
e.evoItem === this.type.evolutionItem && e.validate(playerPokemon, false, e.item!),
|
||||
)
|
||||
: null;
|
||||
|
||||
if (!matchingEvolution && playerPokemon.isFusion()) {
|
||||
matchingEvolution = pokemonEvolutions[playerPokemon.fusionSpecies!.speciesId].find(
|
||||
e =>
|
||||
e.item === this.type.evolutionItem && // TODO: is the bang correct?
|
||||
(e.evoFormKey === null || (e.preFormKey || "") === playerPokemon.getFusionFormKey()) &&
|
||||
(!e.condition || e.condition.predicate(playerPokemon)),
|
||||
e.evoItem === this.type.evolutionItem && e.validate(playerPokemon, true, e.item!),
|
||||
);
|
||||
if (matchingEvolution) {
|
||||
matchingEvolution = new FusionSpeciesFormEvolution(playerPokemon.species.speciesId, matchingEvolution);
|
||||
|
Loading…
Reference in New Issue
Block a user