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 = {
[CardEffects.PREPARE]: async (
game: Document<Game> & Game,
effect: Effect,
player: Player,
_effect: Effect,
_player: Player,
card: Card,
gameService: GameService,
_gameService: GameService,
turnService: TurnService,
eventEmitter: EventEmitter2,
_session: mongoose.mongo.ClientSession,
_eventEmitter: EventEmitter2,
session: mongoose.mongo.ClientSession,
) => {
if (card.cardType !== CardType.CHAMPION) {
throw new HttpException(
@@ -208,14 +208,7 @@ export const tokenMappings = {
}
for (const e of targetEffects) {
const index = game.currentTurn.lockedEffects.findIndex((ee) =>
ee._id.equals(e._id),
);
game.currentTurn.lockedEffects.splice(index, 1);
eventEmitter.emit('sse.game.' + game._id.toHexString(), {
type: 'unlockEffect',
effect: e._id.toHexString(),
});
await turnService.unlockEffect(game, e, session);
}
},
[CardEffects.STUN]: async (
+22
View File
@@ -58,6 +58,28 @@ export class TurnService {
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
async lockEffect(
game: Document<Game> & Game,