From 8e6688daef8986a5f1de3e9caebb778e7b231a03 Mon Sep 17 00:00:00 2001 From: frutescens Date: Sun, 3 Nov 2024 21:25:54 -0800 Subject: [PATCH 1/4] 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 d82acec1c20b..a13388d7de6e 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 e0ed96504b19..d0a43e3bcf88 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 483e6eac9431..d3a0b4a46a98 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 595f347a6b5b..a82a8601234b 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 12f075f1b553..8c4c03da957b 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 a26aa572ef38..a28615a4211c 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); } From 8b189d374725d9273f8095530e3403e6ee9ecb14 Mon Sep 17 00:00:00 2001 From: frutescens Date: Sun, 3 Nov 2024 21:38:38 -0800 Subject: [PATCH 2/4] whoops, should still apply to fainted party member --- src/field/pokemon.ts | 4 ++-- src/ui/party-ui-handler.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index d0a43e3bcf88..148cea1c1038 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -5127,8 +5127,8 @@ export class EnemyPokemon extends Pokemon { 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[]; + if (pokemonReplaced && newPokemon.isAllowedInChallenge()) { + const modifiersToTransfer = this.scene.findModifiers(m => m instanceof PokemonHeldItemModifier && !(m instanceof BaseStatModifier) && 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)); diff --git a/src/ui/party-ui-handler.ts b/src/ui/party-ui-handler.ts index a28615a4211c..e16088f524e6 100644 --- a/src/ui/party-ui-handler.ts +++ b/src/ui/party-ui-handler.ts @@ -1063,7 +1063,7 @@ export default class PartyUiHandler extends MessageUiHandler { this.clearPartySlots(); const releasedPokemon = this.scene.getPlayerParty().splice(slotIndex, 1)[0]; let releasedId: number = 0; - if (releasedPokemon.isAllowedInBattle()) { + if (releasedPokemon.isAllowedInChallenge()) { releasedId = releasedPokemon.id; } this.populatePartySlots(); From ca0d2eca920bb7b9febc4621794da084d976cbbf Mon Sep 17 00:00:00 2001 From: frutescens Date: Sun, 3 Nov 2024 21:49:29 -0800 Subject: [PATCH 3/4] transfer add --- src/field/pokemon.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 148cea1c1038..4ed1b01c88d5 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -5128,7 +5128,7 @@ export class EnemyPokemon extends Pokemon { } if (pokemonReplaced && newPokemon.isAllowedInChallenge()) { - const modifiersToTransfer = this.scene.findModifiers(m => m instanceof PokemonHeldItemModifier && !(m instanceof BaseStatModifier) && m.pokemonId === pokemonReplaced, true) as PokemonHeldItemModifier[]; + const modifiersToTransfer = this.scene.findModifiers(m => m instanceof PokemonHeldItemModifier && !(m instanceof BaseStatModifier) && m.isTransferable && 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)); From 52da58b1b269b9f11daa36eeda707abd68b31362 Mon Sep 17 00:00:00 2001 From: frutescens Date: Sun, 3 Nov 2024 21:54:40 -0800 Subject: [PATCH 4/4] add friendship requirement --- src/ui/party-ui-handler.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/party-ui-handler.ts b/src/ui/party-ui-handler.ts index e16088f524e6..05828f564573 100644 --- a/src/ui/party-ui-handler.ts +++ b/src/ui/party-ui-handler.ts @@ -1063,7 +1063,7 @@ export default class PartyUiHandler extends MessageUiHandler { this.clearPartySlots(); const releasedPokemon = this.scene.getPlayerParty().splice(slotIndex, 1)[0]; let releasedId: number = 0; - if (releasedPokemon.isAllowedInChallenge()) { + if (releasedPokemon.isAllowedInChallenge() && releasedPokemon.friendship > 200) { releasedId = releasedPokemon.id; } this.populatePartySlots();