Feat : add tokens, handle mutex effects
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user