import { RawRequirement } from '../../../../models/achievement/raw-requirement' ; import { GameEvent } from '../../../../models/game-event' ; import { Requirement } from './_requirement' ; export class CorrectOpponentReq implements Requirement { private isCorrectOpponent : boolean ; constructor ( private readonly cardIds ) { } public static create ( rawReq ) { if ( ! rawReq . values || rawReq . values . length === 0 ) { console . error ( 'invalid parameters for CorrectOpponentReq' , rawReq ) ; } return new CorrectOpponentReq ( rawReq . values ) ; } reset ( ) { this . isCorrectOpponent = undefined ; } afterAchievementCompletionReset ( ) { this . isCorrectOpponent = undefined ; } isCompleted ( ) { return this . isCorrectOpponent ; } test ( gameEvent ) { if ( gameEvent . type === GameEvent . OPPONENT ) { this . detectGameResultEvent ( gameEvent ) ; return ; } } private detectGameResultEvent ( gameEvent ) { const opponentPlayer = gameEvent . opponentPlayer ; if ( this . cardIds . indexOf ( opponentPlayer . CardID ) !== - 1 ) { this . isCorrectOpponent = true ; } } }