Skip to content

Commit

Permalink
Merge pull request #1791 from gereon77/add-hold-vps-option
Browse files Browse the repository at this point in the history
Add Hold VPs option
  • Loading branch information
gereon77 authored Jul 6, 2023
2 parents 5fb4ae7 + 29e2dc0 commit e301f4d
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 5 deletions.
3 changes: 2 additions & 1 deletion agot-bg-game-server/src/client/EntireGameComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ export default class EntireGameComponent extends Component<EntireGameComponentPr
<Col xs="auto">
<h4><Badge variant="danger">PAUSED</Badge></h4>
</Col>}
{(this.settings.victoryPointsCountNeededToWin != 7 || this.settings.loyaltyTokenCountNeededToWin != 7) &&
{(this.settings.victoryPointsCountNeededToWin != 7 || this.settings.loyaltyTokenCountNeededToWin != 7 || this.settings.holdVictoryPointsUntilEndOfRound) &&
<Col xs="auto">
<OverlayTrigger
placement="auto"
Expand All @@ -263,6 +263,7 @@ export default class EntireGameComponent extends Component<EntireGameComponentPr
</h6></p>}
<>Required victory points: <b className="text-large">{this.settings.victoryPointsCountNeededToWin}</b></>
{this.settings.playerCount >= 8 && <><br/>Required loyalty tokens: <b className="text-large">{this.settings.loyaltyTokenCountNeededToWin}</b></>}
{this.settings.holdVictoryPointsUntilEndOfRound && <><br/>Players have to hold {this.settings.victoryPointsCountNeededToWin} victory points until the end of the round to win the game!</>}
</div>
</Tooltip>}
popperConfig={{ modifiers: [preventOverflow] }}
Expand Down
16 changes: 16 additions & 0 deletions agot-bg-game-server/src/client/GameSettingsComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,22 @@ export default class GameSettingsComponent extends Component<GameSettingsCompone
onChange={() => this.changeGameSettings(() => this.gameSettings.useVassalPositions = !this.gameSettings.useVassalPositions)}
/>
</Col>
<Col xs="12">
<FormCheck
id="hold-vps-setting"
type="switch"
label={
<OverlayTrigger overlay={
<Tooltip id="hold-vps-setting-tooltip">
When this option is enabled, players do not win immediately when they score their 7th victory point.
Instead, to win the game, players must hold 7 victory points until the end of the round.
</Tooltip>}>
<label htmlFor="hold-vps-setting">Hold victory points</label>
</OverlayTrigger>}
checked={this.gameSettings.holdVictoryPointsUntilEndOfRound}
onChange={() => this.changeGameSettings(() => this.gameSettings.holdVictoryPointsUntilEndOfRound = !this.gameSettings.holdVictoryPointsUntilEndOfRound)}
/>
</Col>
<Col xs="12">
<FormCheck
id="tournament-mode-setting"
Expand Down
3 changes: 2 additions & 1 deletion agot-bg-game-server/src/common/EntireGame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default class EntireGame extends GameState<null, LobbyGameState | IngameG
draftHouseCards: false, thematicDraft: false, limitedDraft: false, blindDraft: false,
mixedWesterosDeck1: false, cokWesterosPhase: false, victoryPointsCountNeededToWin: 7, loyaltyTokenCountNeededToWin: 7, endless: false, faceless: false,
useVassalPositions: false, precedingMustering: false, randomStartPositions: false, initialLiveClock: 60,
noPrivateChats: false, tournamentMode: false, fixedClock: false
noPrivateChats: false, tournamentMode: false, fixedClock: false, holdVictoryPointsUntilEndOfRound: false
};

onSendClientMessage?: (message: ClientMessage) => void;
Expand Down Expand Up @@ -801,4 +801,5 @@ export interface GameSettings {
noPrivateChats: boolean;
tournamentMode: boolean;
fixedClock: boolean;
holdVictoryPointsUntilEndOfRound: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,10 @@ export default class IngameGameState extends GameState<
}

beginNewRound(): void {
if (this.checkVictoryConditions(true)) {
return;
}

if (this.game.turn == this.game.maxTurns) {
const winner = this.game.getPotentialWinner(true);
this.setChildGameState(new GameEndedGameState(this)).firstStart(winner);
Expand Down Expand Up @@ -726,7 +730,11 @@ export default class IngameGameState extends GameState<
});
}

checkVictoryConditions(): boolean {
checkVictoryConditions(isCheckAtEndOfRound = false): boolean {
if (this.entireGame.gameSettings.holdVictoryPointsUntilEndOfRound && !isCheckAtEndOfRound) {
return false;
}

if (this.game.areVictoryConditionsFulfilled()) {
// Game is finished
this.setChildGameState(new GameEndedGameState(this)).firstStart(this.game.getPotentialWinner());
Expand Down
2 changes: 1 addition & 1 deletion agot-bg-game-server/src/server/GlobalServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ export default class GlobalServer {
this.loadedGames.delete(entireGame.id);
}

async performLongRunningOperations(): Promise<void> {
async runBackgroundTasks(): Promise<void> {
while (true) {
await sleep(10 * 60 * 1000);

Expand Down
2 changes: 1 addition & 1 deletion agot-bg-game-server/src/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ const wsServer = new Server({port: parseInt(process.env.PORT || "5000")});

const globalServer = new GlobalServer(wsServer);
globalServer.start();
globalServer.performLongRunningOperations();
globalServer.runBackgroundTasks();

0 comments on commit e301f4d

Please sign in to comment.