Closes #17
This commit is contained in:
@@ -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 (
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user