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 EndOfEchoInHandParser implements EventParser { constructor ( private readonly helper ) { } applies ( gameEvent , state ) { return state && gameEvent . type === GameEvent . END_OF_ECHO_IN_HAND ; } async parse ( currentState , gameEvent ) { const [ cardId , controllerId , localPlayer , entityId ] = gameEvent . parse ( ) ; const isPlayer = controllerId === localPlayer . PlayerId ; const deck = isPlayer ? currentState . playerDeck : currentState . opponentDeck ; const newHand = this . helper . removeSingleCardFromZone ( deck . hand , cardId , entityId ) [ 0 ] ; const newPlayerDeck = Object . assign ( new DeckState ( ) , deck , { hand : newHand , } ) ; return Object . assign ( new GameState ( ) , currentState , { [ isPlayer ? 'playerDeck' : 'opponentDeck' ] : newPlayerDeck , } ) ; } event ( ) { return GameEvent . END_OF_ECHO_IN_HAND ; } }