33 lines
887 B
TypeScript
33 lines
887 B
TypeScript
import { EventEmitter2 } from '@nestjs/event-emitter';
|
|
import { Game, Player } from '../schemas/game.schema';
|
|
import { Document } from 'mongoose';
|
|
import { Card } from 'src/cards/schemas/cards.schema';
|
|
import { CardEffects } from 'src/cards/schemas/cards.types';
|
|
import { Effect } from 'src/cards/schemas/effect.schema';
|
|
|
|
export const effectMappings = {
|
|
[CardEffects.GOLD]: (
|
|
game: Document<Game> & Game,
|
|
effect: Effect,
|
|
_player: Player,
|
|
_card: Card,
|
|
eventEmitter: EventEmitter2,
|
|
) => {
|
|
game.currentTurn.gold += effect.amount;
|
|
eventEmitter.emit('sse.game.' + game._id.toHexString(), {
|
|
type: 'currentTurn.updateGold',
|
|
gold: game.currentTurn.gold,
|
|
operation: effect.amount,
|
|
});
|
|
},
|
|
} as Record<
|
|
CardEffects,
|
|
(
|
|
game: Game,
|
|
effect: Effect,
|
|
player: Player,
|
|
card: Card,
|
|
eventEmitter: EventEmitter2,
|
|
) => void
|
|
>;
|