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 SameMinionAttackReq implements Requirement { private hasMinionAttacked : boolean ; private attackCounts : { [ entityId ] : number ; } ; constructor ( private readonly targetQuantity , private readonly qualifier , private readonly cards ) { this . attackCounts = { } ; } public static create ( rawReq , cards ) { if ( ! rawReq . values || rawReq . values . length !== 2 ) { console . error ( 'invalid parameters for SameMinionAttackReq' , rawReq ) ; } return new SameMinionAttackReq ( parseInt ( rawReq . values [ 0 ] ) , rawReq . values [ 1 ] as QualifierType , cards ) ; } reset ( ) { this . attackCounts = { } ; this . hasMinionAttacked = undefined ; } afterAchievementCompletionReset ( ) { this . attackCounts = { } ; this . hasMinionAttacked = undefined ; } isCompleted ( ) { return this . hasMinionAttacked ; } test ( gameEvent ) { if ( gameEvent . type === GameEvent . ATTACKING_HERO || gameEvent . type === GameEvent . ATTACKING_MINION ) { this . handleEvent ( gameEvent ) ; return ; } } private handleEvent ( gameEvent ) { const localPlayer = gameEvent . localPlayer ; const cardId = gameEvent . additionalData . attackerCardId ; const entityId = gameEvent . additionalData . attackerEntityId ; const controllerId = gameEvent . additionalData . attackerControllerId ; const card = this . cards . getCard ( cardId ) ; if ( controllerId === localPlayer ?. PlayerId && card . type && CardType [ card . type . toUpperCase ( ) ] === CardType . MINION ) { this . attackCounts [ entityId ] = ( this . attackCounts [ entityId ] || 0 ) + 1 ; this . hasMinionAttacked = Object . keys ( this . attackCounts ) . some ( ( entityId ) => this . attackCounts [ entityId ] >= this . targetQuantity ) ; } } }