Fix : various inconsistencies for effects

This commit is contained in:
2024-07-14 00:19:40 +02:00
parent af2965edea
commit b24975b148
3 changed files with 31 additions and 3 deletions
+4 -2
View File
@@ -192,7 +192,7 @@ export class TurnController {
} }
const targetPlayer = findPlayer(_playerId, game); const targetPlayer = findPlayer(_playerId, game);
if (!isInTeam(currentTeam, targetPlayer)) { if (isInTeam(currentTeam, targetPlayer)) {
throw new HttpException( throw new HttpException(
'You cannot target players in the same team as yours', 'You cannot target players in the same team as yours',
HttpStatus.FORBIDDEN, HttpStatus.FORBIDDEN,
@@ -324,7 +324,7 @@ export class TurnController {
); );
} }
const targetPlayer = findPlayer(damageChampion.player, game); const targetPlayer = findPlayer(damageChampion.playerId, game);
if (!targetPlayer) { if (!targetPlayer) {
throw new HttpException('Player not found', HttpStatus.NOT_FOUND); throw new HttpException('Player not found', HttpStatus.NOT_FOUND);
} }
@@ -338,5 +338,7 @@ export class TurnController {
HttpStatus.NOT_FOUND, HttpStatus.NOT_FOUND,
); );
} }
await this.turnService.damageChampion(game, targetPlayer, card);
} }
} }
+1 -1
View File
@@ -2,5 +2,5 @@ import { ApiProperty } from '@nestjs/swagger';
export class DamageChampionDTO { export class DamageChampionDTO {
@ApiProperty() @ApiProperty()
player: string; playerId: string;
} }
+26
View File
@@ -307,4 +307,30 @@ export class TurnService {
await game.save({ session }); await game.save({ session });
} }
@WithTransaction
async damageChampion(
game: Document<Game> & Game,
targetPlayer: Player,
targetCard: Card,
session?: mongoose.mongo.ClientSession,
) {
game.currentTurn.damage -= targetCard.defense;
this.eventEmitter.emit('sse.game.' + game._id.toHexString(), {
type: 'currentTurn.updateDamage',
damage: game.currentTurn.damage,
operation: -targetCard.defense,
});
await this.gamesService.distributeCards(
[targetCard],
targetPlayer.board,
targetPlayer.discard,
game,
session,
);
await game.save({ session });
}
} }