Fix crash when trainer has no encounter or victory messages

pull/16/head
Flashfyre 2024-02-14 15:33:02 -05:00
parent 74f9c51188
commit 6d8ea0ad79
2 changed files with 3 additions and 3 deletions

View File

@ -580,7 +580,7 @@ export class EncounterPhase extends BattlePhase {
const encounterMessages = this.scene.currentBattle.trainer.getEncounterMessages();
if (!encounterMessages.length)
if (!encounterMessages?.length)
doSummon();
else {
let message: string;
@ -2746,7 +2746,7 @@ export class TrainerVictoryPhase extends BattlePhase {
this.scene.ui.showText(`You defeated\n${this.scene.currentBattle.trainer.getName(true)}!`, null, () => {
const victoryMessages = this.scene.currentBattle.trainer.getVictoryMessages();
let showMessageAndEnd = () => this.end();
if (victoryMessages.length) {
if (victoryMessages?.length) {
let message: string;
this.scene.executeWithSeedOffset(() => message = Phaser.Math.RND.pick(victoryMessages), this.scene.currentBattle.waveIndex);
const messagePages = message.split(/\$/g).map(m => m.trim());

View File

@ -126,7 +126,7 @@ export default class Battle {
getBgmOverride(scene: BattleScene): string {
const battlers = this.enemyParty.slice(0, this.getBattlerCount());
if (this.battleType === BattleType.TRAINER) {
if (!this.started && this.trainer.config.encounterBgm && this.trainer.getEncounterMessages().length)
if (!this.started && this.trainer.config.encounterBgm && this.trainer.getEncounterMessages()?.length)
return `encounter_${this.trainer.getEncounterBgm()}`;
return this.trainer.getBattleBgm();
} else if (this.gameMode === GameMode.CLASSIC && this.waveIndex > 195 && this.battleSpec !== BattleSpec.FINAL_BOSS)