import GameState from "../../../../GameState" ; import WildlingsAttackGameState from "../WildlingsAttackGameState" ; import Player from "../../../Player" ; import { ClientMessage } from "../../../../../messages/ClientMessage" ; import { ServerMessage } from "../../../../../messages/ServerMessage" ; import House from "../../../game-data-structure/House" ; import Game from "../../../game-data-structure/Game" ; import SimpleChoiceGameState , { SerializedSimpleChoiceGameState } from "../../../simple-choice-game-state/SimpleChoiceGameState" ; import SelectHouseCardGameState , { SerializedSelectHouseCardGameState } from "../../../select-house-card-game-state/SelectHouseCardGameState" ; import HouseCard , { HouseCardState } from "../../../game-data-structure/house-card/HouseCard" ; import IngameGameState from "../../../IngameGameState" ; export default class MammothRidersNightsWatchVictoryGameState extends GameState < WildlingsAttackGameState , SimpleChoiceGameState | SelectHouseCardGameState < MammothRidersNightsWatchVictoryGameState > > { get game ( ) : Game { return this . parentGameState . game ; } get ingame ( ) : IngameGameState { return this . parentGameState . parentGameState . ingame ; } firstStart ( ) { const house = this . parentGameState . highestBidder ; const usedHouseCards = this . getUsedHouseCards ( house ) ; if ( usedHouseCards . length == 0 ) { this . parentGameState . onWildlingCardExecuteEnd ( ) ; return ; } this . setChildGameState ( new SimpleChoiceGameState ( this ) ) . firstStart ( house , "" , [ "Retrieve a House card" , "Ignore" ] ) ; } onSimpleChoiceGameStateEnd ( choice ) { const house = this . childGameState . house ; if ( choice == 0 ) { this . setChildGameState ( new SelectHouseCardGameState ( this ) ) . firstStart ( house , this . getUsedHouseCards ( house ) ) ; } else { this . parentGameState . onWildlingCardExecuteEnd ( ) ; } } onSelectHouseCardFinish ( house , houseCard , resolvedAutomatically ) { houseCard . state = HouseCardState . AVAILABLE ; this . entireGame . broadcastToClients ( { type : "change-state-house-card" , houseId : house . id , cardIds : [ houseCard . id ] , state : HouseCardState . AVAILABLE } ) ; this . ingame . log ( { type : "mammoth-riders-return-card" , house : house . id , houseCard : houseCard . id } , resolvedAutomatically ) ; this . parentGameState . onWildlingCardExecuteEnd ( ) ; } getUsedHouseCards ( house ) { return house . houseCards . values . filter ( hc => hc . state == HouseCardState . USED ) ; } onPlayerMessage ( player , message ) { this . childGameState . onPlayerMessage ( player , message ) ; } onServerMessage ( _message ) { } serializeToClient ( admin , player ) { return { type : "mammoth-riders-nights-watch-victory" , childGameState : this . childGameState . serializeToClient ( admin , player ) } ; } static deserializeFromServer ( parent , data ) { const mammothRiders = new MammothRidersNightsWatchVictoryGameState ( parent ) ; mammothRiders . childGameState = mammothRiders . deserializeChildGameState ( data . childGameState ) ; return mammothRiders ; } deserializeChildGameState ( data ) { switch ( data . type ) { case "select-house-card" : return SelectHouseCardGameState . deserializeFromServer ( this , data ) ; case "simple-choice" : return SimpleChoiceGameState . deserializeFromServer ( this , data ) ; } } } export interface SerializedMammothRidersNightsWatchVictoryGameState { type : "mammoth-riders-nights-watch-victory" ; childGameState : SerializedSimpleChoiceGameState | SerializedSelectHouseCardGameState ; }