import { BoardSecret } from '../../../models/decktracker/board-secret' ; import { DeckCard } from '../../../models/decktracker/deck-card' ; import { DeckState } from '../../../models/decktracker/deck-state' ; import { GameState } from '../../../models/decktracker/game-state' ; import { GameEvent } from '../../../models/game-event' ; import { DeckManipulationHelper } from './deck-manipulation-helper' ; import { EventParser } from './event-parser' ; export class SecretTriggeredParser implements EventParser { constructor ( private readonly helper ) { } applies ( gameEvent , state ) { return state && gameEvent . type === GameEvent . SECRET_TRIGGERED ; } async parse ( currentState , gameEvent ) { const [ cardId , controllerId , localPlayer , entityId ] = gameEvent . parse ( ) ; const isPlayer = controllerId === localPlayer . PlayerId ; const deck = isPlayer ? currentState . playerDeck : currentState . opponentDeck ; const newSecrets = deck . secrets . filter ( ( secret ) => secret . entityId !== entityId ) . map ( ( secret ) => this . helper . removeSecretOptionFromSecret ( secret , cardId ) ) ; const newOther = this . helper . updateCardInZone ( deck . otherZone , entityId , cardId ) ; const newPlayerDeck = deck . update ( { secrets : newSecrets , otherZone : newOther , } as DeckState ) ; return Object . assign ( new GameState ( ) , currentState , { [ isPlayer ? 'playerDeck' : 'opponentDeck' ] : newPlayerDeck , } ) ; } event ( ) { return GameEvent . SECRET_TRIGGERED ; } }