diff --git a/agot-bg-game-server/src/common/ingame-game-state/planning-game-state/PlanningGameState.ts b/agot-bg-game-server/src/common/ingame-game-state/planning-game-state/PlanningGameState.ts index 302664626..a79d02d42 100644 --- a/agot-bg-game-server/src/common/ingame-game-state/planning-game-state/PlanningGameState.ts +++ b/agot-bg-game-server/src/common/ingame-game-state/planning-game-state/PlanningGameState.ts @@ -51,10 +51,13 @@ export default class PlanningGameState extends GameState { }); this.planningRestrictions = planningRestrictions; - } - isOrderAvailable(house: House, order: Order): boolean { - return this.getAvailableOrders(house).includes(order); + // Automatically set ready for houses which don't have units left + this.game.houses.forEach(h => { + if (this.getPossibleRegionsForOrders(h).length == 0) { + this.setReady(this.ingameGameState.getControllerOfHouse(h)); + } + }); } onPlayerMessage(player: Player, message: ClientMessage): void { @@ -99,30 +102,30 @@ export default class PlanningGameState extends GameState { }) } } else if (message.type == "ready") { - if (this.readyPlayers.includes(player)) { - return; - } - - if (!this.canReady(player.house).status) { - return; - } + this.setReady(player); + } + } - this.readyPlayers.push(player); + private setReady(player: Player): void { + if (this.readyPlayers.includes(player)) { + return; + } - // Check if all player are ready to go the action entireGame state - if (this.readyPlayers.length == this.ingameGameState.players.values.length) { - this.ingameGameState.proceedToActionGameState(this.placedOrders as BetterMap, this.planningRestrictions); - } else { - this.entireGame.broadcastToClients({ - type: "player-ready", - userId: player.user.id - }); - } + if (!this.canReady(player.house).status) { + return; } - } - getPossibleRegionsForOrders(house: House): Region[] { - return this.game.world.getControlledRegions(house).filter(r => r.units.size > 0); + this.readyPlayers.push(player); + + // Check if all player are ready to go the action entireGame state + if (this.readyPlayers.length == this.ingameGameState.players.values.length) { + this.ingameGameState.proceedToActionGameState(this.placedOrders as BetterMap, this.planningRestrictions); + } else { + this.entireGame.broadcastToClients({ + type: "player-ready", + userId: player.user.id + }); + } } serializeToClient(admin: boolean, player: Player | null): SerializedPlanningGameState { @@ -147,7 +150,15 @@ export default class PlanningGameState extends GameState { * Common */ - canReady(house: House): {status: boolean; reason: string} { + getPossibleRegionsForOrders(house: House): Region[] { + return this.game.world.getControlledRegions(house).filter(r => r.units.size > 0); + } + + isOrderAvailable(house: House, order: Order): boolean { + return this.getAvailableOrders(house).includes(order); + } + + canReady(house: House): {status: boolean; reason: string} { const possibleRegions = this.getPossibleRegionsForOrders(house); if (possibleRegions.every(r => this.placedOrders.has(r)))