import { RawRequirement } from '../../../../models/achievement/raw-requirement' ; import { GameEvent } from '../../../../models/game-event' ; import { Requirement } from './_requirement' ; export class TotalDiscardedCardsReq implements Requirement { private totalDiscardedCards = 0 ; private completed = false ; constructor ( private readonly targetDiscardedCards ) { } public static create ( rawReq ) { if ( ! rawReq . values || rawReq . values . length === 0 ) { console . error ( 'invalid parameters for TotalDiscardedCardsReq' , rawReq ) ; } return new TotalDiscardedCardsReq ( parseInt ( rawReq . values [ 0 ] ) ) ; } reset ( ) { this . totalDiscardedCards = 0 ; this . completed = false ; } afterAchievementCompletionReset ( ) { this . totalDiscardedCards = 0 ; this . completed = true ; } isCompleted ( ) { return ! this . completed && this . totalDiscardedCards >= this . targetDiscardedCards ; } test ( gameEvent ) { if ( gameEvent . type === GameEvent . DISCARD_CARD ) { this . handleEvent ( gameEvent ) ; } } private handleEvent ( gameEvent ) { const localPlayerId = gameEvent . localPlayer ?. PlayerId ; const controllerId = gameEvent . controllerId ; if ( controllerId === localPlayerId ) { this . totalDiscardedCards ++ ; } } }