Fix crash in bestof when expiring battles

The main important change is that when `room.destroy()` is called
on an unfinished battle, `room.parent?.game?.onBattleWin?.()` is
now called (it was previously only called for tours, not bestof).

The rest is just about moving the relevant code to more sensible
places.
This commit is contained in:
Guangcong Luo 2024-01-15 00:40:18 -08:00
parent 7c103da51d
commit 6bccd4f622
2 changed files with 8 additions and 9 deletions

View File

@ -1239,7 +1239,10 @@ export class RoomBattle extends RoomGame<RoomBattlePlayer> {
}
override destroy() {
this.setEnded();
if (!this.ended) {
this.setEnded();
this.room.parent?.game?.onBattleWin?.(this.room, '');
}
for (const player of this.players) {
player.destroy();
}

View File

@ -1106,9 +1106,10 @@ export abstract class BasicRoom {
destroy(): void {
// deallocate ourself
if (this.battle && this.tour) {
// resolve state of the tournament;
if (!this.battle.ended) this.tour.onBattleWin(this as any as GameRoom, '');
if (this.game) {
this.game.destroy();
this.game = null;
this.battle = null;
this.tour = null;
}
@ -1132,11 +1133,6 @@ export abstract class BasicRoom {
}
}
if (this.game) {
this.game.destroy();
this.game = null;
this.battle = null;
}
this.active = false;
// Ensure there aren't any pending messages that could restart the expire timer