Feat : add tokens, handle mutex effects

This commit is contained in:
2024-07-07 10:45:44 +02:00
parent d8cf8560c0
commit 8b5c38a28c
12 changed files with 206 additions and 49 deletions
+16 -5
View File
@@ -40,14 +40,14 @@ export class TurnService {
});
for (const effect of card.effects) {
if (isAutoActivable(effect)) {
await this.useEffect(game, player, effect, card, session);
await this.lockEffect(game, player, effect, card, session);
}
}
await game.save({ session });
}
@WithTransaction
async useEffect(
async lockEffect(
game: Document<Game> & Game,
player: Player,
effect: Effect,
@@ -64,7 +64,7 @@ export class TurnService {
);
}
const effectUUID = effect._id.toHexString();
if (game.currentTurn.effectsUsed.includes(effectUUID)) {
if (game.currentTurn.lockedEffects.some((e) => e._id.equals(effectUUID))) {
console.error(`Effect ${effectUUID} already used this turn`);
throw new HttpException(
`Effect ${effectUUID} already used this turn`,
@@ -72,10 +72,21 @@ export class TurnService {
);
}
this.eventEmitter.emit('sse.game.' + game._id.toHexString(), {
type: 'useEffect',
type: 'lockEffect',
effect: effectUUID,
});
game.currentTurn.effectsUsed.push(effectUUID);
if (effect.mutex) {
for (const e of card.effects) {
if (e.mutex == effect.mutex) {
this.eventEmitter.emit('sse.game.' + game._id.toHexString(), {
type: 'lockEffect',
effect: e._id.toHexString(),
});
game.currentTurn.lockedEffects.push(e);
}
}
}
game.currentTurn.lockedEffects.push(effect);
await effectRunner(
game,
effect,