import { RawRequirement } from '../../../../models/achievement/raw-requirement' ; import { GameEvent } from '../../../../models/game-event' ; import { Requirement } from './_requirement' ; export class CorrectStartingHealthReq implements Requirement { private isCorrectStartingHealth : boolean ; private hasDefChangeOccured : boolean ; constructor ( private readonly targetCardId , private readonly targetStartingHealth ) { } public static create ( rawReq ) { if ( ! rawReq . values || rawReq . values . length !== 2 ) { console . error ( 'invalid parameters for CorrectStartingHealthReq' , rawReq ) ; } return new CorrectStartingHealthReq ( rawReq . values [ 0 ] , parseInt ( rawReq . values [ 1 ] ) ) ; } reset ( ) { this . isCorrectStartingHealth = undefined ; this . hasDefChangeOccured = undefined ; } afterAchievementCompletionReset ( ) { this . isCorrectStartingHealth = undefined ; this . hasDefChangeOccured = undefined ; } isCompleted ( ) { return this . isCorrectStartingHealth ; } test ( gameEvent ) { if ( gameEvent . type === GameEvent . CARD_ON_BOARD_AT_GAME_START ) { this . handleEvent ( gameEvent ) ; return ; } if ( gameEvent . type === GameEvent . HEALTH_DEF_CHANGED ) { this . handleDefChangeEvent ( gameEvent ) ; return ; } } private handleEvent ( gameEvent ) { if ( gameEvent . cardId === this . targetCardId && gameEvent . additionalData && gameEvent . additionalData . health === this . targetStartingHealth && ! this . hasDefChangeOccured ) { this . isCorrectStartingHealth = true ; } } private handleDefChangeEvent ( gameEvent ) { if ( gameEvent . cardId === this . targetCardId && ! this . hasDefChangeOccured && ! this . isCorrectStartingHealth ) { this . hasDefChangeOccured = true ; this . isCorrectStartingHealth = gameEvent . additionalData . newHealth === this . targetStartingHealth ; } } }