Skip to content

Commit

Permalink
feat(rushroyale): handle winner when last top out
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheeg committed Nov 30, 2024
1 parent 69689f4 commit 647e0ff
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions public/views/mp/rushroyale.html
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -705,8 +723,6 @@
}
};

// player.onGameOver();

players.push(player);
});

Expand Down

0 comments on commit 647e0ff

Please sign in to comment.