Some fixes before Alpha
This commit is contained in:
@@ -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),
|
||||
|
||||
@@ -146,9 +146,11 @@ export class GameService {
|
||||
game: Document<Game> & 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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -77,6 +77,7 @@ export function WithTransaction(
|
||||
if (e instanceof HttpException) {
|
||||
throw e;
|
||||
}
|
||||
console.log(e);
|
||||
reject(
|
||||
new HttpException(
|
||||
'Another request is processing',
|
||||
|
||||
Reference in New Issue
Block a user