diff --git a/src/games/controllers/turn.controller.ts b/src/games/controllers/turn.controller.ts index c9033f5..aeae8e1 100644 --- a/src/games/controllers/turn.controller.ts +++ b/src/games/controllers/turn.controller.ts @@ -275,6 +275,12 @@ export class TurnController { CardEffects.PLAY_NEXT_CARD_BOUGHT, ]; + const discardTokens = [ + CardEffects.RESTACK_DISCARDED_ACTION, + CardEffects.RESTACK_DISCARDED_CARD, + CardEffects.RESTACK_DISCARDED_CHAMPION, + ]; + let targetCard: Card; let targetPlayer = currentPlayer; if (enemyTargetTokens.includes(token.effect)) { @@ -286,6 +292,10 @@ export class TurnController { targetCard = game.market.cards.find((c) => c._id.equals(useTokenDto.cardId)) ?? game.fireGems.cards.find((c) => c._id.equals(useTokenDto.cardId)); + } else if (discardTokens.includes(token.effect)) { + targetCard = targetPlayer.discard.cards.find((c) => + c._id.equals(useTokenDto.cardId), + ); } else { targetCard = currentPlayer.board.cards.find((c) => c._id.equals(useTokenDto.cardId), diff --git a/src/games/services/games.service.ts b/src/games/services/games.service.ts index 62a8188..6c9579f 100644 --- a/src/games/services/games.service.ts +++ b/src/games/services/games.service.ts @@ -146,9 +146,11 @@ export class GameService { game: Document & Game, session?: mongoose.mongo.ClientSession, ) { + const shallow = [...from.cards]; + shallow.reverse(); if (amount <= from.cards.length) { await this.distributeCards( - from.cards.slice(0, amount), + shallow.slice(0, amount), from, to, game, @@ -159,7 +161,7 @@ export class GameService { } else { const toDraw = from.cards.length; await this.distributeCards( - from.cards.slice(0, toDraw), + shallow.slice(0, toDraw), from, to, game, @@ -278,14 +280,14 @@ export class GameService { ) { const index = game.teams.findIndex((t) => t._id.equals(team._id)); game.teams.splice(index, 1); - if (game.teams.length <= 1) { - await this.endGame(game, session); - } this.eventEmitter.emit('sse.game.' + game._id.toHexString(), { type: 'killTeam', teamId: team._id, }); await game.save({ session }); + if (game.teams.length <= 1) { + await this.endGame(game, session); + } } @WithTransaction diff --git a/src/games/services/turn.service.ts b/src/games/services/turn.service.ts index 0d95711..6c0bb03 100644 --- a/src/games/services/turn.service.ts +++ b/src/games/services/turn.service.ts @@ -313,12 +313,10 @@ export class TurnService { health: team.health, operation: -amount, }); - - if (team.health <= 0) { - this.gamesService.killTeam(game, team, session); - } - await game.save({ session }); + if (team.health <= 0) { + await this.gamesService.killTeam(game, team, session); + } } @WithTransaction diff --git a/src/games/utils.ts b/src/games/utils.ts index 3b39964..0a08deb 100644 --- a/src/games/utils.ts +++ b/src/games/utils.ts @@ -77,6 +77,7 @@ export function WithTransaction( if (e instanceof HttpException) { throw e; } + console.log(e); reject( new HttpException( 'Another request is processing',