fix #762 by using slotIndex to add to party

for now the new pokemon was ALWAYS just pushed to the party array. Now it's put into the slot that was also previously selected as the mon to release
This commit is contained in:
flx-sta 2024-09-04 12:51:04 -07:00
parent fde32cea6c
commit a7fb3241fd
4 changed files with 25 additions and 6 deletions

1
src/constants.ts Normal file
View File

@ -0,0 +1 @@
export const PLAYER_PARTY_MAX_SIZE = 6;

View File

@ -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);
}

View File

@ -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();
}

View File

@ -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;
}