import { GameEvent } from '../../../models/game-event' ; import { MainWindowState } from '../../../models/mainwindow/main-window-state' ; import { BattleMercenary , MercenariesBattleState } from '../../../models/mercenaries/mercenaries-battle-state' ; import { MercenariesParser } from './_mercenaries-parser' ; export class MercenariesZonePositionChangedParser implements MercenariesParser { public eventType = ( ) => GameEvent . ZONE_POSITION_CHANGED ; public applies = ( battleState ) => battleState != null ; public parse ( battleState , event , mainWindowState ) { const [ cardId , controllerId , localPlayer , entityId ] = event . parse ( ) ; const isPlayer = controllerId === localPlayer . PlayerId ; const team = isPlayer ? battleState . playerTeam : battleState . opponentTeam ; if ( ! team . mercenaries ?. map ( ( merc ) => merc . entityId ) . includes ( entityId ) ) { console . debug ( '[merc-zone-position] not about a merc, returning' , event ) ; return battleState ; } const newTeam = team . updateMercenary ( entityId , BattleMercenary . create ( { zonePosition : event . additionalData . zonePosition , } ) ) ; return battleState . update ( { playerTeam : isPlayer ? newTeam : battleState . playerTeam , opponentTeam : isPlayer ? battleState . opponentTeam : newTeam , } as MercenariesBattleState ) ; } }