import { RawRequirement } from '../../../../models/achievement/raw-requirement' ; import { GameEvent } from '../../../../models/game-event' ; import { Requirement } from './_requirement' ; export class TotalHeroHealReq implements Requirement { private totalHealingReceived = 0 ; constructor ( private readonly targetHealing , private readonly qualifier ) { } public static create ( rawReq ) { if ( ! rawReq . values || rawReq . values . length !== 2 ) { console . error ( 'invalid parameters for TotalHeroHealReq' , rawReq ) ; } return new TotalHeroHealReq ( parseInt ( rawReq . values [ 0 ] ) , rawReq . values [ 1 ] ) ; } reset ( ) { this . totalHealingReceived = 0 ; } afterAchievementCompletionReset ( ) { this . totalHealingReceived = 0 ; } isCompleted ( ) { if ( this . qualifier === 'AT_LEAST' ) { return this . totalHealingReceived >= this . targetHealing ; } return this . totalHealingReceived === this . targetHealing ; } test ( gameEvent ) { if ( gameEvent . type === GameEvent . HEALING ) { this . handleEvent ( gameEvent ) ; } } private handleEvent ( gameEvent ) { const localPlayerCardId = gameEvent . localPlayer ?. CardID ; const localPlayerId = gameEvent . localPlayer ?. PlayerId ; const healingForLocalPlayer = gameEvent . additionalData . targets [ localPlayerCardId ] ; if ( healingForLocalPlayer && healingForLocalPlayer . TargetControllerId === localPlayerId ) { this . totalHealingReceived += healingForLocalPlayer . Healing ; } } }