From 8e6688daef8986a5f1de3e9caebb778e7b231a03 Mon Sep 17 00:00:00 2001 From: frutescens Date: Sun, 3 Nov 2024 21:25:54 -0800 Subject: [PATCH] Not sure if I'm happy, but it's over... --- src/battle-scene.ts | 5 ++--- src/field/pokemon.ts | 11 ++++++++++- src/phases/attempt-capture-phase.ts | 10 +++++----- src/test/moves/dragon_rage.test.ts | 2 -- src/test/moves/fissure.test.ts | 2 -- src/ui/party-ui-handler.ts | 11 +++++++---- 6 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/battle-scene.ts b/src/battle-scene.ts index d82acec1c20..a13388d7de6 100644 --- a/src/battle-scene.ts +++ b/src/battle-scene.ts @@ -2632,10 +2632,9 @@ export default class BattleScene extends SceneBase { }); } - removePartyMemberModifiers(partyMemberIndex: integer): Promise { + removePartyMemberModifiers(partyMemberId: integer): Promise { return new Promise(resolve => { - const pokemonId = this.getPlayerParty()[partyMemberIndex].id; - const modifiersToRemove = this.modifiers.filter(m => m instanceof PokemonHeldItemModifier && (m as PokemonHeldItemModifier).pokemonId === pokemonId); + const modifiersToRemove = this.modifiers.filter(m => m instanceof PokemonHeldItemModifier && (m as PokemonHeldItemModifier).pokemonId === partyMemberId); for (const m of modifiersToRemove) { this.modifiers.splice(this.modifiers.indexOf(m), 1); } diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index e0ed96504b1..d0a43e3bcf8 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -5110,7 +5110,7 @@ export class EnemyPokemon extends Pokemon { * @param slotIndex an optional index to place the pokemon in the party * @returns the pokemon that was added or null if the pokemon could not be added */ - addToParty(pokeballType: PokeballType, slotIndex: number = -1) { + addToParty(pokeballType: PokeballType, slotIndex: number = -1, pokemonReplaced?: number | null) { const party = this.scene.getPlayerParty(); let ret: PlayerPokemon | null = null; @@ -5126,6 +5126,15 @@ export class EnemyPokemon extends Pokemon { if (slotIndex === 0) { newPokemon.setVisible(false); // Hide if replaced with first pokemon } + + if (pokemonReplaced && newPokemon.isAllowedInBattle()) { + const modifiersToTransfer = this.scene.findModifiers(m => m instanceof PokemonHeldItemModifier && m.pokemonId === pokemonReplaced, true) as PokemonHeldItemModifier[]; + const transferResults: Promise[] = []; + for (const modifier of modifiersToTransfer) { + transferResults.push(this.scene.tryTransferHeldItemModifier(modifier, newPokemon, false, modifier.getStackCount(), true, true)); + } + Promise.allSettled(transferResults).then(() => newPokemon.scene.removePartyMemberModifiers(pokemonReplaced)); + } party.splice(slotIndex, 0, newPokemon); } else { party.push(newPokemon); diff --git a/src/phases/attempt-capture-phase.ts b/src/phases/attempt-capture-phase.ts index 483e6eac943..d3a0b4a46a9 100644 --- a/src/phases/attempt-capture-phase.ts +++ b/src/phases/attempt-capture-phase.ts @@ -233,8 +233,8 @@ export class AttemptCapturePhase extends PokemonPhase { this.scene.clearEnemyHeldItemModifiers(); this.scene.field.remove(pokemon, true); }; - const addToParty = (slotIndex?: number) => { - const newPokemon = pokemon.addToParty(this.pokeballType, slotIndex); + const addToParty = (slotIndex?: number, releasedPokemon?: number) => { + const newPokemon = pokemon.addToParty(this.pokeballType, slotIndex, releasedPokemon); const modifiers = this.scene.findModifiers(m => m instanceof PokemonHeldItemModifier, false); if (this.scene.getPlayerParty().filter(p => p.isShiny()).length === PLAYER_PARTY_MAX_SIZE) { this.scene.validateAchv(achvs.SHINY_PARTY); @@ -262,15 +262,15 @@ export class AttemptCapturePhase extends PokemonPhase { }); }, false); }, () => { - this.scene.ui.setMode(Mode.PARTY, PartyUiMode.RELEASE, this.fieldIndex, (slotIndex: integer, _option: PartyOption) => { + this.scene.ui.setMode(Mode.PARTY, PartyUiMode.RELEASE, this.fieldIndex, (slotIndex: number, _option: PartyOption, releasedPokemon: number) => { this.scene.ui.setMode(Mode.MESSAGE).then(() => { if (slotIndex < 6) { - addToParty(slotIndex); + addToParty(slotIndex, releasedPokemon); } else { promptRelease(); } }); - }); + }, ); }, () => { this.scene.ui.setMode(Mode.MESSAGE).then(() => { removePokemon(); diff --git a/src/test/moves/dragon_rage.test.ts b/src/test/moves/dragon_rage.test.ts index 595f347a6b5..a82a8601234 100644 --- a/src/test/moves/dragon_rage.test.ts +++ b/src/test/moves/dragon_rage.test.ts @@ -51,8 +51,6 @@ describe("Moves - Dragon Rage", () => { partyPokemon = game.scene.getPlayerParty()[0]; enemyPokemon = game.scene.getEnemyPokemon()!; - // remove berries - game.scene.removePartyMemberModifiers(0); game.scene.clearEnemyHeldItemModifiers(); }); diff --git a/src/test/moves/fissure.test.ts b/src/test/moves/fissure.test.ts index 12f075f1b55..8c4c03da957 100644 --- a/src/test/moves/fissure.test.ts +++ b/src/test/moves/fissure.test.ts @@ -46,8 +46,6 @@ describe("Moves - Fissure", () => { partyPokemon = game.scene.getPlayerParty()[0]; enemyPokemon = game.scene.getEnemyPokemon()!; - // remove berries - game.scene.removePartyMemberModifiers(0); game.scene.clearEnemyHeldItemModifiers(); }); diff --git a/src/ui/party-ui-handler.ts b/src/ui/party-ui-handler.ts index a26aa572ef3..a28615a4211 100644 --- a/src/ui/party-ui-handler.ts +++ b/src/ui/party-ui-handler.ts @@ -123,7 +123,7 @@ export enum PartyOption { ALL = 4000, } -export type PartySelectCallback = (cursor: integer, option: PartyOption) => void; +export type PartySelectCallback = (cursor: integer, option: PartyOption, args?: any | undefined) => void; export type PartyModifierTransferSelectCallback = (fromCursor: integer, index: integer, itemQuantity?: integer, toCursor?: integer) => void; export type PartyModifierSpliceSelectCallback = (fromCursor: integer, toCursor?: integer) => void; export type PokemonSelectFilter = (pokemon: PlayerPokemon) => string | null; @@ -1061,9 +1061,11 @@ export default class PartyUiHandler extends MessageUiHandler { doRelease(slotIndex: integer): void { this.showText(this.getReleaseMessage(getPokemonNameWithAffix(this.scene.getPlayerParty()[slotIndex])), null, () => { this.clearPartySlots(); - this.scene.removePartyMemberModifiers(slotIndex); const releasedPokemon = this.scene.getPlayerParty().splice(slotIndex, 1)[0]; - releasedPokemon.destroy(); + let releasedId: number = 0; + if (releasedPokemon.isAllowedInBattle()) { + releasedId = releasedPokemon.id; + } this.populatePartySlots(); if (this.cursor >= this.scene.getPlayerParty().length) { this.setCursor(this.cursor - 1); @@ -1071,8 +1073,9 @@ export default class PartyUiHandler extends MessageUiHandler { if (this.partyUiMode === PartyUiMode.RELEASE) { const selectCallback = this.selectCallback; this.selectCallback = null; - selectCallback && selectCallback(this.cursor, PartyOption.RELEASE); + selectCallback && selectCallback(this.cursor, PartyOption.RELEASE, releasedId); } + releasedPokemon.destroy(); this.showText("", 0); }, null, true); }