import { CardsFacadeService } from '@services/cards-facade.service' ; import { RawRequirement } from '../../../../../models/achievement/raw-requirement' ; import { GameEvent } from '../../../../../models/game-event' ; import { Requirement } from '../_requirement' ; import { buildCardArraysFromDeck } from './deckbuilding-helper' ; export class DeckbuildingTypeReq implements Requirement { private doesDeckMeetSpec : boolean ; constructor ( private readonly targetTypeQuantity , private readonly type , private readonly qualifier , private readonly cards ) { } public static create ( rawReq , cards ) { return new DeckbuildingTypeReq ( parseInt ( rawReq . values [ 0 ] ) , rawReq . values [ 1 ] , rawReq . values [ 2 ] , cards ) ; } reset ( ) { this . doesDeckMeetSpec = undefined ; } afterAchievementCompletionReset ( ) { this . doesDeckMeetSpec = undefined ; } isCompleted ( ) { return this . doesDeckMeetSpec ; } test ( gameEvent ) { if ( gameEvent . type === GameEvent . PLAYERS_INFO ) { this . handleEvent ( gameEvent ) ; } } private handleEvent ( gameEvent ) { const deck = gameEvent . localPlayer ?. deck ? gameEvent . localPlayer . deck . deck : null ; if ( deck && deck . cards && deck . cards . length > 0 ) { const cards = buildCardArraysFromDeck ( deck , this . cards ) ; const numberOfMatchingCards = cards . filter ( ( card ) => card . type && card . type . toUpperCase ( ) . indexOf ( this . type ) !== - 1 ) . length ; if ( this . qualifier === 'AT_LEAST' ) { this . doesDeckMeetSpec = numberOfMatchingCards >= this . targetTypeQuantity ; } else if ( this . qualifier === 'AT_MOST' ) { this . doesDeckMeetSpec = numberOfMatchingCards <= this . targetTypeQuantity ; } else { this . doesDeckMeetSpec = numberOfMatchingCards === this . targetTypeQuantity ; } } else { this . doesDeckMeetSpec = false ; } } }