diff --git a/src/battle-phases.ts b/src/battle-phases.ts index 0ec9682d1a7..0cb4a62da07 100644 --- a/src/battle-phases.ts +++ b/src/battle-phases.ts @@ -654,7 +654,7 @@ export class StatChangePhase extends PokemonPhase { }); } }); - + this.scene.tweens.add({ targets: statSprite, duration: 1500, @@ -803,7 +803,7 @@ export class SwitchPhase extends BattlePhase { start() { super.start(); - this.scene.ui.setMode(Mode.PARTY, this.isModal ? PartyUiMode.FAINT_SWITCH : PartyUiMode.SWITCH, (slotIndex: integer) => { + this.scene.ui.setMode(Mode.PARTY, this.isModal ? PartyUiMode.FAINT_SWITCH : PartyUiMode.POST_BATTLE_SWITCH, (slotIndex: integer) => { if (slotIndex && slotIndex < 6) this.scene.unshiftPhase(new SwitchSummonPhase(this.scene, slotIndex, this.doReturn)); this.scene.ui.setMode(Mode.MESSAGE).then(() => super.end()); @@ -1114,10 +1114,9 @@ export class AttemptCapturePhase extends BattlePhase { this.scene.ui.setMode(Mode.CONFIRM, () => { this.scene.ui.setMode(Mode.PARTY, PartyUiMode.RELEASE, (slotIndex: integer) => { this.scene.ui.setMode(Mode.MESSAGE).then(() => { - if (slotIndex < 6) { - this.scene.getParty().splice(slotIndex, 1); + if (slotIndex < 6) addToParty(); - } else + else promptRelease(); }); }); diff --git a/src/battle-scene.ts b/src/battle-scene.ts index fd405622a7e..77ebbd91374 100644 --- a/src/battle-scene.ts +++ b/src/battle-scene.ts @@ -5,7 +5,7 @@ import { EncounterPhase, SummonPhase, CommandPhase, NextEncounterPhase, SwitchBi import { PlayerPokemon, EnemyPokemon } from './pokemon'; import PokemonSpecies, { allSpecies, getPokemonSpecies } from './pokemon-species'; import * as Utils from './utils'; -import { Modifier, ModifierBar, ConsumablePokemonModifier, ConsumableModifier, PartyShareModifier, PokemonHpRestoreModifier, HealingBoosterModifier, PersistentModifier } from './modifier'; +import { Modifier, ModifierBar, ConsumablePokemonModifier, ConsumableModifier, PartyShareModifier, PokemonHpRestoreModifier, HealingBoosterModifier, PersistentModifier, PokemonHeldItemModifier } from './modifier'; import { PokeballType } from './pokeball'; import { Species } from './species'; import { initAutoPlay } from './auto-play'; @@ -536,15 +536,18 @@ export default class BattleScene extends Phaser.Scene { }); } - updatePartyForModifiers(): Promise { + removePartyMemberModifiers(partyMemberIndex: integer): Promise { return new Promise(resolve => { - Promise.allSettled(this.party.map(p => { - p.calculateStats(); - return p.updateInfo(); - })).then(() => resolve()); + const pokemonId = this.getParty()[partyMemberIndex].id; + const modifiersToRemove = this.modifiers.filter(m => (m instanceof PokemonHeldItemModifier) && (m as PokemonHeldItemModifier).pokemonId === pokemonId); + for (let m of modifiersToRemove) + this.modifiers.splice(this.modifiers.indexOf(m), 1); + this.updateModifiers().then(() => resolve()); }); } + + updateModifiers(): Promise { return new Promise(resolve => { for (let modifier of this.modifiers) { @@ -567,6 +570,15 @@ export default class BattleScene extends Phaser.Scene { }); } + updatePartyForModifiers(): Promise { + return new Promise(resolve => { + Promise.allSettled(this.party.map(p => { + p.calculateStats(); + return p.updateInfo(); + })).then(() => resolve()); + }); + } + getModifier(modifierType: { new(...args: any[]): Modifier }): Modifier { return this.modifiers.find(m => m instanceof modifierType); } diff --git a/src/ui/party-ui-handler.ts b/src/ui/party-ui-handler.ts index 1e95c7f1c61..74fa5ccb8f2 100644 --- a/src/ui/party-ui-handler.ts +++ b/src/ui/party-ui-handler.ts @@ -151,19 +151,16 @@ export default class PartyUiHandler extends MessageUiHandler { if (button === Button.ACTION) { const option = this.options[this.optionsCursor]; const pokemon = this.scene.getParty()[this.cursor]; - if (option === PartyOption.SHIFT || option === PartyOption.SEND_OUT || option === PartyOption.APPLY || option === PartyOption.RELEASE) { + if (option === PartyOption.SHIFT || option === PartyOption.SEND_OUT || option === PartyOption.APPLY + || (this.partyUiMode === PartyUiMode.RELEASE && option === PartyOption.RELEASE)) { let filterResult: string = this.selectFilter(pokemon); if (filterResult === null) { this.clearOptions(); if (this.selectCallback) { - const selectCallback = this.selectCallback; - if (option === PartyOption.RELEASE) { - this.partyMessageBox.setTexture('party_message'); - this.showText(this.getReleaseMessage(pokemon.name), null, () => { - this.selectCallback = null; - selectCallback(this.cursor); - }, null, true); - } else { + if (option === PartyOption.RELEASE) + this.doRelease(this.cursor); + else { + const selectCallback = this.selectCallback; this.selectCallback = null; selectCallback(this.cursor); } @@ -185,6 +182,21 @@ export default class PartyUiHandler extends MessageUiHandler { } else if (option === PartyOption.SUMMARY) { ui.playSelect(); ui.setModeWithoutClear(Mode.SUMMARY, pokemon).then(() => this.clearOptions()); + } else if (option === PartyOption.RELEASE) { + this.clearOptions(); + ui.playSelect(); + if (this.cursor) { + this.showText(`Do you really want to release ${pokemon.name}?`, null, () => { + ui.setModeWithoutClear(Mode.CONFIRM, () => { + ui.setMode(Mode.PARTY); + this.doRelease(this.cursor); + }, () => { + ui.setMode(Mode.PARTY); + this.message.setText(defaultMessage); + }); + }); + } else + this.showText('You can\'t release a POKéMON that\'s in battle!', null, () => this.message.setText(defaultMessage), null, true); } else if (option === PartyOption.CANCEL) this.processInput(Button.CANCEL); } else if (button === Button.CANCEL) { @@ -331,7 +343,12 @@ export default class PartyUiHandler extends MessageUiHandler { break; } - this.options.push(PartyOption.SUMMARY, PartyOption.CANCEL); + this.options.push(PartyOption.SUMMARY); + + if (this.partyUiMode === PartyUiMode.SWITCH) + this.options.push(PartyOption.RELEASE); + + this.options.push(PartyOption.CANCEL); for (let o = 0; o < this.options.length; o++) { const yCoord = -6 - 16 * o; @@ -352,13 +369,34 @@ export default class PartyUiHandler extends MessageUiHandler { this.setCursor(0); } + doRelease(slotIndex: integer): void { + this.showText(this.getReleaseMessage(this.scene.getParty()[slotIndex].name), null, () => { + this.clearPartySlots(); + this.scene.removePartyMemberModifiers(slotIndex); + this.scene.getParty().splice(slotIndex, 1); + this.populatePartySlots(); + if (this.cursor >= this.scene.getParty().length) + this.setCursor(this.cursor - 1); + if (this.partyUiMode === PartyUiMode.RELEASE) { + const selectCallback = this.selectCallback; + this.selectCallback = null; + selectCallback(this.cursor); + } else + this.message.setText(defaultMessage); + }, null, true); + } + getReleaseMessage(pokemonName: string): string { const rand = Utils.randInt(128); - if (rand < 32) + if (rand < 20) return `Goodbye, ${pokemonName}!`; - else if (rand < 64) + else if (rand < 40) + return `Byebye, ${pokemonName}!`; + else if (rand < 60) return `Farewell, ${pokemonName}!`; - else if (rand < 96) + else if (rand < 80) + return `So long, ${pokemonName}!`; + else if (rand < 100) return `This is where we part, ${pokemonName}!`; else if (rand < 108) return `I'll miss you, ${pokemonName}!`; diff --git a/src/ui/ui.ts b/src/ui/ui.ts index f3bccb0478a..eaf57bf7271 100644 --- a/src/ui/ui.ts +++ b/src/ui/ui.ts @@ -17,9 +17,9 @@ export enum Mode { COMMAND, FIGHT, BALL, - CONFIRM, MODIFIER_SELECT, PARTY, + CONFIRM, SUMMARY, STARTER_SELECT, EVOLUTION_SCENE @@ -52,9 +52,9 @@ export default class UI extends Phaser.GameObjects.Container { new CommandUiHandler(scene), new FightUiHandler(scene), new BallUiHandler(scene), - new ConfirmUiHandler(scene), new ModifierSelectUiHandler(scene), new PartyUiHandler(scene), + new ConfirmUiHandler(scene), new SummaryUiHandler(scene), new StarterSelectUiHandler(scene), new EvolutionSceneHandler(scene)