Chore : various fixes

This commit is contained in:
2024-07-14 14:49:24 +02:00
parent b24975b148
commit 14e8f5c089
7 changed files with 225 additions and 14 deletions
@@ -66,6 +66,12 @@ export class GamesController {
HttpStatus.FORBIDDEN, HttpStatus.FORBIDDEN,
); );
} }
if (currentPlayer.discardMarkers || currentPlayer.fuckUMarkers) {
throw new HttpException(
'You must consume all your discard markers before ending your turn',
HttpStatus.FORBIDDEN,
);
}
await this.gameService.endTurn(game); await this.gameService.endTurn(game);
} }
+94 -2
View File
@@ -61,6 +61,12 @@ export class TurnController {
HttpStatus.FORBIDDEN, HttpStatus.FORBIDDEN,
); );
} }
if (currentPlayer.discardMarkers || currentPlayer.fuckUMarkers) {
throw new HttpException(
'You cannot lock a card while having discard markers',
HttpStatus.BAD_REQUEST,
);
}
if (game.currentTurn.cardsLocked.some((c) => c._id.equals(card._id))) { if (game.currentTurn.cardsLocked.some((c) => c._id.equals(card._id))) {
throw new HttpException('Card already locked', HttpStatus.BAD_REQUEST); throw new HttpException('Card already locked', HttpStatus.BAD_REQUEST);
} }
@@ -92,6 +98,12 @@ export class TurnController {
HttpStatus.FORBIDDEN, HttpStatus.FORBIDDEN,
); );
} }
if (currentPlayer.discardMarkers || currentPlayer.fuckUMarkers) {
throw new HttpException(
'You cannot buy a card while having discard markers',
HttpStatus.BAD_REQUEST,
);
}
if (!game.market.cards.some((c) => c._id.equals(card._id))) { if (!game.market.cards.some((c) => c._id.equals(card._id))) {
throw new HttpException( throw new HttpException(
'Card not in current game market', 'Card not in current game market',
@@ -126,6 +138,12 @@ export class TurnController {
HttpStatus.FORBIDDEN, HttpStatus.FORBIDDEN,
); );
} }
if (currentPlayer.discardMarkers || currentPlayer.fuckUMarkers) {
throw new HttpException(
'You cannot buy a card while having discard markers',
HttpStatus.BAD_REQUEST,
);
}
if (game.fireGems.cards.length < 1) { if (game.fireGems.cards.length < 1) {
throw new HttpException('No Gems left', HttpStatus.NOT_FOUND); throw new HttpException('No Gems left', HttpStatus.NOT_FOUND);
} }
@@ -156,6 +174,12 @@ export class TurnController {
HttpStatus.FORBIDDEN, HttpStatus.FORBIDDEN,
); );
} }
if (currentPlayer.discardMarkers || currentPlayer.fuckUMarkers) {
throw new HttpException(
'You cannot lock an effect while having discard markers',
HttpStatus.BAD_REQUEST,
);
}
if (game.currentTurn.lockedEffects.some((e) => e._id.equals(effect._id))) { if (game.currentTurn.lockedEffects.some((e) => e._id.equals(effect._id))) {
throw new HttpException('Effect already locked', HttpStatus.BAD_REQUEST); throw new HttpException('Effect already locked', HttpStatus.BAD_REQUEST);
} }
@@ -206,6 +230,14 @@ export class TurnController {
throw new HttpException('Token not found', HttpStatus.NOT_FOUND); throw new HttpException('Token not found', HttpStatus.NOT_FOUND);
} }
await this.turnService.makeDiscard(game, targetToken, targetPlayer); await this.turnService.makeDiscard(game, targetToken, targetPlayer);
const index = game.currentTurn.tokens.findIndex((t) =>
t._id.equals(targetToken._id),
);
game.currentTurn.tokens.splice(index, 1);
this.eventEmitter.emit('sse.game.' + game._id.toHexString(), {
type: 'currentTurn.useToken',
tokenId: targetToken._id.toHexString(),
});
} }
@Post('useToken/:tokenId') @Post('useToken/:tokenId')
@@ -227,6 +259,7 @@ export class TurnController {
HttpStatus.FORBIDDEN, HttpStatus.FORBIDDEN,
); );
} }
if (!game.currentTurn.tokens.some((t) => t._id.equals(token._id))) { if (!game.currentTurn.tokens.some((t) => t._id.equals(token._id))) {
throw new HttpException('Token not found', HttpStatus.NOT_FOUND); throw new HttpException('Token not found', HttpStatus.NOT_FOUND);
} }
@@ -239,6 +272,7 @@ export class TurnController {
const marketTokens = [ const marketTokens = [
CardEffects.STACK_NEXT_ACTION_BOUGHT, CardEffects.STACK_NEXT_ACTION_BOUGHT,
CardEffects.STACK_NEXT_CARD_BOUGHT, CardEffects.STACK_NEXT_CARD_BOUGHT,
CardEffects.PLAY_NEXT_CARD_BOUGHT,
]; ];
let targetCard: Card; let targetCard: Card;
@@ -258,9 +292,18 @@ export class TurnController {
); );
} }
if (!targetCard) { if (token.effect != CardEffects.DRAW_AND_DISCARD) {
throw new HttpException('Card not found', HttpStatus.NOT_FOUND); if (currentPlayer.discardMarkers || currentPlayer.fuckUMarkers) {
throw new HttpException(
'You cannot use a token while having discard markers',
HttpStatus.BAD_REQUEST,
);
}
if (!targetCard) {
throw new HttpException('Card not found', HttpStatus.NOT_FOUND);
}
} }
await this.turnService.useToken(game, targetPlayer, token, targetCard); await this.turnService.useToken(game, targetPlayer, token, targetCard);
} }
@@ -290,6 +333,12 @@ export class TurnController {
} }
const targetPlayer = findPlayer(playerId, game); const targetPlayer = findPlayer(playerId, game);
if (targetPlayer.board.cards.some((c) => c.guard)) {
throw new HttpException(
'You cannot target this player while there is a guard',
HttpStatus.BAD_REQUEST,
);
}
await this.turnService.damagePlayer( await this.turnService.damagePlayer(
game, game,
damagePlayerDTO.amount, damagePlayerDTO.amount,
@@ -339,6 +388,49 @@ export class TurnController {
); );
} }
if (!card.guard) {
if (targetPlayer.board.cards.some((c) => c.guard)) {
throw new HttpException(
'You cannot target this champion while there is a guard',
HttpStatus.BAD_REQUEST,
);
}
}
await this.turnService.damageChampion(game, targetPlayer, card); await this.turnService.damageChampion(game, targetPlayer, card);
} }
@Post('discardCard/:cardId')
@ApiOperation({
summary: 'Discard a card if you have fuckU or discard markers',
})
@UseGuards(AuthGuard)
async discardCard(
@Param('gameId') _gameId: string,
@Param('cardId') _cardId: string,
@Param('gameId', GameStartedPipe) game: Document<Game> & Game,
@Param('cardId', CardPipe) card: Document<Card> & Card,
@Session() session: Record<string, string>,
) {
const currentPlayer = getPlayer(session, game);
const currentTeam = getCurrentTeam(game);
if (!isInTeam(currentTeam, currentPlayer)) {
throw new HttpException(
'It is not your turn to play',
HttpStatus.FORBIDDEN,
);
}
if (currentPlayer.discardMarkers == 0 && currentPlayer.fuckUMarkers == 0) {
throw new HttpException(
'You do not have any discard or fuckU markers',
HttpStatus.BAD_REQUEST,
);
}
if (!currentPlayer.board.cards.some((c) => c._id.equals(_cardId))) {
throw new HttpException('Card not found in board', HttpStatus.NOT_FOUND);
}
await this.turnService.discardCard(game, currentPlayer, card);
}
} }
+10
View File
@@ -49,6 +49,16 @@ export class PlayingTurn extends Types.ObjectId {
@Prop({ default: 0 }) @Prop({ default: 0 })
gold: number; gold: number;
@Prop({
type: mongoose.Schema.Types.ObjectId,
ref: 'Effect',
autopopulate: false,
})
drawAndDiscardCurrentEffect?: Effect;
@Prop({ default: 0 })
drawAndDiscardCurrentAmount: number;
} }
@Schema() @Schema()
+24 -4
View File
@@ -47,7 +47,10 @@ export async function removeToken(
effect: Effect, effect: Effect,
eventEmitter: EventEmitter2, eventEmitter: EventEmitter2,
) { ) {
game.currentTurn.tokens.splice(game.currentTurn.tokens.indexOf(effect), 1); game.currentTurn.tokens.splice(
game.currentTurn.tokens.findIndex((t) => t._id.equals(effect._id)),
1,
);
eventEmitter.emit('sse.game.' + game._id.toHexString(), { eventEmitter.emit('sse.game.' + game._id.toHexString(), {
type: 'currentTurn.removeToken', type: 'currentTurn.removeToken',
token: effect._id, token: effect._id,
@@ -322,7 +325,7 @@ export const tokenMappings = {
player.stack, player.stack,
session, session,
); );
await gameService.fillMarket(game); await gameService.fillMarket(game, session);
}, },
[CardEffects.STACK_NEXT_CARD_BOUGHT]: async ( [CardEffects.STACK_NEXT_CARD_BOUGHT]: async (
game: Document<Game> & Game, game: Document<Game> & Game,
@@ -370,20 +373,37 @@ export const tokenMappings = {
player.board, player.board,
session, session,
); );
await gameService.fillMarket(game); await gameService.fillMarket(game, session);
}, },
[CardEffects.DRAW_AND_DISCARD]: async ( [CardEffects.DRAW_AND_DISCARD]: async (
game: Document<Game> & Game, game: Document<Game> & Game,
effect: Effect, effect: Effect,
player: Player, player: Player,
card: Card, _card: Card,
gameService: GameService, gameService: GameService,
turnService: TurnService, turnService: TurnService,
eventEmitter: EventEmitter2, eventEmitter: EventEmitter2,
session: mongoose.mongo.ClientSession, session: mongoose.mongo.ClientSession,
) => { ) => {
if (
game.currentTurn.drawAndDiscardCurrentEffect &&
!game.currentTurn.drawAndDiscardCurrentEffect._id.equals(effect._id)
) {
throw new HttpException(
'You cannot use a token while having discard markers',
HttpStatus.BAD_REQUEST,
);
}
await gameService.drawToBoard(1, player, game, session); await gameService.drawToBoard(1, player, game, session);
await player.discardMarkers++; await player.discardMarkers++;
eventEmitter.emit('sse.game.' + game._id.toHexString(), {
type: 'player.addDiscardMarker',
operation: 1,
discardMarkers: player.discardMarkers,
playerId: player._id.toHexString(),
});
game.currentTurn.drawAndDiscardCurrentAmount++;
game.currentTurn.drawAndDiscardCurrentEffect = effect;
}, },
} as Record< } as Record<
CardEffects, CardEffects,
+21
View File
@@ -33,6 +33,27 @@ export class GameService {
let currentTeam = getCurrentTeam(game); let currentTeam = getCurrentTeam(game);
for (const player of currentTeam.players) { for (const player of currentTeam.players) {
if (player.discardMarkers > 0) {
this.eventEmitter.emit('sse.game.' + game._id.toHexString(), {
type: 'player.removeDiscardMarker',
operation: -player.discardMarkers,
discardMarkers: 0,
playerId: player._id.toHexString(),
});
player.discardMarkers = 0;
}
if (player.fuckUMarkers > 0) {
player.fuckUMarkers--;
this.eventEmitter.emit('sse.game.' + game._id.toHexString(), {
type: 'player.removeFuckUMarker',
operation: -player.fuckUMarkers,
fuckUMarkers: 0,
playerId: player._id.toHexString(),
});
player.fuckUMarkers = 0;
}
await this.distributeCards( await this.distributeCards(
player.board.cards.filter((c) => !c.defense), player.board.cards.filter((c) => !c.defense),
player.board, player.board,
+69 -8
View File
@@ -232,6 +232,12 @@ export class TurnService {
session?: mongoose.mongo.ClientSession, session?: mongoose.mongo.ClientSession,
) { ) {
target.fuckUMarkers++; target.fuckUMarkers++;
this.eventEmitter.emit('sse.game.' + game._id.toHexString(), {
type: 'player.addFuckUMarker',
operation: 1,
fuckUMarkers: target.fuckUMarkers,
playerId: target._id.toHexString(),
});
const index = game.currentTurn.tokens.findIndex((t) => const index = game.currentTurn.tokens.findIndex((t) =>
t._id.equals(token._id), t._id.equals(token._id),
); );
@@ -265,14 +271,21 @@ export class TurnService {
this.eventEmitter, this.eventEmitter,
session, session,
); );
const index = game.currentTurn.tokens.findIndex((t) => if (
t._id.equals(token._id), token.effect != CardEffects.DRAW_AND_DISCARD ||
); (token.effect == CardEffects.DRAW_AND_DISCARD &&
game.currentTurn.tokens.splice(index, 1); token.times >= game.currentTurn.drawAndDiscardCurrentAmount)
this.eventEmitter.emit('sse.game.' + game._id.toHexString(), { ) {
type: 'currentTurn.useToken', const index = game.currentTurn.tokens.findIndex((t) =>
tokenId: token._id.toHexString(), t._id.equals(token._id),
}); );
game.currentTurn.tokens.splice(index, 1);
this.eventEmitter.emit('sse.game.' + game._id.toHexString(), {
type: 'currentTurn.useToken',
tokenId: token._id.toHexString(),
});
}
await game.save({ session }); await game.save({ session });
} }
@@ -333,4 +346,52 @@ export class TurnService {
await game.save({ session }); await game.save({ session });
} }
@WithTransaction
async discardCard(
game: Document<Game> & Game,
player: Player,
card: Card,
session?: mongoose.mongo.ClientSession,
) {
await this.gamesService.distributeCards(
[card],
player.board,
player.discard,
game,
);
if (player.discardMarkers > 0) {
player.discardMarkers--;
this.eventEmitter.emit('sse.game.' + game._id.toHexString(), {
type: 'player.removeDiscardMarker',
operation: -1,
discardMarkers: player.discardMarkers,
playerId: player._id.toHexString(),
});
} else if (player.fuckUMarkers > 0) {
player.fuckUMarkers--;
this.eventEmitter.emit('sse.game.' + game._id.toHexString(), {
type: 'player.removeFuckUMarker',
operation: -1,
fuckUMarkers: player.fuckUMarkers,
playerId: player._id.toHexString(),
});
}
game.currentTurn.drawAndDiscardCurrentAmount = 0;
game.currentTurn.drawAndDiscardCurrentEffect = null;
// if (token) {
// const index = game.currentTurn.tokens.findIndex((t) =>
// t._id.equals(token._id),
// );
// game.currentTurn.tokens.splice(index, 1);
// this.eventEmitter.emit('sse.game.' + game._id.toHexString(), {
// type: 'currentTurn.useToken',
// tokenId: token._id.toHexString(),
// });
// game.currentTurn.drawAndDiscardCurrentEffect = null;
// }
await game.save({ session });
}
} }
+1
View File
@@ -83,6 +83,7 @@ export function WithTransaction(
HttpStatus.TOO_MANY_REQUESTS, HttpStatus.TOO_MANY_REQUESTS,
), ),
); );
return;
}); });
resolve(data); resolve(data);
return data; return data;