import SelectUnitsGameState , { SerializedSelectUnitsGameState } from "../../../select-units-game-state/SelectUnitsGameState" ; import Player from "../../../Player" ; import House from "../../../game-data-structure/House" ; import WildlingCardEffectInTurnOrderGameState from "../WildlingCardEffectInTurnOrderGameState" ; import Unit from "../../../game-data-structure/Unit" ; import Region from "../../../game-data-structure/Region" ; import { ClientMessage } from "../../../../../messages/ClientMessage" ; import { ServerMessage } from "../../../../../messages/ServerMessage" ; import WildlingsAttackGameState from "../WildlingsAttackGameState" ; import IngameGameState from "../../../IngameGameState" ; export default class MammothRidersWildlingVictoryGameState extends WildlingCardEffectInTurnOrderGameState < SelectUnitsGameState < MammothRidersWildlingVictoryGameState > > { get ingame ( ) : IngameGameState { return this . parentGameState . parentGameState . ingame ; } executeForLowestBidder ( house ) { this . executeForHouse ( house , 3 ) ; } executeForEveryoneElse ( house ) { this . executeForHouse ( house , 2 ) ; } executeForHouse ( house , count ) { const units = this . game . world . getUnitsOfHouse ( house ) ; count = Math . min ( count , units . length ) ; if ( units . length > 0 ) { this . setChildGameState ( new SelectUnitsGameState ( this ) ) . firstStart ( house , units , count ) ; } else { this . ingame . log ( { type : "mammoth-riders-destroy-units" , house : house . id , units : [ ] } , true ) ; this . proceedNextHouse ( house ) ; } } onPlayerMessage ( player , message ) { this . childGameState . onPlayerMessage ( player , message ) ; } onServerMessage ( _message ) { } onSelectUnitsEnd ( house , selectedUnits , resolvedAutomatically ) { selectedUnits . forEach ( ( [ region , units ] ) => { units . forEach ( u => region . units . delete ( u . id ) ) ; this . entireGame . broadcastToClients ( { type : "remove-units" , unitIds : units . map ( u => u . id ) , regionId : region . id } ) ; } ) ; this . ingame . log ( { type : "mammoth-riders-destroy-units" , house : house . id , units : selectedUnits . map ( ( [ region , units ] ) => [ region . id , units . map ( u => u . type . id ) ] ) } , resolvedAutomatically ) ; this . proceedNextHouse ( house ) ; } serializeToClient ( admin , player ) { return { type : "mammoth-riders-wildling-victory" , childGameState : this . childGameState . serializeToClient ( admin , player ) } ; } static deserializeFromServer ( wildlingsAttack , data ) { const mammothRiders = new MammothRidersWildlingVictoryGameState ( wildlingsAttack ) ; mammothRiders . childGameState = mammothRiders . deserializeChildGameState ( data . childGameState ) ; return mammothRiders ; } deserializeChildGameState ( data ) { return SelectUnitsGameState . deserializeFromServer ( this , data ) ; } } export interface SerializedMammothRidersWildlingVictoryGameState { type : "mammoth-riders-wildling-victory" ; childGameState : SerializedSelectUnitsGameState ; }