Some fixes before Alpha

This commit is contained in:
2024-07-14 15:54:08 +02:00
parent 14e8f5c089
commit d361a7a599
4 changed files with 21 additions and 10 deletions
+10
View File
@@ -275,6 +275,12 @@ export class TurnController {
CardEffects.PLAY_NEXT_CARD_BOUGHT, CardEffects.PLAY_NEXT_CARD_BOUGHT,
]; ];
const discardTokens = [
CardEffects.RESTACK_DISCARDED_ACTION,
CardEffects.RESTACK_DISCARDED_CARD,
CardEffects.RESTACK_DISCARDED_CHAMPION,
];
let targetCard: Card; let targetCard: Card;
let targetPlayer = currentPlayer; let targetPlayer = currentPlayer;
if (enemyTargetTokens.includes(token.effect)) { if (enemyTargetTokens.includes(token.effect)) {
@@ -286,6 +292,10 @@ export class TurnController {
targetCard = targetCard =
game.market.cards.find((c) => c._id.equals(useTokenDto.cardId)) ?? game.market.cards.find((c) => c._id.equals(useTokenDto.cardId)) ??
game.fireGems.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 { } else {
targetCard = currentPlayer.board.cards.find((c) => targetCard = currentPlayer.board.cards.find((c) =>
c._id.equals(useTokenDto.cardId), c._id.equals(useTokenDto.cardId),
+7 -5
View File
@@ -146,9 +146,11 @@ export class GameService {
game: Document<Game> & Game, game: Document<Game> & Game,
session?: mongoose.mongo.ClientSession, session?: mongoose.mongo.ClientSession,
) { ) {
const shallow = [...from.cards];
shallow.reverse();
if (amount <= from.cards.length) { if (amount <= from.cards.length) {
await this.distributeCards( await this.distributeCards(
from.cards.slice(0, amount), shallow.slice(0, amount),
from, from,
to, to,
game, game,
@@ -159,7 +161,7 @@ export class GameService {
} else { } else {
const toDraw = from.cards.length; const toDraw = from.cards.length;
await this.distributeCards( await this.distributeCards(
from.cards.slice(0, toDraw), shallow.slice(0, toDraw),
from, from,
to, to,
game, game,
@@ -278,14 +280,14 @@ export class GameService {
) { ) {
const index = game.teams.findIndex((t) => t._id.equals(team._id)); const index = game.teams.findIndex((t) => t._id.equals(team._id));
game.teams.splice(index, 1); game.teams.splice(index, 1);
if (game.teams.length <= 1) {
await this.endGame(game, session);
}
this.eventEmitter.emit('sse.game.' + game._id.toHexString(), { this.eventEmitter.emit('sse.game.' + game._id.toHexString(), {
type: 'killTeam', type: 'killTeam',
teamId: team._id, teamId: team._id,
}); });
await game.save({ session }); await game.save({ session });
if (game.teams.length <= 1) {
await this.endGame(game, session);
}
} }
@WithTransaction @WithTransaction
+3 -5
View File
@@ -313,12 +313,10 @@ export class TurnService {
health: team.health, health: team.health,
operation: -amount, operation: -amount,
}); });
if (team.health <= 0) {
this.gamesService.killTeam(game, team, session);
}
await game.save({ session }); await game.save({ session });
if (team.health <= 0) {
await this.gamesService.killTeam(game, team, session);
}
} }
@WithTransaction @WithTransaction
+1
View File
@@ -77,6 +77,7 @@ export function WithTransaction(
if (e instanceof HttpException) { if (e instanceof HttpException) {
throw e; throw e;
} }
console.log(e);
reject( reject(
new HttpException( new HttpException(
'Another request is processing', 'Another request is processing',