fix : attempt to fix prepare with sub_effects
release-tag / release-image (push) Failing after 7s

Closes #17
This commit is contained in:
2024-12-21 11:07:28 +01:00
parent 160a794ed6
commit 0aaf03839b
2 changed files with 28 additions and 13 deletions
+6 -13
View File
@@ -178,13 +178,13 @@ export const effectMappings = {
export const tokenMappings = { export const tokenMappings = {
[CardEffects.PREPARE]: async ( [CardEffects.PREPARE]: 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 (card.cardType !== CardType.CHAMPION) { if (card.cardType !== CardType.CHAMPION) {
throw new HttpException( throw new HttpException(
@@ -208,14 +208,7 @@ export const tokenMappings = {
} }
for (const e of targetEffects) { for (const e of targetEffects) {
const index = game.currentTurn.lockedEffects.findIndex((ee) => await turnService.unlockEffect(game, e, session);
ee._id.equals(e._id),
);
game.currentTurn.lockedEffects.splice(index, 1);
eventEmitter.emit('sse.game.' + game._id.toHexString(), {
type: 'unlockEffect',
effect: e._id.toHexString(),
});
} }
}, },
[CardEffects.STUN]: async ( [CardEffects.STUN]: async (
+22
View File
@@ -58,6 +58,28 @@ export class TurnService {
await game.save({ session }); await game.save({ session });
} }
@WithTransaction
async unlockEffect(
game: Document<Game> & Game,
effect: Effect,
session: mongoose.mongo.ClientSession,
) {
const index = game.currentTurn.lockedEffects.findIndex((ee) =>
ee._id.equals(effect._id),
);
game.currentTurn.lockedEffects.splice(index, 1);
this.eventEmitter.emit('sse.game.' + game._id.toHexString(), {
type: 'unlockEffect',
effect: effect._id.toHexString(),
});
for (const sub of effect.subEffects) {
await this.unlockEffect(game, sub, session);
}
await game.save({ session });
}
@WithTransaction @WithTransaction
async lockEffect( async lockEffect(
game: Document<Game> & Game, game: Document<Game> & Game,