import { Injectable } from '@angular/core' ; import { CardsFacadeService } from '@services/cards-facade.service' ; import { GameState } from '../../../../models/decktracker/game-state' ; import { GameEvent } from '../../../../models/game-event' ; import { DeckManipulationHelper } from '../deck-manipulation-helper' ; import { EventParser } from '../event-parser' ; import { TriggerOnAttackSecretsParser } from './trigger-on-attack-secrets-parser' ; import { TriggerOnDamageSecretsParser } from './trigger-on-damage-secrets-parser' ; import { TriggerOnFriendlyMinionDiedSecretsParser } from './trigger-on-friendly-minion-died-secrets-parser' ; import { TriggerOnHeroPowerSecretsParser } from './trigger-on-hero-power-secrets-parser' ; import { TriggerOnMinionPlaySecretsParser } from './trigger-on-minion-play-secrets-parser' ; import { TriggerOnNumCardDrawSecretsParser } from './trigger-on-num-card-draw-secrets-parser' ; import { TriggerOnNumCardPlaySecretsParser } from './trigger-on-num-card-play-secrets-parser' ; import { TriggerOnSpellPlaySecretsParser } from './trigger-on-spell-play-secrets-parser' ; import { TriggerOnTurnEndSecretsParser } from './trigger-on-turn-end-secrets-parser' ; import { TriggerOnTurnStartSecretsParser } from './trigger-on-turn-start-secrets-parser' ; @ Injectable ( ) export class SecretsParserService { private secretParsers = this . buildSecretParsers ( ) ; constructor ( private readonly helper , private readonly allCards ) { } public async parseSecrets ( gameState , gameEvent , additionalInfo ) { if ( ! gameState ) { return null ; } if ( this . isSecretInPlayer ( gameState ) ) { for ( const parser of this . secretParsers ) { if ( parser . applies ( gameEvent , gameState ) ) { gameState = await parser . parse ( gameState , gameEvent , additionalInfo ) ; } } } return gameState ; } private isSecretInPlayer ( gameState ) { return gameState . playerDeck ?. secrets ?. length > 0 || gameState . opponentDeck ?. secrets ?. length > 0 ; } private buildSecretParsers ( ) { return [ new TriggerOnAttackSecretsParser ( this . helper , this . allCards ) , new TriggerOnDamageSecretsParser ( this . helper , this . allCards ) , new TriggerOnFriendlyMinionDiedSecretsParser ( this . helper ) , new TriggerOnHeroPowerSecretsParser ( this . helper ) , new TriggerOnMinionPlaySecretsParser ( this . helper , this . allCards ) , new TriggerOnNumCardPlaySecretsParser ( this . helper , this . allCards ) , new TriggerOnNumCardDrawSecretsParser ( this . helper , this . allCards ) , new TriggerOnSpellPlaySecretsParser ( this . helper , this . allCards ) , new TriggerOnTurnStartSecretsParser ( this . helper ) , new TriggerOnTurnEndSecretsParser ( this . helper ) , ] ; } }