Skip to content

Commit

Permalink
Chansey's Egg Toss: fix ending on player removal (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
dot-Comfey authored Apr 17, 2024
1 parent 6b9335a commit 2b514ec
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/games/chanseys-egg-toss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class ChanseysEggToss extends ScriptedGame {
this.currentHolder = player;
this.explodeEgg(reason);
} else {
this.eliminatePlayer(player);
this.say(player.name + " was DQed " + reason + "!");
this.eliminatePlayer(player);
}
}

Expand All @@ -44,12 +44,16 @@ class ChanseysEggToss extends ScriptedGame {
}

onRemovePlayer(player: Player): void {
if (this.currentHolder && this.getRemainingPlayerCount() < 2) {
if (this.getRemainingPlayerCount() < 2) {
this.say(player.name + " left the game!");
this.end();
}
}

onEliminatePlayer(): void {
if (this.getRemainingPlayerCount() < 2) this.end();
}

giveEgg(player: Player): void {
const previousHolder = this.currentHolder;

Expand Down Expand Up @@ -77,16 +81,10 @@ class ChanseysEggToss extends ScriptedGame {
this.currentHolder = null;
}

if (this.getRemainingPlayerCount() < 2) return this.end();
this.setTimeout(() => void this.nextRound(), 5000);
}

async onNextRound(): Promise<void> { // eslint-disable-line @typescript-eslint/require-await
const remainingPlayerCount = this.getRemainingPlayerCount();
if (remainingPlayerCount < 2) {
return this.end();
}

this.spamTosses.clear();

const html = this.getRoundHtml(players => this.getPlayerNames(players));
Expand All @@ -97,7 +95,7 @@ class ChanseysEggToss extends ScriptedGame {
const eggText = "Chansey handed the egg to **" + holder.name + "**!";
this.on(eggText, () => {
let time: number;
if (remainingPlayerCount === 2) {
if (this.getRemainingPlayerCount() === 2) {
time = 5000;
} else {
time = this.sampleOne(this.roundTimes);
Expand Down

0 comments on commit 2b514ec

Please sign in to comment.