import { GameType } from '@firestone-hs/reference-data' ; import { GameEvent } from '../../../../../../models/game-event' ; import { normalizeHeroCardId } from '../../../../bgs-utils' ; import { RealTimeStatsState } from '../../real-time-stats' ; import { EventParser } from '../_event-parser' ; export class RTStatsBgsOpponentRevealedParser implements EventParser { applies ( gameEvent , currentState ) { return ( [ GameType . GT_BATTLEGROUNDS , GameType . GT_BATTLEGROUNDS_FRIENDLY ] . includes ( currentState . gameType ) && gameEvent . type === GameEvent . BATTLEGROUNDS_OPPONENT_REVEALED ) ; } parse ( gameEvent , currentState ) { const heroCardId = normalizeHeroCardId ( gameEvent . additionalData . cardId ) ; const health = gameEvent . additionalData . health ; const turn = currentState . reconnectOngoing ? currentState . currentTurn : 0 ; const hpOverTurn = currentState . hpOverTurn ; const existingData = hpOverTurn [ heroCardId ] ?? [ ] ; const newData = [ ... existingData . filter ( ( data ) => data . turn !== turn ) , { turn : turn , value : turn === 0 || existingData . length === 0 ? health : existingData [ existingData . length - 1 ] . value , armor : 0 , } , ] ; console . debug ( 'bgs damage armor opponentRevealed' , heroCardId , newData , hpOverTurn [ heroCardId ] ) ; hpOverTurn [ heroCardId ] = newData ; return currentState . update ( { hpOverTurn : hpOverTurn , } as RealTimeStatsState ) ; } name ( ) { return 'RTStatsBgsOpponentRevealedParser' ; } }