import { CardType } from '@firestone-hs/reference-data' ; import { CardsFacadeService } from '@services/cards-facade.service' ; 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 CardOnBoardAtGameStart implements EventParser { constructor ( private readonly helper , private readonly allCards ) { } applies ( gameEvent , state ) { return state && gameEvent . type === GameEvent . CARD_ON_BOARD_AT_GAME_START ; } async parse ( currentState , gameEvent ) { const [ cardId , controllerId , localPlayer , entityId ] = gameEvent . parse ( ) ; const creatorCardId = gameEvent . additionalData . creatorCardId ; const isPlayer = controllerId === localPlayer . PlayerId ; const deck = isPlayer ? currentState . playerDeck : currentState . opponentDeck ; const card = this . helper . findCardInZone ( deck . deck , cardId , entityId ) ; const dbCard = this . allCards . getCard ( cardId ) ; if ( dbCard . type && CardType [ dbCard . type . toUpperCase ( ) ] === CardType . HERO ) { return currentState ; } const newDeck = this . helper . removeSingleCardFromZone ( deck . deck , cardId , entityId , deck . deckList . length === 0 ) [ 0 ] ; const cardWithZone = card . update ( { zone : 'PLAY' , creatorCardId : creatorCardId , temporaryCard : false , } as DeckCard ) ; const newBoard = this . helper . addSingleCardToZone ( deck . board , cardWithZone ) ; const newPlayerDeck = Object . assign ( new DeckState ( ) , deck , { deck : newDeck , board : newBoard , } as DeckState ) ; return Object . assign ( new GameState ( ) , currentState , { [ isPlayer ? 'playerDeck' : 'opponentDeck' ] : newPlayerDeck , } ) ; } event ( ) { return GameEvent . CARD_ON_BOARD_AT_GAME_START ; } }