Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QoL] Proof of Concept - Transfer held items from released Party Pokemon to new Pokemon #4788

Open
wants to merge 4 commits into
base: beta
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/battle-scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2632,10 +2632,9 @@ export default class BattleScene extends SceneBase {
});
}

removePartyMemberModifiers(partyMemberIndex: integer): Promise<void> {
removePartyMemberModifiers(partyMemberId: integer): Promise<void> {
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);
}
Expand Down
11 changes: 10 additions & 1 deletion src/field/pokemon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -5126,6 +5126,15 @@ export class EnemyPokemon extends Pokemon {
if (slotIndex === 0) {
newPokemon.setVisible(false); // Hide if replaced with first pokemon
}

if (pokemonReplaced && newPokemon.isAllowedInChallenge()) {
const modifiersToTransfer = this.scene.findModifiers(m => m instanceof PokemonHeldItemModifier && !(m instanceof BaseStatModifier) && m.isTransferable && m.pokemonId === pokemonReplaced, true) as PokemonHeldItemModifier[];
const transferResults: Promise<boolean>[] = [];
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);
Expand Down
10 changes: 5 additions & 5 deletions src/phases/attempt-capture-phase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 0 additions & 2 deletions src/test/moves/dragon_rage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand Down
2 changes: 0 additions & 2 deletions src/test/moves/fissure.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand Down
11 changes: 7 additions & 4 deletions src/ui/party-ui-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1061,18 +1061,21 @@ 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.isAllowedInChallenge() && releasedPokemon.friendship > 200) {
releasedId = releasedPokemon.id;
}
this.populatePartySlots();
if (this.cursor >= this.scene.getPlayerParty().length) {
this.setCursor(this.cursor - 1);
}
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);
}
Expand Down
Loading