From 647e0ff9df97051f416a8a702d9049f9d32e14fd Mon Sep 17 00:00:00 2001 From: Timothee Groleau Date: Sat, 30 Nov 2024 11:16:46 +0800 Subject: [PATCH] feat(rushroyale): handle winner when last top out --- public/views/mp/rushroyale.html | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/public/views/mp/rushroyale.html b/public/views/mp/rushroyale.html index 5ec5f57a..8c0ab802 100644 --- a/public/views/mp/rushroyale.html +++ b/public/views/mp/rushroyale.html @@ -495,7 +495,10 @@ toId = setTimeout(endCycle, duration * 1000); } + let endingCycle = false; + function endCycle() { + endingCycle = true; // figure out who to kick const num_kicked = kickPlayer(); @@ -507,13 +510,25 @@ // round is over reset(); } + + endingCycle = false; } - function kickPlayer() { + function kickPlayer(topOutPlayer) { const { sorted_players, active_players } = getSortedPlayers(); let cut_idx; + // special handling for top out players to ensure the winner is shown + if (topOutPlayer) { + if (active_players.length === 1) { + active_players[0].game?.end(); + active_players[0].playWinnerAnimation(); + reset(); + } + return; + } + if (active_players.length >= 2) { // grab all the tail players with the same score const lastPlayer = peek(active_players); @@ -668,7 +683,10 @@ this.dom.full_node.classList.add('eliminated'); this.dom.rank_node.classList.add('eliminated'); - updateScore(); + if (!endingCycle) { + updateScore(); + kickPlayer(this); + } }; player._playWinnerAnimation = player.playWinnerAnimation; @@ -705,8 +723,6 @@ } }; - // player.onGameOver(); - players.push(player); });