import GameState from "../../GameState" ; import Game from "../game-data-structure/Game" ; import House from "../game-data-structure/House" ; import HouseCard from "../game-data-structure/house-card/HouseCard" ; import { ServerMessage } from "../../../messages/ServerMessage" ; import Player from "../Player" ; import { ClientMessage } from "../../../messages/ClientMessage" ; import IngameGameState from "../IngameGameState" ; import User from "../../../server/User" ; interface ParentGameState extends GameState < any , any > { game : Game ; ingame : IngameGameState ; onSelectHouseCardFinish ( house , houseCard , resolvedAutomatically ) : void ; } export default class SelectHouseCardGameState < P extends ParentGameState > extends GameState < P > { house : House ; houseCards : HouseCard [ ] ; firstStart ( house , houseCards ) { this . house = house ; this . houseCards = houseCards ; if ( houseCards . length == 0 ) { throw new Error ( "SelectHouseCardGameState called with houseCards.length == 0!" ) ; } if ( houseCards . length == 1 ) { this . parentGameState . onSelectHouseCardFinish ( house , houseCards [ 0 ] , true ) ; } } select ( houseCard ) { this . parentGameState . entireGame . sendMessageToServer ( { type : "select-house-card" , houseCard : houseCard . id } ) ; } onPlayerMessage ( player , message ) { if ( message . type == "select-house-card" ) { const houseCard = this . parentGameState . game . getHouseCardById ( message . houseCard ) ; if ( this . parentGameState . ingame . getControllerOfHouse ( this . house ) != player ) { return ; } if ( ! this . houseCards . includes ( houseCard ) ) { return ; } this . parentGameState . onSelectHouseCardFinish ( this . house , houseCard , false ) ; } } getWaitedUsers ( ) { return [ this . parentGameState . ingame . getControllerOfHouse ( this . house ) . user ] ; } onServerMessage ( _message ) { } serializeToClient ( _admin , _player ) { return { type : "select-house-card" , house : this . house . id , houseCards : this . houseCards . map ( hc => hc . id ) } ; } static deserializeFromServer < P extends ParentGameState > ( parent , data ) { const selectHouseCardGameState = new SelectHouseCardGameState ( parent ) ; selectHouseCardGameState . house = parent . game . houses . get ( data . house ) ; selectHouseCardGameState . houseCards = data . houseCards . map ( hcid => parent . game . getHouseCardById ( hcid ) ) ; return selectHouseCardGameState ; } } export interface SerializedSelectHouseCardGameState { type : "select-house-card" ; house : string ; houseCards : string [ ] ; }