import { CardsFacadeService } from '@services/cards-facade.service' ; import { RawRequirement } from '../../../../models/achievement/raw-requirement' ; import { GameEvent } from '../../../../models/game-event' ; import { Requirement } from './_requirement' ; export class PlayerClassReq implements Requirement { private isCorrectPlayerClass : boolean ; constructor ( private readonly playerClass , private readonly cards ) { } public static create ( rawReq , cards ) { if ( ! rawReq . values || rawReq . values . length !== 1 ) { console . error ( 'invalid parameters for PlayerClassReq' , rawReq ) ; } return new PlayerClassReq ( rawReq . values [ 0 ] , cards ) ; } reset ( ) { this . isCorrectPlayerClass = undefined ; } afterAchievementCompletionReset ( ) { this . isCorrectPlayerClass = undefined ; } isCompleted ( ) { return this . isCorrectPlayerClass ; } test ( gameEvent ) { if ( gameEvent . type === GameEvent . LOCAL_PLAYER ) { this . handleEvent ( gameEvent ) ; } } private handleEvent ( gameEvent ) { const localPlayer = gameEvent . localPlayer ; if ( localPlayer ?. CardID ) { const card = this . cards . getCard ( localPlayer ?. CardID ) ; const playerClass = card && card . playerClass ? card . playerClass . toLowerCase ( ) : null ; this . isCorrectPlayerClass = playerClass === this . playerClass ; } } }