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 { LocalizationFacadeService } from '../../localization-facade.service' ; import { DeckManipulationHelper } from './deck-manipulation-helper' ; import { EventParser } from './event-parser' ; export class MinionSummonedFromHandParser implements EventParser { constructor ( private readonly helper , private readonly allCards , private readonly i18n ) { } applies ( gameEvent , state ) { return state && gameEvent . type === GameEvent . MINION_SUMMONED_FROM_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 card = this . helper . findCardInZone ( deck . hand , cardId , entityId ) ; const [ newHand , removedCard ] = this . helper . removeSingleCardFromZone ( deck . hand , cardId , entityId , deck . deckList . length === 0 ) ; let newDeck = removedCard != null ? this . helper . updateDeckForAi ( gameEvent , currentState , removedCard ) : deck . deck ; if ( removedCard == null && cardId ) { const [ newDeckAfterReveal , removedCardFromDeck ] = this . helper . removeSingleCardFromZone ( newDeck , cardId , entityId , deck . deckList . length === 0 ) ; if ( removedCardFromDeck ) { newDeck = newDeckAfterReveal ; } } const refCard = this . allCards . getCard ( cardId ) ; const isOnBoard = refCard && refCard . type === 'Minion' ; const cardWithZone = card ?. update ( { zone : isOnBoard ? 'PLAY' : null , temporaryCard : false , } as DeckCard ) || DeckCard . create ( { entityId : entityId , cardId : cardId , cardName : this . i18n . getCardName ( cardId , refCard . name ) , manaCost : refCard ?. cost , rarity : refCard ?. rarity ?. toLowerCase ( ) , zone : isOnBoard ? 'PLAY' : null , temporaryCard : false , } as DeckCard ) ; const newBoard = isOnBoard ? this . helper . addSingleCardToZone ( deck . board , cardWithZone ) : deck . board ; const newOtherZone = isOnBoard ? deck . otherZone : this . helper . addSingleCardToZone ( deck . otherZone , cardWithZone ) ; const newPlayerDeck = Object . assign ( new DeckState ( ) , deck , { hand : newHand , board : newBoard , deck : newDeck , otherZone : newOtherZone , } as DeckState ) ; return Object . assign ( new GameState ( ) , currentState , { [ isPlayer ? 'playerDeck' : 'opponentDeck' ] : newPlayerDeck , } ) ; } event ( ) { return GameEvent . MINION_SUMMONED_FROM_HAND ; } }