import { RawRequirement } from '../../../../models/achievement/raw-requirement' ; import { GameEvent } from '../../../../models/game-event' ; import { Requirement } from './_requirement' ; export class GameTypeReq implements Requirement { private isCorrectGameType : boolean ; constructor ( private readonly gameTypes ) { } public static create ( rawReq ) { if ( ! rawReq . values || rawReq . values . length === 0 ) { console . error ( 'invalid parameters for GameTypeReq' , rawReq ) ; } return new GameTypeReq ( rawReq . values . map ( ( gameType ) => parseInt ( gameType ) ) ) ; } reset ( ) { this . isCorrectGameType = undefined ; } afterAchievementCompletionReset ( ) { this . isCorrectGameType = undefined ; } isCompleted ( ) { if ( process . env . LOCAL_TEST ) { return true ; } return this . isCorrectGameType ; } test ( gameEvent ) { if ( gameEvent . type === GameEvent . MATCH_METADATA ) { this . handleEvent ( gameEvent ) ; } } private handleEvent ( gameEvent ) { if ( this . gameTypes . indexOf ( gameEvent . additionalData . metaData . GameType ) !== - 1 ) { this . isCorrectGameType = true ; } } }