Feat : Lock champions at start of game
This commit is contained in:
@@ -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 });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user