Fix : end turn and draw cards

This commit is contained in:
2024-06-11 21:51:19 -04:00
parent da7262fbeb
commit e18343ee93
+7 -4
View File
@@ -35,6 +35,8 @@ export class GameService {
player.discard, player.discard,
game, game,
); );
await this.drawToHand(5, player, game);
} }
const index = game.teams.indexOf(currentTurn); const index = game.teams.indexOf(currentTurn);
@@ -87,7 +89,7 @@ export class GameService {
discard: Container, discard: Container,
game: Document<Game> & Game, game: Document<Game> & Game,
) { ) {
if (amount >= from.cards.length) { if (amount <= from.cards.length) {
await this.distributeCards(from.cards.slice(0, amount), from, to, game); await this.distributeCards(from.cards.slice(0, amount), from, to, game);
await game.save(); await game.save();
return; return;
@@ -126,17 +128,18 @@ export class GameService {
HttpStatus.NOT_FOUND, HttpStatus.NOT_FOUND,
); );
} }
for (const c of cards) { const shallow = [...cards];
for (const c of shallow) {
const index = from.cards.indexOf(c); const index = from.cards.indexOf(c);
from.cards.splice(index, 1); from.cards.splice(index, 1);
to.cards.push(c); to.cards.push(c);
} }
await game.save();
this.eventEmitter.emit('sse.game.' + game._id.toHexString(), { this.eventEmitter.emit('sse.game.' + game._id.toHexString(), {
type: 'distributeCards', type: 'distributeCards',
from: from._id.toHexString(), from: from._id.toHexString(),
to: to._id.toHexString(), to: to._id.toHexString(),
cards: cards, cards: shallow,
}); });
await game.save();
} }
} }