Fix some bugs with double battle switching

This commit is contained in:
Flashfyre 2023-05-31 12:38:55 -04:00
parent 95f35fd2f7
commit 47fd9985c8
2 changed files with 24 additions and 12 deletions

View File

@ -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();

View File

@ -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: