Not sure if I'm happy, but it's over...

This commit is contained in:
frutescens 2024-11-03 21:25:54 -08:00
parent 618dfbd324
commit 8e6688daef
6 changed files with 24 additions and 17 deletions

View File

@ -2632,10 +2632,9 @@ export default class BattleScene extends SceneBase {
}); });
} }
removePartyMemberModifiers(partyMemberIndex: integer): Promise<void> { removePartyMemberModifiers(partyMemberId: integer): Promise<void> {
return new Promise(resolve => { return new Promise(resolve => {
const pokemonId = this.getPlayerParty()[partyMemberIndex].id; const modifiersToRemove = this.modifiers.filter(m => m instanceof PokemonHeldItemModifier && (m as PokemonHeldItemModifier).pokemonId === partyMemberId);
const modifiersToRemove = this.modifiers.filter(m => m instanceof PokemonHeldItemModifier && (m as PokemonHeldItemModifier).pokemonId === pokemonId);
for (const m of modifiersToRemove) { for (const m of modifiersToRemove) {
this.modifiers.splice(this.modifiers.indexOf(m), 1); this.modifiers.splice(this.modifiers.indexOf(m), 1);
} }

View File

@ -5110,7 +5110,7 @@ export class EnemyPokemon extends Pokemon {
* @param slotIndex an optional index to place the pokemon in the party * @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 * @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(); const party = this.scene.getPlayerParty();
let ret: PlayerPokemon | null = null; let ret: PlayerPokemon | null = null;
@ -5126,6 +5126,15 @@ export class EnemyPokemon extends Pokemon {
if (slotIndex === 0) { if (slotIndex === 0) {
newPokemon.setVisible(false); // Hide if replaced with first 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[];
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); party.splice(slotIndex, 0, newPokemon);
} else { } else {
party.push(newPokemon); party.push(newPokemon);

View File

@ -233,8 +233,8 @@ export class AttemptCapturePhase extends PokemonPhase {
this.scene.clearEnemyHeldItemModifiers(); this.scene.clearEnemyHeldItemModifiers();
this.scene.field.remove(pokemon, true); this.scene.field.remove(pokemon, true);
}; };
const addToParty = (slotIndex?: number) => { const addToParty = (slotIndex?: number, releasedPokemon?: number) => {
const newPokemon = pokemon.addToParty(this.pokeballType, slotIndex); const newPokemon = pokemon.addToParty(this.pokeballType, slotIndex, releasedPokemon);
const modifiers = this.scene.findModifiers(m => m instanceof PokemonHeldItemModifier, false); const modifiers = this.scene.findModifiers(m => m instanceof PokemonHeldItemModifier, false);
if (this.scene.getPlayerParty().filter(p => p.isShiny()).length === PLAYER_PARTY_MAX_SIZE) { if (this.scene.getPlayerParty().filter(p => p.isShiny()).length === PLAYER_PARTY_MAX_SIZE) {
this.scene.validateAchv(achvs.SHINY_PARTY); this.scene.validateAchv(achvs.SHINY_PARTY);
@ -262,15 +262,15 @@ export class AttemptCapturePhase extends PokemonPhase {
}); });
}, false); }, 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(() => { this.scene.ui.setMode(Mode.MESSAGE).then(() => {
if (slotIndex < 6) { if (slotIndex < 6) {
addToParty(slotIndex); addToParty(slotIndex, releasedPokemon);
} else { } else {
promptRelease(); promptRelease();
} }
}); });
}); }, );
}, () => { }, () => {
this.scene.ui.setMode(Mode.MESSAGE).then(() => { this.scene.ui.setMode(Mode.MESSAGE).then(() => {
removePokemon(); removePokemon();

View File

@ -51,8 +51,6 @@ describe("Moves - Dragon Rage", () => {
partyPokemon = game.scene.getPlayerParty()[0]; partyPokemon = game.scene.getPlayerParty()[0];
enemyPokemon = game.scene.getEnemyPokemon()!; enemyPokemon = game.scene.getEnemyPokemon()!;
// remove berries
game.scene.removePartyMemberModifiers(0);
game.scene.clearEnemyHeldItemModifiers(); game.scene.clearEnemyHeldItemModifiers();
}); });

View File

@ -46,8 +46,6 @@ describe("Moves - Fissure", () => {
partyPokemon = game.scene.getPlayerParty()[0]; partyPokemon = game.scene.getPlayerParty()[0];
enemyPokemon = game.scene.getEnemyPokemon()!; enemyPokemon = game.scene.getEnemyPokemon()!;
// remove berries
game.scene.removePartyMemberModifiers(0);
game.scene.clearEnemyHeldItemModifiers(); game.scene.clearEnemyHeldItemModifiers();
}); });

View File

@ -123,7 +123,7 @@ export enum PartyOption {
ALL = 4000, 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 PartyModifierTransferSelectCallback = (fromCursor: integer, index: integer, itemQuantity?: integer, toCursor?: integer) => void;
export type PartyModifierSpliceSelectCallback = (fromCursor: integer, toCursor?: integer) => void; export type PartyModifierSpliceSelectCallback = (fromCursor: integer, toCursor?: integer) => void;
export type PokemonSelectFilter = (pokemon: PlayerPokemon) => string | null; export type PokemonSelectFilter = (pokemon: PlayerPokemon) => string | null;
@ -1061,9 +1061,11 @@ export default class PartyUiHandler extends MessageUiHandler {
doRelease(slotIndex: integer): void { doRelease(slotIndex: integer): void {
this.showText(this.getReleaseMessage(getPokemonNameWithAffix(this.scene.getPlayerParty()[slotIndex])), null, () => { this.showText(this.getReleaseMessage(getPokemonNameWithAffix(this.scene.getPlayerParty()[slotIndex])), null, () => {
this.clearPartySlots(); this.clearPartySlots();
this.scene.removePartyMemberModifiers(slotIndex);
const releasedPokemon = this.scene.getPlayerParty().splice(slotIndex, 1)[0]; const releasedPokemon = this.scene.getPlayerParty().splice(slotIndex, 1)[0];
releasedPokemon.destroy(); let releasedId: number = 0;
if (releasedPokemon.isAllowedInBattle()) {
releasedId = releasedPokemon.id;
}
this.populatePartySlots(); this.populatePartySlots();
if (this.cursor >= this.scene.getPlayerParty().length) { if (this.cursor >= this.scene.getPlayerParty().length) {
this.setCursor(this.cursor - 1); this.setCursor(this.cursor - 1);
@ -1071,8 +1073,9 @@ export default class PartyUiHandler extends MessageUiHandler {
if (this.partyUiMode === PartyUiMode.RELEASE) { if (this.partyUiMode === PartyUiMode.RELEASE) {
const selectCallback = this.selectCallback; const selectCallback = this.selectCallback;
this.selectCallback = null; this.selectCallback = null;
selectCallback && selectCallback(this.cursor, PartyOption.RELEASE); selectCallback && selectCallback(this.cursor, PartyOption.RELEASE, releasedId);
} }
releasedPokemon.destroy();
this.showText("", 0); this.showText("", 0);
}, null, true); }, null, true);
} }