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 (
|
if (
|
||||||
modifier instanceof PokemonHeldItemModifier &&
|
modifier instanceof PokemonHeldItemModifier &&
|
||||||
!isNullOrUndefined(modifier.getSpecies()) &&
|
!isNullOrUndefined(modifier.getSpecies()) &&
|
||||||
!this.getPokemonById((modifier as PokemonHeldItemModifier).pokemonId)?.hasSpecies(modifier.getSpecies()!)
|
!this.getPokemonById(modifier.pokemonId)?.hasSpecies(modifier.getSpecies()!)
|
||||||
) {
|
) {
|
||||||
modifiers.splice(m--, 1);
|
modifiers.splice(m--, 1);
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ import { Gender, getGenderSymbol } from "#app/data/gender";
|
|||||||
import { PokeballType } from "#enums/pokeball";
|
import { PokeballType } from "#enums/pokeball";
|
||||||
import type Pokemon from "#app/field/pokemon";
|
import type Pokemon from "#app/field/pokemon";
|
||||||
import { PokemonType } from "#enums/pokemon-type";
|
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 { WeatherType } from "#enums/weather-type";
|
||||||
import { Nature } from "#enums/nature";
|
import { Nature } from "#enums/nature";
|
||||||
import { BiomeId } from "#enums/biome-id";
|
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];
|
export type EvolutionLevel = [species: SpeciesId, level: number];
|
||||||
|
|
||||||
enum EvoCondKey {
|
const EvoCondKey = {
|
||||||
FRIENDSHIP = 1,
|
FRIENDSHIP: 1,
|
||||||
TIME,
|
TIME: 2,
|
||||||
MOVE,
|
MOVE: 3,
|
||||||
MOVE_TYPE,
|
MOVE_TYPE: 4,
|
||||||
PARTY_TYPE,
|
PARTY_TYPE: 5,
|
||||||
WEATHER,
|
WEATHER: 6,
|
||||||
BIOME,
|
BIOME: 7,
|
||||||
TYROGUE,
|
TYROGUE: 8,
|
||||||
SHEDINJA,
|
SHEDINJA: 9,
|
||||||
EVO_TREASURE_TRACKER,
|
EVO_TREASURE_TRACKER: 10,
|
||||||
RANDOM_FORM,
|
RANDOM_FORM: 11,
|
||||||
SPECIES_CAUGHT,
|
SPECIES_CAUGHT: 12,
|
||||||
GENDER,
|
GENDER: 13,
|
||||||
NATURE,
|
NATURE: 14,
|
||||||
HELD_ITEM, // Currently checks only for species stat booster items
|
HELD_ITEM: 15, // Currently checks only for species stat booster items
|
||||||
}
|
} as const;
|
||||||
|
|
||||||
type EvolutionConditionData =
|
type EvolutionConditionData =
|
||||||
{key: EvoCondKey.FRIENDSHIP | EvoCondKey.RANDOM_FORM | EvoCondKey.EVO_TREASURE_TRACKER, value: number} |
|
{key: typeof EvoCondKey.FRIENDSHIP | typeof EvoCondKey.RANDOM_FORM | typeof EvoCondKey.EVO_TREASURE_TRACKER, value: number} |
|
||||||
{key: EvoCondKey.MOVE, move: MoveId} |
|
{key: typeof EvoCondKey.MOVE, move: MoveId} |
|
||||||
{key: EvoCondKey.TIME, time: TimeOfDay[]} |
|
{key: typeof EvoCondKey.TIME, time: TimeOfDay[]} |
|
||||||
{key: EvoCondKey.BIOME, biome: BiomeId[]} |
|
{key: typeof EvoCondKey.BIOME, biome: BiomeId[]} |
|
||||||
{key: EvoCondKey.GENDER, gender: Gender} |
|
{key: typeof EvoCondKey.GENDER, gender: Gender} |
|
||||||
{key: EvoCondKey.MOVE_TYPE | EvoCondKey.PARTY_TYPE, pkmnType: PokemonType} |
|
{key: typeof EvoCondKey.MOVE_TYPE | typeof EvoCondKey.PARTY_TYPE, pkmnType: PokemonType} |
|
||||||
{key: EvoCondKey.SPECIES_CAUGHT, speciesCaught: SpeciesId} |
|
{key: typeof EvoCondKey.SPECIES_CAUGHT, speciesCaught: SpeciesId} |
|
||||||
{key: EvoCondKey.HELD_ITEM, itemKey: SpeciesStatBoosterItem} |
|
{key: typeof EvoCondKey.HELD_ITEM, itemKey: SpeciesStatBoosterItem} |
|
||||||
{key: EvoCondKey.NATURE, nature: Nature[]} |
|
{key: typeof EvoCondKey.NATURE, nature: Nature[]} |
|
||||||
{key: EvoCondKey.WEATHER, weather: WeatherType[]} |
|
{key: typeof EvoCondKey.WEATHER, weather: WeatherType[]} |
|
||||||
{key: EvoCondKey.TYROGUE, move: TyrogueMove} |
|
{key: typeof EvoCondKey.TYROGUE, move: TyrogueMove} |
|
||||||
{key: EvoCondKey.SHEDINJA}
|
{key: typeof EvoCondKey.SHEDINJA};
|
||||||
;
|
|
||||||
|
|
||||||
export class SpeciesEvolutionCondition {
|
export class SpeciesEvolutionCondition {
|
||||||
public data: EvolutionConditionData[];
|
public data: EvolutionConditionData[];
|
||||||
@ -126,7 +125,9 @@ export class SpeciesEvolutionCondition {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public get description(): string[] {
|
public get description(): string[] {
|
||||||
if (isNullOrUndefined(this.desc)) {
|
if (!isNullOrUndefined(this.desc)) {
|
||||||
|
return this.desc;
|
||||||
|
}
|
||||||
this.desc = this.data.map(cond => {
|
this.desc = this.data.map(cond => {
|
||||||
switch(cond.key) {
|
switch(cond.key) {
|
||||||
case EvoCondKey.FRIENDSHIP:
|
case EvoCondKey.FRIENDSHIP:
|
||||||
@ -158,7 +159,6 @@ export class SpeciesEvolutionCondition {
|
|||||||
return i18next.t(`pokemonEvolutions:heldItem.${cond.itemKey}`);
|
return i18next.t(`pokemonEvolutions:heldItem.${cond.itemKey}`);
|
||||||
}
|
}
|
||||||
}).filter(s => !isNullOrUndefined(s)); // Filter out stringless conditions
|
}).filter(s => !isNullOrUndefined(s)); // Filter out stringless conditions
|
||||||
}
|
|
||||||
return this.desc;
|
return this.desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,7 +175,7 @@ export class SpeciesEvolutionCondition {
|
|||||||
case EvoCondKey.MOVE_TYPE:
|
case EvoCondKey.MOVE_TYPE:
|
||||||
return pokemon.moveset.some(m => m.getMove().type === cond.pkmnType);
|
return pokemon.moveset.some(m => m.getMove().type === cond.pkmnType);
|
||||||
case EvoCondKey.PARTY_TYPE:
|
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:
|
case EvoCondKey.EVO_TREASURE_TRACKER:
|
||||||
return pokemon.getHeldItems().some(m =>
|
return pokemon.getHeldItems().some(m =>
|
||||||
m.is("EvoTrackerModifier") &&
|
m.is("EvoTrackerModifier") &&
|
||||||
@ -190,9 +190,7 @@ export class SpeciesEvolutionCondition {
|
|||||||
case EvoCondKey.WEATHER:
|
case EvoCondKey.WEATHER:
|
||||||
return cond.weather.includes(globalScene.arena.getWeatherType());
|
return cond.weather.includes(globalScene.arena.getWeatherType());
|
||||||
case EvoCondKey.TYROGUE:
|
case EvoCondKey.TYROGUE:
|
||||||
return pokemon.getMoveset(true).find(m =>
|
return pokemon.getMoveset(true).find(m => m.moveId as TyrogueMove)?.moveId === cond.move;
|
||||||
m && m.moveId as TyrogueMove
|
|
||||||
)?.moveId === cond.move;
|
|
||||||
case EvoCondKey.NATURE:
|
case EvoCondKey.NATURE:
|
||||||
return cond.nature.includes(pokemon.getNature());
|
return cond.nature.includes(pokemon.getNature());
|
||||||
case EvoCondKey.RANDOM_FORM: {
|
case EvoCondKey.RANDOM_FORM: {
|
||||||
@ -230,18 +228,16 @@ export class SpeciesFormEvolution {
|
|||||||
this.level = level;
|
this.level = level;
|
||||||
this.item = item || EvolutionItem.NONE;
|
this.item = item || EvolutionItem.NONE;
|
||||||
if (!isNullOrUndefined(condition)) {
|
if (!isNullOrUndefined(condition)) {
|
||||||
if (Array.isArray(condition)) { // Waiting on coerceArray...
|
this.condition = new SpeciesEvolutionCondition(...coerceArray(condition));
|
||||||
this.condition = new SpeciesEvolutionCondition(...condition);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.condition = new SpeciesEvolutionCondition(condition);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
this.wildDelay = wildDelay ?? SpeciesWildEvolutionDelay.NONE;
|
this.wildDelay = wildDelay ?? SpeciesWildEvolutionDelay.NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
get description(): string {
|
get description(): string {
|
||||||
if (this.desc.length === 0) {
|
if (this.desc.length > 0) {
|
||||||
|
return this.desc;
|
||||||
|
}
|
||||||
|
|
||||||
const strings: string[] = [];
|
const strings: string[] = [];
|
||||||
let len = 0;
|
let len = 0;
|
||||||
if (this.level > 1) {
|
if (this.level > 1) {
|
||||||
@ -274,7 +270,7 @@ export class SpeciesFormEvolution {
|
|||||||
})
|
})
|
||||||
.join(" ")
|
.join(" ")
|
||||||
.replace(" \n", i18next.t("pokemonEvolutions:connector") + "\n");
|
.replace(" \n", i18next.t("pokemonEvolutions:connector") + "\n");
|
||||||
}
|
|
||||||
return this.desc;
|
return this.desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -290,7 +286,7 @@ export class SpeciesFormEvolution {
|
|||||||
pokemon.level >= this.level &&
|
pokemon.level >= this.level &&
|
||||||
// Check form key, using the fusion's form key if we're checking the fusion
|
// 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.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))
|
((item ?? EvolutionItem.NONE) === (this.item ?? EvolutionItem.NONE))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -302,7 +298,7 @@ export class SpeciesFormEvolution {
|
|||||||
pokemon.level >= this.level &&
|
pokemon.level >= this.level &&
|
||||||
// Check form key, using the fusion's form key if we're checking the fusion
|
// 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) &&
|
(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)
|
new SpeciesEvolution(SpeciesId.ESCAVALIER, 1, EvolutionItem.LINKING_CORD, {key: EvoCondKey.SPECIES_CAUGHT, speciesCaught: SpeciesId.SHELMET}, SpeciesWildEvolutionDelay.VERY_LONG)
|
||||||
],
|
],
|
||||||
[SpeciesId.SHELMET]: [
|
[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]: [
|
[SpeciesId.SPRITZEE]: [
|
||||||
new SpeciesEvolution(SpeciesId.AROMATISSE, 1, EvolutionItem.SACHET, null, SpeciesWildEvolutionDelay.VERY_LONG)
|
new SpeciesEvolution(SpeciesId.AROMATISSE, 1, EvolutionItem.SACHET, null, SpeciesWildEvolutionDelay.VERY_LONG)
|
||||||
|
Loading…
Reference in New Issue
Block a user