import { RawRequirement } from '../../../../models/achievement/raw-requirement' ; import { GameEvent } from '../../../../models/game-event' ; import { DamageGameEvent } from '../../../../models/mainwindow/game-events/damage-game-event' ; import { Requirement } from './_requirement' ; export class LastDamageDoneByMinionReq implements Requirement { private lastMinionThatDamagedOpponent : string ; constructor ( private readonly targetSourceMinion ) { } public static create ( rawReq ) { if ( ! rawReq . values || rawReq . values . length === 0 ) { console . error ( 'invalid parameters for LastDamageDoneByMinionReq' , rawReq ) ; } return new LastDamageDoneByMinionReq ( rawReq . values [ 0 ] ) ; } reset ( ) { this . lastMinionThatDamagedOpponent = undefined ; } afterAchievementCompletionReset ( ) { this . lastMinionThatDamagedOpponent = undefined ; } isCompleted ( ) { return this . lastMinionThatDamagedOpponent === this . targetSourceMinion ; } test ( gameEvent ) { if ( gameEvent . type === GameEvent . DAMAGE ) { this . handleDamageEvent ( gameEvent as DamageGameEvent ) ; } } private handleDamageEvent ( gameEvent ) { const opponentPlayerCardId = gameEvent . opponentPlayer ?. CardID ; const opponentPlayerId = gameEvent . opponentPlayer ?. PlayerId ; const damageForOpponentPlayer = Object . values ( gameEvent . additionalData . targets ) . find ( ( target ) => target . TargetCardId === opponentPlayerCardId ) ; if ( damageForOpponentPlayer && damageForOpponentPlayer . TargetControllerId === opponentPlayerId ) { this . lastMinionThatDamagedOpponent = gameEvent . additionalData . sourceCardId ; } } }