import { GameEvent } from '../../../../../../models/game-event' ; import { normalizeHeroCardId } from '../../../../bgs-utils' ; import { HpTurnInfo , RealTimeStatsState } from '../../real-time-stats' ; import { EventParser } from '../_event-parser' ; export class RTStatBgsTurnStartParser implements EventParser { applies ( gameEvent , currentState ) { return ( gameEvent . type === GameEvent . BATTLEGROUNDS_RECRUIT_PHASE || gameEvent . type === GameEvent . BATTLEGROUNDS_COMBAT_START ) ; } parse ( gameEvent , currentState ) { const heroesFromGame = gameEvent . additionalData . heroes ; const newCurrentTurn = Math . ceil ( gameEvent . additionalData . turnNumber / 2 ) ; const hpOverTurn = currentState . hpOverTurn ; for ( const hero of Object . keys ( hpOverTurn ) ) { const existingStats = hpOverTurn [ hero ] ; if ( ! existingStats ?. length ) { continue ; } const { currentHp , currentArmor } = this . getHpForHero ( hero , heroesFromGame ) ; const newStats = [ ... existingStats . filter ( ( stat ) => stat . turn !== newCurrentTurn ) , { turn : newCurrentTurn , value : currentHp ?? 0 , armor : currentArmor ?? 0 , } , ] ; hpOverTurn [ hero ] = newStats ; } return currentState . update ( { hpOverTurn : hpOverTurn , } as RealTimeStatsState ) ; } private getHpForHero ( heroCardId , heroes ) { const hero = heroes . find ( ( h ) => normalizeHeroCardId ( h . CardId ) === normalizeHeroCardId ( heroCardId ) ) ; if ( ! hero ) { console . warn ( 'could not find hero' , heroCardId , heroes ) ; } return { currentHp : hero ?. Health , currentArmor : hero ?. Armor , } ; } name ( ) { return 'RTStatBgsTurnStartParser' ; } } interface Hero { readonly CardId : string ; readonly EntityId : number ; readonly Health : number ; readonly Armor : number ; }