From 63192b49608ae650e5a25b2f36ee2d34065419ee Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Sun, 22 Nov 2020 11:16:29 -0500 Subject: [PATCH] Fix/Testing --- commands/games-mp/poker.js | 10 +++++++--- util/Util.js | 6 ++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/commands/games-mp/poker.js b/commands/games-mp/poker.js index 0cbcb8e2..157e4ff6 100644 --- a/commands/games-mp/poker.js +++ b/commands/games-mp/poker.js @@ -3,7 +3,7 @@ const Collection = require('@discordjs/collection'); const { Hand } = require('pokersolver'); const { stripIndents } = require('common-tags'); const Deck = require('../../structures/cards/Deck'); -const { formatNumber, list, delay, awaitPlayers } = require('../../util/Util'); +const { formatNumber, list, delay, removeFromArray, awaitPlayers } = require('../../util/Util'); const max = 6; const min = 2; const bigBlindAmount = 100; @@ -65,7 +65,7 @@ module.exports = class PokerCommand extends Command { }); } let winner = null; - const rotation = players.map(p => p.id); + let rotation = players.map(p => p.id); while (!winner) { const bigBlind = players.get(rotation[1]); bigBlind.money -= bigBlindAmount; @@ -165,7 +165,11 @@ module.exports = class PokerCommand extends Command { winners[0].user.money += turnData.pot; } await this.resetGame(msg, players, deck); - if (players.size <= 1) { + for (const playerID of rotation) { + if (!players.has(playerID)) removeFromArray(rotation, playerID); + } + console.log(players.size); + if (players.size < 2) { winner = players.first(); break; } diff --git a/util/Util.js b/util/Util.js index b7a41e9f..9baf97e7 100644 --- a/util/Util.js +++ b/util/Util.js @@ -48,6 +48,12 @@ module.exports = class Util { return arr; } + static removeFromArray(arr, value) { + const index = arr.indexOf(value); + if (index > -1) return arr.splice(index, 1); + return arr; + } + static removeDuplicates(arr) { if (arr.length === 0 || arr.length === 1) return arr; const newArr = [];