import { CardIds } from '@firestone-hs/reference-data' ; 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 { MinionsDiedEvent } from '../../../models/mainwindow/game-events/minions-died-event' ; import { DeckManipulationHelper } from './deck-manipulation-helper' ; import { EventParser } from './event-parser' ; export class MinionDiedParser implements EventParser { constructor ( private readonly helper ) { } applies ( gameEvent , state ) { return state && gameEvent . type === GameEvent . MINIONS_DIED ; } async parse ( currentState , gameEvent ) { const [ , , localPlayer ] = gameEvent . parse ( ) ; const deadMinions = gameEvent . additionalData . deadMinions ; let result = currentState ; for ( const deadMinion of deadMinions ) { const cardId = deadMinion . CardId ; const entityId = deadMinion . EntityId ; const isPlayer = deadMinion . ControllerId === localPlayer ?. PlayerId ; const deck = isPlayer ? result . playerDeck : result . opponentDeck ; const card = this . helper . findCardInZone ( deck . board , cardId , entityId ) ; const cardWithZone = card . update ( { zone : 'GRAVEYARD' , entityId : - card . entityId , } as DeckCard ) ; const newBoard = this . helper . removeSingleCardFromZone ( deck . board , cardId , entityId ) [ 0 ] ; const newOther = this . helper . addSingleCardToZone ( deck . otherZone , cardWithZone ) ; const newPlayerDeck = Object . assign ( new DeckState ( ) , deck , { board : newBoard , otherZone : newOther , elwynnBoarsDeadThisMatch : deck . elwynnBoarsDeadThisMatch + ( cardId === CardIds . ElwynnBoar ? 1 : 0 ) , } as DeckState ) ; result = Object . assign ( new GameState ( ) , result , { [ isPlayer ? 'playerDeck' : 'opponentDeck' ] : newPlayerDeck , } ) ; } return result ; } event ( ) { return GameEvent . MINIONS_DIED ; } }