import { GameEvent } from '../../../models/game-event' ; import { MainWindowState } from '../../../models/mainwindow/main-window-state' ; import { MercenariesAction , MercenariesBattleState } from '../../../models/mercenaries/mercenaries-battle-state' ; import { CardsFacadeService } from '../../cards-facade.service' ; import { MercenariesParser } from './_mercenaries-parser' ; export class MercenariesHeroDiedParser implements MercenariesParser { constructor ( private readonly allCards ) { } public eventType = ( ) => GameEvent . MINIONS_DIED ; public applies = ( battleState ) => battleState != null ; public parse ( battleState , event , mainWindowState ) { const [ , , localPlayer ] = event . parse ( ) ; const deadMinions = event . additionalData . deadMinions ; const deadEntityIds = deadMinions . map ( ( minion ) => minion . EntityId ) ; const actionQueue = battleState . actionQueue . filter ( ( a ) => ! deadEntityIds . includes ( a . ownerEntityId ) ) ; const battleStateWithActions = battleState . update ( { } ) ; if ( ! localPlayer ) { console . error ( '[merc-minions-died-parser] no local player present' , event ) ; return battleStateWithActions ; } let workingBattleState = battleStateWithActions ; for ( const deadMinion of deadMinions ) { const entityId = deadMinion . EntityId ; const controllerId = deadMinion . ControllerId ; const isPlayer = controllerId === localPlayer . PlayerId ; const team = isPlayer ? workingBattleState . playerTeam : workingBattleState . opponentTeam ; const newTeam = team . updateMercenary ( entityId , { isDead : true } ) ; workingBattleState = workingBattleState . update ( { playerTeam : isPlayer ? newTeam : workingBattleState . playerTeam , opponentTeam : isPlayer ? workingBattleState . opponentTeam : newTeam , } as MercenariesBattleState ) ; } return workingBattleState ; } }