mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-06-21 17:12:44 +02:00
Review suggestions
- Convert `EvoCondKey` enum to `const` object - Use early returns in `SpeciesEvolutionCondition#description` and `SpeciesFormEvolution#description` - Replace `!!x.find` with `x.some` and `y.indexOf() > -1` with `y.includes()` - Implement `coerceArray` - Fix Shelmet evolution condition checking for Shelmet and not Karrablast - Remove unnecessary type casting in `battle-scene.ts`
This commit is contained in:
parent
2215aa0972
commit
3f10b0c11b
@ -2966,7 +2966,7 @@ export default class BattleScene extends SceneBase {
|
||||
if (
|
||||
modifier instanceof PokemonHeldItemModifier &&
|
||||
!isNullOrUndefined(modifier.getSpecies()) &&
|
||||
!this.getPokemonById((modifier as PokemonHeldItemModifier).pokemonId)?.hasSpecies(modifier.getSpecies()!)
|
||||
!this.getPokemonById(modifier.pokemonId)?.hasSpecies(modifier.getSpecies()!)
|
||||
) {
|
||||
modifiers.splice(m--, 1);
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ import { Gender, getGenderSymbol } from "#app/data/gender";
|
||||
import { PokeballType } from "#enums/pokeball";
|
||||
import type Pokemon from "#app/field/pokemon";
|
||||
import { PokemonType } from "#enums/pokemon-type";
|
||||
import { isNullOrUndefined, randSeedInt } from "#app/utils/common";
|
||||
import { coerceArray, isNullOrUndefined, randSeedInt } from "#app/utils/common";
|
||||
import { WeatherType } from "#enums/weather-type";
|
||||
import { Nature } from "#enums/nature";
|
||||
import { BiomeId } from "#enums/biome-id";
|
||||
@ -84,38 +84,37 @@ type TyrogueMove = MoveId.LOW_SWEEP | MoveId.MACH_PUNCH | MoveId.RAPID_SPIN;
|
||||
*/
|
||||
export type EvolutionLevel = [species: SpeciesId, level: number];
|
||||
|
||||
enum EvoCondKey {
|
||||
FRIENDSHIP = 1,
|
||||
TIME,
|
||||
MOVE,
|
||||
MOVE_TYPE,
|
||||
PARTY_TYPE,
|
||||
WEATHER,
|
||||
BIOME,
|
||||
TYROGUE,
|
||||
SHEDINJA,
|
||||
EVO_TREASURE_TRACKER,
|
||||
RANDOM_FORM,
|
||||
SPECIES_CAUGHT,
|
||||
GENDER,
|
||||
NATURE,
|
||||
HELD_ITEM, // Currently checks only for species stat booster items
|
||||
}
|
||||
const EvoCondKey = {
|
||||
FRIENDSHIP: 1,
|
||||
TIME: 2,
|
||||
MOVE: 3,
|
||||
MOVE_TYPE: 4,
|
||||
PARTY_TYPE: 5,
|
||||
WEATHER: 6,
|
||||
BIOME: 7,
|
||||
TYROGUE: 8,
|
||||
SHEDINJA: 9,
|
||||
EVO_TREASURE_TRACKER: 10,
|
||||
RANDOM_FORM: 11,
|
||||
SPECIES_CAUGHT: 12,
|
||||
GENDER: 13,
|
||||
NATURE: 14,
|
||||
HELD_ITEM: 15, // Currently checks only for species stat booster items
|
||||
} as const;
|
||||
|
||||
type EvolutionConditionData =
|
||||
{key: EvoCondKey.FRIENDSHIP | EvoCondKey.RANDOM_FORM | EvoCondKey.EVO_TREASURE_TRACKER, value: number} |
|
||||
{key: EvoCondKey.MOVE, move: MoveId} |
|
||||
{key: EvoCondKey.TIME, time: TimeOfDay[]} |
|
||||
{key: EvoCondKey.BIOME, biome: BiomeId[]} |
|
||||
{key: EvoCondKey.GENDER, gender: Gender} |
|
||||
{key: EvoCondKey.MOVE_TYPE | EvoCondKey.PARTY_TYPE, pkmnType: PokemonType} |
|
||||
{key: EvoCondKey.SPECIES_CAUGHT, speciesCaught: SpeciesId} |
|
||||
{key: EvoCondKey.HELD_ITEM, itemKey: SpeciesStatBoosterItem} |
|
||||
{key: EvoCondKey.NATURE, nature: Nature[]} |
|
||||
{key: EvoCondKey.WEATHER, weather: WeatherType[]} |
|
||||
{key: EvoCondKey.TYROGUE, move: TyrogueMove} |
|
||||
{key: EvoCondKey.SHEDINJA}
|
||||
;
|
||||
{key: typeof EvoCondKey.FRIENDSHIP | typeof EvoCondKey.RANDOM_FORM | typeof EvoCondKey.EVO_TREASURE_TRACKER, value: number} |
|
||||
{key: typeof EvoCondKey.MOVE, move: MoveId} |
|
||||
{key: typeof EvoCondKey.TIME, time: TimeOfDay[]} |
|
||||
{key: typeof EvoCondKey.BIOME, biome: BiomeId[]} |
|
||||
{key: typeof EvoCondKey.GENDER, gender: Gender} |
|
||||
{key: typeof EvoCondKey.MOVE_TYPE | typeof EvoCondKey.PARTY_TYPE, pkmnType: PokemonType} |
|
||||
{key: typeof EvoCondKey.SPECIES_CAUGHT, speciesCaught: SpeciesId} |
|
||||
{key: typeof EvoCondKey.HELD_ITEM, itemKey: SpeciesStatBoosterItem} |
|
||||
{key: typeof EvoCondKey.NATURE, nature: Nature[]} |
|
||||
{key: typeof EvoCondKey.WEATHER, weather: WeatherType[]} |
|
||||
{key: typeof EvoCondKey.TYROGUE, move: TyrogueMove} |
|
||||
{key: typeof EvoCondKey.SHEDINJA};
|
||||
|
||||
export class SpeciesEvolutionCondition {
|
||||
public data: EvolutionConditionData[];
|
||||
@ -126,7 +125,9 @@ export class SpeciesEvolutionCondition {
|
||||
}
|
||||
|
||||
public get description(): string[] {
|
||||
if (isNullOrUndefined(this.desc)) {
|
||||
if (!isNullOrUndefined(this.desc)) {
|
||||
return this.desc;
|
||||
}
|
||||
this.desc = this.data.map(cond => {
|
||||
switch(cond.key) {
|
||||
case EvoCondKey.FRIENDSHIP:
|
||||
@ -158,7 +159,6 @@ export class SpeciesEvolutionCondition {
|
||||
return i18next.t(`pokemonEvolutions:heldItem.${cond.itemKey}`);
|
||||
}
|
||||
}).filter(s => !isNullOrUndefined(s)); // Filter out stringless conditions
|
||||
}
|
||||
return this.desc;
|
||||
}
|
||||
|
||||
@ -175,7 +175,7 @@ export class SpeciesEvolutionCondition {
|
||||
case EvoCondKey.MOVE_TYPE:
|
||||
return pokemon.moveset.some(m => m.getMove().type === cond.pkmnType);
|
||||
case EvoCondKey.PARTY_TYPE:
|
||||
return !!globalScene.getPlayerParty().find(p => p.getTypes(false, false, true).indexOf(cond.pkmnType) > -1)
|
||||
return globalScene.getPlayerParty().some(p => p.getTypes(false, false, true).includes(cond.pkmnType))
|
||||
case EvoCondKey.EVO_TREASURE_TRACKER:
|
||||
return pokemon.getHeldItems().some(m =>
|
||||
m.is("EvoTrackerModifier") &&
|
||||
@ -190,9 +190,7 @@ export class SpeciesEvolutionCondition {
|
||||
case EvoCondKey.WEATHER:
|
||||
return cond.weather.includes(globalScene.arena.getWeatherType());
|
||||
case EvoCondKey.TYROGUE:
|
||||
return pokemon.getMoveset(true).find(m =>
|
||||
m && m.moveId as TyrogueMove
|
||||
)?.moveId === cond.move;
|
||||
return pokemon.getMoveset(true).find(m => m.moveId as TyrogueMove)?.moveId === cond.move;
|
||||
case EvoCondKey.NATURE:
|
||||
return cond.nature.includes(pokemon.getNature());
|
||||
case EvoCondKey.RANDOM_FORM: {
|
||||
@ -230,18 +228,16 @@ export class SpeciesFormEvolution {
|
||||
this.level = level;
|
||||
this.item = item || EvolutionItem.NONE;
|
||||
if (!isNullOrUndefined(condition)) {
|
||||
if (Array.isArray(condition)) { // Waiting on coerceArray...
|
||||
this.condition = new SpeciesEvolutionCondition(...condition);
|
||||
}
|
||||
else {
|
||||
this.condition = new SpeciesEvolutionCondition(condition);
|
||||
}
|
||||
this.condition = new SpeciesEvolutionCondition(...coerceArray(condition));
|
||||
}
|
||||
this.wildDelay = wildDelay ?? SpeciesWildEvolutionDelay.NONE;
|
||||
}
|
||||
|
||||
get description(): string {
|
||||
if (this.desc.length === 0) {
|
||||
if (this.desc.length > 0) {
|
||||
return this.desc;
|
||||
}
|
||||
|
||||
const strings: string[] = [];
|
||||
let len = 0;
|
||||
if (this.level > 1) {
|
||||
@ -274,7 +270,7 @@ export class SpeciesFormEvolution {
|
||||
})
|
||||
.join(" ")
|
||||
.replace(" \n", i18next.t("pokemonEvolutions:connector") + "\n");
|
||||
}
|
||||
|
||||
return this.desc;
|
||||
}
|
||||
|
||||
@ -290,7 +286,7 @@ export class SpeciesFormEvolution {
|
||||
pokemon.level >= this.level &&
|
||||
// Check form key, using the fusion's form key if we're checking the fusion
|
||||
(isNullOrUndefined(this.preFormKey) || (forFusion ? pokemon.getFusionFormKey() : pokemon.getFormKey()) === this.preFormKey) &&
|
||||
(isNullOrUndefined(this.condition) || this.condition?.conditionsFulfilled(pokemon)) &&
|
||||
(isNullOrUndefined(this.condition) || this.condition.conditionsFulfilled(pokemon)) &&
|
||||
((item ?? EvolutionItem.NONE) === (this.item ?? EvolutionItem.NONE))
|
||||
);
|
||||
}
|
||||
@ -302,7 +298,7 @@ export class SpeciesFormEvolution {
|
||||
pokemon.level >= this.level &&
|
||||
// Check form key, using the fusion's form key if we're checking the fusion
|
||||
(isNullOrUndefined(this.preFormKey) || (forFusion ? pokemon.getFormKey() : pokemon.getFusionFormKey()) === this.preFormKey) &&
|
||||
(this.condition === null || this.condition?.conditionsFulfilled(pokemon))
|
||||
(isNullOrUndefined(this.condition) || this.condition.conditionsFulfilled(pokemon))
|
||||
);
|
||||
}
|
||||
|
||||
@ -1777,7 +1773,7 @@ export const pokemonEvolutions: PokemonEvolutions = {
|
||||
new SpeciesEvolution(SpeciesId.ESCAVALIER, 1, EvolutionItem.LINKING_CORD, {key: EvoCondKey.SPECIES_CAUGHT, speciesCaught: SpeciesId.SHELMET}, SpeciesWildEvolutionDelay.VERY_LONG)
|
||||
],
|
||||
[SpeciesId.SHELMET]: [
|
||||
new SpeciesEvolution(SpeciesId.ACCELGOR, 1, EvolutionItem.LINKING_CORD, {key: EvoCondKey.SPECIES_CAUGHT, speciesCaught: SpeciesId.SHELMET}, SpeciesWildEvolutionDelay.VERY_LONG)
|
||||
new SpeciesEvolution(SpeciesId.ACCELGOR, 1, EvolutionItem.LINKING_CORD, {key: EvoCondKey.SPECIES_CAUGHT, speciesCaught: SpeciesId.KARRABLAST}, SpeciesWildEvolutionDelay.VERY_LONG)
|
||||
],
|
||||
[SpeciesId.SPRITZEE]: [
|
||||
new SpeciesEvolution(SpeciesId.AROMATISSE, 1, EvolutionItem.SACHET, null, SpeciesWildEvolutionDelay.VERY_LONG)
|
||||
|
Loading…
Reference in New Issue
Block a user