Feat : Lock champions at start of game

This commit is contained in:
2024-07-05 16:49:01 +02:00
parent 9d0cdca6e9
commit aca90efc5d
3 changed files with 67 additions and 20 deletions
+19 -12
View File
@@ -1,4 +1,10 @@
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
import {
forwardRef,
HttpException,
HttpStatus,
Inject,
Injectable,
} from '@nestjs/common';
import { Game, Player } from '../schemas/game.schema';
import mongoose, { Document, Model } from 'mongoose';
import { Card } from 'src/cards/schemas/cards.schema';
@@ -6,7 +12,7 @@ import { EventEmitter2 } from '@nestjs/event-emitter';
import { Effect } from 'src/cards/schemas/effect.schema';
import { CardEffects, EffectType } from 'src/cards/schemas/cards.types';
import { WithTransaction } from '../utils';
import { effectMappings } from './effect.functions';
import { effectMappings, isAutoActivable } from './effect.functions';
import { InjectConnection, InjectModel } from '@nestjs/mongoose';
import { GameService } from './games.service';
@@ -14,6 +20,7 @@ import { GameService } from './games.service';
export class TurnService {
constructor(
private eventEmitter: EventEmitter2,
@Inject(forwardRef(() => GameService))
private readonly gamesService: GameService,
@InjectModel(Game.name) private gameModel: Model<Game>,
@InjectConnection() private readonly connection: mongoose.Connection,
@@ -32,15 +39,7 @@ export class TurnService {
card: card._id.toHexString(),
});
for (const effect of card.effects) {
if (
[CardEffects.HEAL, CardEffects.GOLD, CardEffects.DAMAGE].includes(
effect.effect,
) &&
!effect.mutex &&
!effect.per &&
(!effect.condition ||
effect.condition.effectId == EffectType.CHAMPION_ACTION)
) {
if (isAutoActivable(effect)) {
await this.useEffect(game, player, effect, card, session);
}
}
@@ -77,7 +76,15 @@ export class TurnService {
effect: effectUUID,
});
game.currentTurn.effectsUsed.push(effectUUID);
await effectRunner(game, effect, player, card, this.eventEmitter);
await effectRunner(
game,
effect,
player,
card,
this.gamesService,
this.eventEmitter,
session,
);
await game.save({ session });
}