diff --git a/src/constants.ts b/src/constants.ts new file mode 100644 index 00000000000..a2f7e47b996 --- /dev/null +++ b/src/constants.ts @@ -0,0 +1 @@ +export const PLAYER_PARTY_MAX_SIZE = 6; diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index e0a9a4a86ce..d930bead2a7 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -58,6 +58,7 @@ import { StatStageChangePhase } from "#app/phases/stat-stage-change-phase"; import { SwitchSummonPhase } from "#app/phases/switch-summon-phase"; import { ToggleDoublePositionPhase } from "#app/phases/toggle-double-position-phase"; import { Challenges } from "#enums/challenges"; +import { PLAYER_PARTY_MAX_SIZE } from "#app/constants"; export enum FieldPosition { CENTER, @@ -4413,17 +4414,23 @@ export class EnemyPokemon extends Pokemon { return BattlerIndex.ENEMY + this.getFieldIndex(); } - addToParty(pokeballType: PokeballType) { + addToParty(pokeballType: PokeballType, slotIndex: number = -1) { const party = this.scene.getParty(); let ret: PlayerPokemon | null = null; - if (party.length < 6) { + if (party.length < PLAYER_PARTY_MAX_SIZE) { this.pokeball = pokeballType; this.metLevel = this.level; this.metBiome = this.scene.arena.biomeType; this.metSpecies = this.species.speciesId; const newPokemon = this.scene.addPlayerPokemon(this.species, this.level, this.abilityIndex, this.formIndex, this.gender, this.shiny, this.variant, this.ivs, this.nature, this); - party.push(newPokemon); + + if (Utils.isBetween(slotIndex, 0, PLAYER_PARTY_MAX_SIZE - 1)) { + party.splice(slotIndex, 0, newPokemon); + } else { + party.push(newPokemon); + } + ret = newPokemon; this.scene.triggerPokemonFormChange(newPokemon, SpeciesFormChangeActiveTrigger, true); } diff --git a/src/phases/attempt-capture-phase.ts b/src/phases/attempt-capture-phase.ts index 72995c0f006..3c49aaeb244 100644 --- a/src/phases/attempt-capture-phase.ts +++ b/src/phases/attempt-capture-phase.ts @@ -221,8 +221,8 @@ export class AttemptCapturePhase extends PokemonPhase { this.scene.clearEnemyHeldItemModifiers(); this.scene.field.remove(pokemon, true); }; - const addToParty = () => { - const newPokemon = pokemon.addToParty(this.pokeballType); + const addToParty = (slotIndex?: number) => { + const newPokemon = pokemon.addToParty(this.pokeballType, slotIndex); const modifiers = this.scene.findModifiers(m => m instanceof PokemonHeldItemModifier, false); if (this.scene.getParty().filter(p => p.isShiny()).length === 6) { this.scene.validateAchv(achvs.SHINY_PARTY); @@ -253,7 +253,7 @@ export class AttemptCapturePhase extends PokemonPhase { this.scene.ui.setMode(Mode.PARTY, PartyUiMode.RELEASE, this.fieldIndex, (slotIndex: integer, _option: PartyOption) => { this.scene.ui.setMode(Mode.MESSAGE).then(() => { if (slotIndex < 6) { - addToParty(); + addToParty(slotIndex); } else { promptRelease(); } diff --git a/src/utils.ts b/src/utils.ts index 173ea25b17c..15cd2786627 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -583,3 +583,14 @@ export function toDmgValue(value: number, minValue: number = 1) { export function getLocalizedSpriteKey(baseKey: string) { return `${baseKey}${verifyLang(i18next.resolvedLanguage) ? `_${i18next.resolvedLanguage}` : ""}`; } + +/** + * Check if a number is between two other numbers + * @param num the number to check + * @param min the minimum value + * @param max the maximum value + * @returns true if number is between min and max + */ +export function isBetween(num: number, min: number, max: number): boolean { + return num >= min && num <= max; +}