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