Skip to content

Commit

Permalink
Cannot draw cards if the deck doesn't have enough cards to draw.
Browse files Browse the repository at this point in the history
  • Loading branch information
kberg committed Feb 13, 2025
1 parent ad345cd commit 7349a40
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/server/behavior/Executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ export class Executor implements BehaviorExecutor {
}
}

if (behavior.drawCard !== undefined) {
const drawCard = behavior.drawCard;
const count = typeof(drawCard) === 'number' ? drawCard : ctx.count(drawCard.count);
if (game.projectDeck.canDraw(count) === false) {
return false;
}
}

if (behavior.global !== undefined) {
const g = behavior.global;
if (g.temperature !== undefined && game.getTemperature() >= MAX_TEMPERATURE) {
Expand Down
15 changes: 15 additions & 0 deletions tests/cards/base/BusinessContacts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,19 @@ describe('BusinessContacts', () => {
expect(player.cardsInHand).deep.eq([card1, card2]);
expect(game.projectDeck.discardPile).deep.eq([card3, card4]);
});

it('Cannot draw when the deck is empty', () => {
const card = new BusinessContacts();
const [game, player] = testGame(2);

game.projectDeck.discardPile.length = 0;
game.projectDeck.drawPile.length = 5;
expect(card.canPlay(player)).is.true;
game.projectDeck.drawPile.length = 4;
expect(card.canPlay(player)).is.true;
game.projectDeck.drawPile.length = 3;
expect(card.canPlay(player)).is.false;
game.projectDeck.drawPile.length = 2;
expect(card.canPlay(player)).is.false;
});
});

0 comments on commit 7349a40

Please sign in to comment.