Skip to content

Commit

Permalink
Fixed a bug where multi-select cards would not work correctly (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroclutch authored Jan 13, 2025
1 parent 3f1c4f3 commit b77bad7
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions games/Cards Against Humanity/classes/CardsAgainstHumanity.js
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ export default class CardsAgainstHumanity extends Game {
// Only select single-blanks
do {
this.blackCard = new BlackCard(this.cardDeck.draw('black')[0])
} while(this.blackCard.responses > 1 || !this.blackCard.text || this.blackCard.text.length == 0)
} while(!this.blackCard.text || this.blackCard.text.length == 0)
if(!this.blackCard.text) {
logger.error('Error: card loaded with no text')
}
Expand Down Expand Up @@ -679,8 +679,7 @@ export default class CardsAgainstHumanity extends Game {
// await X messages, depending on how many white cards are needed
let selectionCollector = this.channel.createMessageCollector({ filter: messageFilter, time: this.settings.timeLimit });

let lastSubmissionStatus = this.renderSubmissionStatus()

this.czar.submitted = true
selectionCollector.on('collect', async m => {
if(this.ending) return

Expand All @@ -692,17 +691,26 @@ export default class CardsAgainstHumanity extends Game {
m.delete().catch(logger.error.bind(logger))
}

// save selection for one card
this.submittedCards.push({
player,
card: [player.cards[cardRemoved]]
})
player.submitted = true
// Add player submissions to the list
let submission = this.submittedCards.find(submission => submission.player.user.id == player.user.id)
if(!submission) {
submission = {
player,
card: [player.cards[cardRemoved]]
}
this.submittedCards.push(submission)
} else {
submission.card.push(player.cards[cardRemoved])
}

if(submission.card.length == this.blackCard.responses) {
player.submitted = true
}

// remove cards from hand
player.cards.splice(cardRemoved, 1, '')

if(this.submittedCards.length == this.players.size - 1) {
if(this.players.every(p => p.submitted)) {
selectionCollector.stop()

// Clean up submission status message
Expand Down

0 comments on commit b77bad7

Please sign in to comment.