import { StatContext } from '@firestone-hs/build-global-stats/dist/model/context.type' ; import { GlobalStatKey } from '@firestone-hs/build-global-stats/dist/model/global-stat-key.type' ; import { GlobalStats } from '@firestone-hs/build-global-stats/dist/model/global-stats' ; import { RawRequirement } from '../../../../../models/achievement/raw-requirement' ; import { GameEvent } from '../../../../../models/game-event' ; import { Requirement } from '../_requirement' ; export class GlobalStatReq implements Requirement { private isValid : boolean ; constructor ( private readonly targetKey , private readonly targetContext , private readonly targetValue ) { } public static create ( rawReq ) { if ( ! rawReq . values || rawReq . values . length !== 3 ) { console . error ( 'invalid parameters for TotalDamageToEnemyHeroesReq' , rawReq ) ; } return new GlobalStatReq ( rawReq . values [ 0 ] as GlobalStatKey , rawReq . values [ 1 ] as StatContext , parseInt ( rawReq . values [ 2 ] ) ) ; } reset ( ) { this . isValid = undefined ; } afterAchievementCompletionReset ( ) { this . isValid = undefined ; } isCompleted ( ) { return this . isValid ; } test ( gameEvent ) { if ( gameEvent . type === GameEvent . GLOBAL_STATS_UPDATED ) { this . handleEvent ( gameEvent ) ; } } private handleEvent ( gameEvent ) { const stats = gameEvent . additionalData . stats ; const relevantStat = stats . stats . find ( ( stat ) => stat . statContext === this . targetContext && stat . statKey === this . targetKey ) ; this . isValid = relevantStat && relevantStat . value >= this . targetValue ; } }