Skip to content
This repository has been archived by the owner on Jan 31, 2021. It is now read-only.

Commit

Permalink
Fix draw 11 bug (hopefully), fix player count with bot
Browse files Browse the repository at this point in the history
  • Loading branch information
lilyissillyyy committed Aug 17, 2018
1 parent 9c144b5 commit 34d8575
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 17 deletions.
6 changes: 3 additions & 3 deletions commands/games/apples-to-apples.js
Original file line number Diff line number Diff line change
Expand Up @@ -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...');
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions commands/games/cards-against-humanity.js
Original file line number Diff line number Diff line change
Expand Up @@ -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...');
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
14 changes: 5 additions & 9 deletions structures/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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 = [];
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion util/Collectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down

0 comments on commit 34d8575

Please sign in to comment.