import { ReferenceCard } from '@firestone-hs/reference-data' ; import { CardsFacadeService } from '@services/cards-facade.service' ; import { RawRequirement } from '../../../../../models/achievement/raw-requirement' ; import { GameEvent } from '../../../../../models/game-event' ; import { QualifierType } from '../_qualifier.type' ; import { Requirement } from '../_requirement' ; import { TextQualifierType } from '../_text-qualifier.type' ; import { buildCardArraysFromDeck } from './deckbuilding-helper' ; export class DeckbuildingCardNameReq implements Requirement { private doesDeckMeetSpec : boolean ; private readonly text : string [ ] ; constructor ( private readonly targetCardQuantity , private readonly qualifier , private readonly textQualifier , text , private readonly cards ) { this . text = text . split ( '|' ) ; } public static create ( rawReq , cards ) { return new DeckbuildingCardNameReq ( parseInt ( rawReq . values [ 0 ] ) , rawReq . values [ 1 ] as QualifierType , rawReq . values [ 2 ] as TextQualifierType , rawReq . values [ 3 ] , 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 ) => this . cardMatches ( card ) ) . length ; if ( this . qualifier === 'AT_LEAST' ) { this . doesDeckMeetSpec = numberOfMatchingCards >= this . targetCardQuantity ; } else if ( this . qualifier === 'AT_MOST' ) { this . doesDeckMeetSpec = numberOfMatchingCards <= this . targetCardQuantity ; } else { this . doesDeckMeetSpec = numberOfMatchingCards === this . targetCardQuantity ; } } else { this . doesDeckMeetSpec = false ; } } private cardMatches ( card ) { if ( this . textQualifier === 'STARTS_WITH' ) { return this . text . some ( ( text ) => card . name && card . name . toLowerCase ( ) . startsWith ( text . toLowerCase ( ) ) ) ; } console . error ( 'No support for textQualifier' , this . textQualifier ) ; return false ; } }