import { RawRequirement } from '../../../../models/achievement/raw-requirement' ; import { GameEvent } from '../../../../models/game-event' ; import { Requirement } from './_requirement' ; export class PlayerHeroReq implements Requirement { private isCorrectPlayerHero : boolean ; constructor ( private readonly cardId ) { } public static create ( rawReq ) { if ( ! rawReq . values || rawReq . values . length !== 1 ) { console . error ( 'invalid parameters for PlayerHeroReq' , rawReq ) ; } return new PlayerHeroReq ( rawReq . values [ 0 ] ) ; } reset ( ) { this . isCorrectPlayerHero = undefined ; } afterAchievementCompletionReset ( ) { this . isCorrectPlayerHero = undefined ; } isCompleted ( ) { return this . isCorrectPlayerHero ; } test ( gameEvent ) { if ( gameEvent . type === GameEvent . LOCAL_PLAYER ) { this . handleEvent ( gameEvent ) ; } } private handleEvent ( gameEvent ) { const localPlayer = gameEvent . localPlayer ; if ( localPlayer ?. CardID && localPlayer . CardID . indexOf ( this . cardId ) !== - 1 ) { this . isCorrectPlayerHero = true ; } } }