diff --git a/src/battle-phases.ts b/src/battle-phases.ts index 294bbe266ab..9eb61b06d85 100644 --- a/src/battle-phases.ts +++ b/src/battle-phases.ts @@ -453,6 +453,15 @@ export class SummonPhase extends PartyMemberPokemonPhase { } preSummon(): void { + const partyMember = this.getPokemon(); + if (partyMember.isFainted()) { + const party = this.scene.getParty(); + const nonFaintedIndex = party.slice(this.partyMemberIndex).findIndex(p => !p.isFainted()) + this.partyMemberIndex; + const nonFaintedPartyMember = party[nonFaintedIndex]; + party[nonFaintedIndex] = partyMember; + party[this.partyMemberIndex] = nonFaintedPartyMember; + } + this.scene.ui.showText(`Go! ${this.getPokemon().name}!`); this.scene.trainer.play('trainer_m_pb'); this.scene.tweens.add({ @@ -478,8 +487,6 @@ export class SummonPhase extends PartyMemberPokemonPhase { const fpOffset = playerPokemon.getFieldPositionOffset(); - console.log(fpOffset); - pokeball.setVisible(true); this.scene.tweens.add({ @@ -563,7 +570,7 @@ export class SwitchSummonPhase extends SummonPhase { } preSummon(): void { - if (!this.doReturn) { + if (!this.doReturn || !this.scene.getParty()[this.slotIndex]) { this.switchAndSummon(); return; } @@ -594,7 +601,7 @@ export class SwitchSummonPhase extends SummonPhase { const party = this.scene.getParty(); const switchedPokemon = party[this.slotIndex]; this.lastPokemon = this.getPokemon(); - if (this.batonPass) { + if (this.batonPass && switchedPokemon) { this.scene.getEnemyField().forEach(enemyPokemon => enemyPokemon.transferTagsBySourceId(this.lastPokemon.id, switchedPokemon.id)); if (!this.scene.findModifier(m => m instanceof SwitchEffectTransferModifier && (m as SwitchEffectTransferModifier).pokemonId === switchedPokemon.id)) { const batonPassModifier = this.scene.findModifier(m => m instanceof SwitchEffectTransferModifier @@ -602,15 +609,20 @@ export class SwitchSummonPhase extends SummonPhase { this.scene.tryTransferHeldItemModifier(batonPassModifier, switchedPokemon, false, false); } } - party[this.slotIndex] = this.lastPokemon; - party[this.fieldIndex] = switchedPokemon; - this.scene.ui.showText(`Go! ${switchedPokemon.name}!`); - this.summon(); + if (switchedPokemon) { + party[this.slotIndex] = this.lastPokemon; + party[this.fieldIndex] = switchedPokemon; + this.scene.ui.showText(`Go! ${switchedPokemon.name}!`); + this.summon(); + } else + this.end(); } end() { - if (this.batonPass) - this.getPokemon().transferSummon(this.lastPokemon); + const pokemon = this.getPokemon(); + + if (this.batonPass && pokemon) + pokemon.transferSummon(this.lastPokemon); this.lastPokemon?.resetSummonData(); diff --git a/src/ui/command-ui-handler.ts b/src/ui/command-ui-handler.ts index 2882b495d50..d4c6498303c 100644 --- a/src/ui/command-ui-handler.ts +++ b/src/ui/command-ui-handler.ts @@ -2,7 +2,7 @@ import { CommandPhase } from "../battle-phases"; import BattleScene, { Button } from "../battle-scene"; import { addTextObject, TextStyle } from "./text"; import { toPokemonUpperCase } from "../utils"; -import { PartyUiMode } from "./party-ui-handler"; +import PartyUiHandler, { PartyUiMode } from "./party-ui-handler"; import UI, { Mode } from "./ui"; import UiHandler from "./uiHandler"; @@ -65,7 +65,7 @@ export default class CommandUiHandler extends UiHandler { success = true; break; case 2: - ui.setMode(Mode.PARTY, PartyUiMode.SWITCH, (this.scene.getCurrentPhase() as CommandPhase).getPokemon().getFieldIndex()); + ui.setMode(Mode.PARTY, PartyUiMode.SWITCH, (this.scene.getCurrentPhase() as CommandPhase).getPokemon().getFieldIndex(), null, PartyUiHandler.FilterNonFainted); success = true; break; case 3: