From 34d8575acdb7b83d52c416d3c535b305221ee7a9 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Fri, 17 Aug 2018 10:17:54 +0000 Subject: [PATCH] Fix draw 11 bug (hopefully), fix player count with bot --- commands/games/apples-to-apples.js | 6 +++--- commands/games/cards-against-humanity.js | 6 +++--- package.json | 2 +- structures/Player.js | 14 +++++--------- util/Collectors.js | 2 +- 5 files changed, 13 insertions(+), 17 deletions(-) diff --git a/commands/games/apples-to-apples.js b/commands/games/apples-to-apples.js index 21aa562..df32f8f 100644 --- a/commands/games/apples-to-apples.js +++ b/commands/games/apples-to-apples.js @@ -52,7 +52,7 @@ module.exports = class ApplesToApplesCommand extends Command { await msg.util.sendNew( `You will need at least ${bot ? 1 : 2} more player${bot ? '' : 's'}. To join, type \`join game\`.` ); - const awaitedPlayers = await awaitPlayers(msg, 10, bot ? 2 : 3); + const awaitedPlayers = await awaitPlayers(msg, bot ? 9 : 10, bot ? 2 : 3); if (!awaitedPlayers) { this.client.playing.delete(msg.channel.id); return msg.util.sendNew('Game could not be started...'); @@ -62,13 +62,13 @@ module.exports = class ApplesToApplesCommand extends Command { const players = new Collection(); for (const user of awaitedPlayers) { const player = new Player(user); - player.dealHand(redDeck, 10); + player.dealHand(redDeck); players.set(player.id, player); } const czars = players.map(player => player.id); if (bot) { const player = new Player(this.client.user); - player.dealHand(redDeck, 10); + player.dealHand(redDeck); players.set(player.id, player); } let winner = null; diff --git a/commands/games/cards-against-humanity.js b/commands/games/cards-against-humanity.js index 8d9f4cf..6505ca4 100644 --- a/commands/games/cards-against-humanity.js +++ b/commands/games/cards-against-humanity.js @@ -52,7 +52,7 @@ module.exports = class CardsAgainstHumanityCommand extends Command { await msg.util.sendNew( `You will need at least ${bot ? 1 : 2} more player${bot ? '' : 's'}. To join, type \`join game\`.` ); - const awaitedPlayers = await awaitPlayers(msg, 10, bot ? 2 : 3); + const awaitedPlayers = await awaitPlayers(msg, bot ? 9 : 10, bot ? 2 : 3); if (!awaitedPlayers) { this.client.playing.delete(msg.channel.id); return msg.util.sendNew('Game could not be started...'); @@ -62,13 +62,13 @@ module.exports = class CardsAgainstHumanityCommand extends Command { const players = new Collection(); for (const user of awaitedPlayers) { const player = new Player(user); - player.dealHand(whiteDeck, 10); + player.dealHand(whiteDeck); players.set(player.id, player); } const czars = players.map(player => player.id); if (bot) { const player = new Player(this.client.user); - player.dealHand(whiteDeck, 10); + player.dealHand(whiteDeck); players.set(player.id, player); } let winner = null; diff --git a/package.json b/package.json index 8fd9702..983abcb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cards-against-humanity", - "version": "2.1.0", + "version": "2.1.1", "description": "Cards Against Humanity, but for Discord!", "main": "CAH.js", "scripts": { diff --git a/structures/Player.js b/structures/Player.js index 60c17b2..d9a4403 100644 --- a/structures/Player.js +++ b/structures/Player.js @@ -10,13 +10,9 @@ module.exports = class Player { this.strikes = 0; } - dealHand(deck, amount) { - if (amount <= 0) return this.hand; - if (amount > 1) { - for (let i = 0; i < amount; i++) this.hand.add(deck.draw()); - } else { - this.hand.add(deck.draw()); - } + dealHand(deck) { + if (this.hand.size > 9) return this.hand; + for (let i = 0; i < 10 - this.hand.size; i++) this.hand.add(deck.draw()); return this.hand; } @@ -31,7 +27,7 @@ module.exports = class Player { async turn(channel, czar, black, deck, chosenCards) { if (this.user.id === czar.user.id) return; - this.dealHand(deck, 10 - this.hand.size); + this.dealHand(deck); const hand = Array.from(this.hand); if (this.user.bot) { const chosen = []; @@ -73,7 +69,7 @@ module.exports = class Player { this.points--; await this.user.send('Swapping cards...'); for (const card of this.hand) this.hand.delete(card); - this.dealHand(deck, 10); + this.dealHand(deck); return this.turn(channel, czar, black, deck, chosenCards); // eslint-disable-line consistent-return } if (choices.size < black.pick) { diff --git a/util/Collectors.js b/util/Collectors.js index 750a1c8..e4fff03 100644 --- a/util/Collectors.js +++ b/util/Collectors.js @@ -45,7 +45,7 @@ module.exports = class CollectorsUtil { collector.on('collect', msg => { if (msg.content.toLowerCase() === 'join game') { const player = new Player(msg.author); - player.dealHand(whiteDeck, 10); + player.dealHand(whiteDeck); players.set(player.id, player); czars.push(player.id); } else if (msg.content.toLowerCase() === 'leave game') {