import { CardType } 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' ; export class TotalMinionsSummonedReq implements Requirement { private summonCount = 0 ; constructor ( private readonly targetQuantity , private readonly qualifier , private readonly cards ) { } public static create ( rawReq , cards ) { if ( ! rawReq . values || rawReq . values . length !== 2 ) { console . error ( 'invalid parameters for TotalMinionsSummonedReq' , rawReq ) ; } return new TotalMinionsSummonedReq ( parseInt ( rawReq . values [ 0 ] ) , rawReq . values [ 1 ] as QualifierType , cards ) ; } reset ( ) { this . summonCount = 0 ; } afterAchievementCompletionReset ( ) { this . summonCount = 0 ; } isCompleted ( ) { if ( this . qualifier === 'AT_LEAST' ) { return this . summonCount >= this . targetQuantity ; } else if ( this . qualifier === 'AT_MOST' ) { return this . summonCount <= this . targetQuantity ; } else { console . error ( 'invalid qualifier for total-cards-played-req' , this . qualifier ) ; return false ; } } test ( gameEvent ) { if ( gameEvent . type === GameEvent . MINION_SUMMONED || gameEvent . type === GameEvent . MINION_SUMMONED_FROM_HAND || gameEvent . type === GameEvent . CARD_PLAYED ) { this . detectCardPlayedEvent ( gameEvent ) ; return ; } } private detectCardPlayedEvent ( gameEvent ) { const cardId = gameEvent . cardId ; const controllerId = gameEvent . controllerId ; const localPlayer = gameEvent . localPlayer ; const card = this . cards . getCard ( cardId ) ; if ( ! card ?. type ) { return ; } if ( controllerId === localPlayer ?. PlayerId && CardType [ card . type ?. toUpperCase ( ) ] === CardType . MINION ) { this . summonCount = ( this . summonCount || 0 ) + 1 ; } } }