Skip to content

Commit

Permalink
Merge pull request #1817 from gereon77/hide-house-cards-for-blind-draft
Browse files Browse the repository at this point in the history
Hide house cards for blind draft
  • Loading branch information
gereon77 authored Feb 6, 2024
2 parents cffb6ed + 9b4b7bf commit d2bd61b
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 45 deletions.
2 changes: 1 addition & 1 deletion agot-bg-game-server/src/client/GameLogListComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default class GameLogListComponent extends Component<GameLogListComponent
}

get fogOfWar(): boolean {
return !this.ingame.isEnded && !this.ingame.isCancelled && this.ingame.fogOfWar;
return !this.ingame.isEndedOrCancelled && this.ingame.fogOfWar;
}

createHouseCards(data: [string, HouseCardData][]): [string, HouseCard][] {
Expand Down
3 changes: 2 additions & 1 deletion agot-bg-game-server/src/client/GameSettingsComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,8 @@ export default class GameSettingsComponent extends Component<GameSettingsCompone
label={
<OverlayTrigger overlay={
<Tooltip id="blind-draft-tooltip">
Players receive random House cards and Influence positions. Can be combined with <i>Limited Draft</i>.
Players receive random House cards and Influence positions. House cards remain hidden throughout the game.
Can be combined with <i>Limited Draft</i>.
</Tooltip>}>
<label htmlFor="blind-draft-setting">Blind Draft</label>
</OverlayTrigger>}
Expand Down
71 changes: 35 additions & 36 deletions agot-bg-game-server/src/client/HouseRowComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default class HouseRowComponent extends Component<HouseRowComponentProps>

render(): ReactNode {
const isVassal = this.ingame.isVassalHouse(this.house);
const gameRunning = !this.ingame.isEnded && !this.ingame.isCancelled;
const gameRunning = !this.ingame.isEndedOrCancelled;

// We crop the victory points to victoryCountsNeededToWin but in the UI we want to show if a player was able to gain more VPs
const victoryPoints = this.ingame.entireGame.isFeastForCrows
Expand Down Expand Up @@ -298,7 +298,15 @@ export default class HouseRowComponent extends Component<HouseRowComponentProps>
)}
<Col xs="auto">
<Row className="justify-content-center">
{this.renderHouseCards(isVassal)}
{!isVassal
? this.renderPlayerHouseCards()
: _.sortBy(this.game.vassalHouseCards.values, hc => hc.combatStrength).map(hc => (
<Col xs="auto" key={`vassal-cards_${this.house.id}_${hc.id}`}>
<HouseCardComponent
houseCard={hc}
size="tiny" />
</Col>
))}
</Row>
{this.house.laterHouseCards != null && !isVassal &&
<Row className="justify-content-center">
Expand All @@ -325,53 +333,44 @@ export default class HouseRowComponent extends Component<HouseRowComponentProps>
</>;
}

private renderHouseCards(isVassal: boolean): ReactNode {
const showAllOtherPlayerHouseCards = !this.ingame.hasChildGameState(ThematicDraftHouseCardsGameState);
renderPlayerHouseCards(): ReactNode {
const showOnlyCardBacksForOtherHouses = this.ingame.hasChildGameState(ThematicDraftHouseCardsGameState)
|| (this.ingame.entireGame.gameSettings.blindDraft && !this.ingame.isEndedOrCancelled);
const doesControlCurrentHouse = this.props.gameClient.doesControlHouse(this.house);

const chooseHouseCards = this.ingame.hasChildGameState(ChooseHouseCardGameState) ? this.ingame.getChildGameState(ChooseHouseCardGameState) as ChooseHouseCardGameState : null;
const isCommandingVassalInCombat = chooseHouseCards?.combatGameState.isCommandingVassalInCombat(this.house) ?? false;

return !isVassal
? (showAllOtherPlayerHouseCards || this.props.gameClient.doesControlHouse(this.house))
? this.renderPlayerHouseCards()
: null
: _.sortBy(this.game.vassalHouseCards.values, hc => hc.combatStrength).map(hc => (
<Col xs="auto" key={`vassal-cards_${this.house.id}_${hc.id}`}>
if (isCommandingVassalInCombat) {
return _.range(0, 3).map(i => <Col xs="auto" key={`vassal-combat_back_${this.house.id}_${i}`}>
<div className="vertical-game-card tiny" style={{
backgroundImage: `url(${houseCardsBackImages.get("vassal")})`
}}/>
</Col>);
}

if (!showOnlyCardBacksForOtherHouses || doesControlCurrentHouse) {
return _.sortBy(this.house.houseCards.values, hc => hc.combatStrength).map(hc => (
<Col xs="auto" key={`house-card_${this.house.id}_${hc.id}`}>
{hc.state == HouseCardState.AVAILABLE ? (
<HouseCardComponent
houseCard={hc}
size="tiny" />
) : (
<HouseCardBackComponent
house={null}
house={this.house}
houseCard={hc}
size="tiny" />
)}
</Col>
));
}

renderPlayerHouseCards(): ReactNode {
const chooseHouseCards = this.ingame.hasChildGameState(ChooseHouseCardGameState) ? this.ingame.getChildGameState(ChooseHouseCardGameState) as ChooseHouseCardGameState : null;
const isCommandingVassalInCombat = chooseHouseCards?.combatGameState.isCommandingVassalInCombat(this.house) ?? false;
}

return isCommandingVassalInCombat
? _.range(0, 3).map(i => <Col xs="auto" key={`vassal-combat_back_${this.house.id}_${i}`}>
<div className="vertical-game-card tiny" style={{
backgroundImage: `url(${houseCardsBackImages.get("vassal")})`
}}/>
</Col>)
: _.sortBy(this.house.houseCards.values, hc => hc.combatStrength).map(hc => (
<Col xs="auto" key={`house-card_${this.house.id}_${hc.id}`}>
{hc.state == HouseCardState.AVAILABLE ? (
<HouseCardComponent
houseCard={hc}
size="tiny" />
) : (
<HouseCardBackComponent
house={this.house}
houseCard={hc}
size="tiny" />
)}
</Col>
));
return _.range(0, this.house.houseCards.size).map(i => <Col xs="auto" key={`house-card_${this.house.id}_${i}`}>
<div className="vertical-game-card tiny" style={{
backgroundImage: `url(${houseCardsBackImages.get(this.house.id)})`
}}/>
</Col>);
}

renderVassalDropDownItems(): ReactNode {
Expand Down
2 changes: 1 addition & 1 deletion agot-bg-game-server/src/client/IngameComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ export default class IngameComponent extends Component<IngameComponentProps> {
this.authenticatedPlayer.house.knowsNextWildlingCard;
const nextWildlingCard = this.game.wildlingDeck.find(c => c.id == this.game.clientNextWildlingCardId);

const gameRunning = !this.ingame.isEnded && !this.ingame.isCancelled;
const gameRunning = !this.ingame.isEndedOrCancelled;
const roundWarning = gameRunning && (this.game.maxTurns - this.game.turn) == 1;
const roundCritical = gameRunning && (this.game.turn == this.game.maxTurns);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ export default class IngameGameState extends GameState<
return this.childGameState instanceof CancelledGameState;
}

get isEndedOrCancelled(): boolean {
return this.isEnded || this.isCancelled;
}

get fogOfWar(): boolean {
return this.entireGame.gameSettings.fogOfWar;
}
Expand Down Expand Up @@ -1589,7 +1593,7 @@ export default class IngameGameState extends GameState<
}

getVisibleRegionsForPlayer(player: Player | null): Region[] {
if (!this.fogOfWar || this.isCancelled || this.isEnded) {
if (!this.fogOfWar || this.isEndedOrCancelled) {
return this.world.regions.values;
}

Expand All @@ -1605,7 +1609,7 @@ export default class IngameGameState extends GameState<
return [];
}

if (this.isCancelled || this.isEnded) {
if (this.isEndedOrCancelled) {
return this.world.regions.values;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ const fogOfWarBannedLogs = [
'orders-revealed'
];

const blindDraftBannedLogs = [
'orders-revealed',
'house-cards-returned',
'roose-bolton-house-cards-returned',
'massing-on-the-milkwater-house-cards-back'
];

export default class GameLogManager {
ingameGameState: IngameGameState;
@observable logs: GameLog[] = [];
Expand All @@ -26,11 +33,20 @@ export default class GameLogManager {
}

private logFilter = (log: GameLog): boolean => {
if (this.ingameGameState.isEndedOrCancelled) return true;
return this.fogOfWarFilter(log) && this.blindDraftFilter(log);
}

private fogOfWarFilter = (log: GameLog): boolean => {
if (!this.ingameGameState.fogOfWar) return true;
if (this.ingameGameState.isEnded || this.ingameGameState.isCancelled) return true;
return !fogOfWarBannedLogs.includes(log.data.type);
}

private blindDraftFilter = (log: GameLog): boolean => {
if (!this.ingameGameState.entireGame.gameSettings.blindDraft) return true;
return !blindDraftBannedLogs.includes(log.data.type);
}

log(data: GameLogData, resolvedAutomatically = false): void {
const time = new Date();
const log = {data, time, resolvedAutomatically};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import Game from "./Game";
import { ObjectiveCard, SpecialObjectiveCard } from "./static-data-structure/ObjectiveCard";
import Player from "../Player";
import { objectiveCards, specialObjectiveCards } from "./static-data-structure/objectiveCards";
import ThematicDraftHouseCardsGameState from "../thematic-draft-house-cards-game-state/ThematicDraftHouseCardsGameState";

export default class House {
id: string;
Expand Down
4 changes: 2 additions & 2 deletions agot-bg-game-server/src/server/GlobalServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ export default class GlobalServer {
}

if (!entireGame.gameSettings.onlyLive || !entireGame.ingameGameState
|| entireGame.ingameGameState.isEnded || entireGame.ingameGameState.isCancelled) {
|| entireGame.ingameGameState.isEndedOrCancelled) {
return;
}

Expand Down Expand Up @@ -553,7 +553,7 @@ export default class GlobalServer {

if (entireGame.gameSettings.onlyLive && entireGame.ingameGameState) {
const ingame = entireGame.ingameGameState;
if (!ingame.isEnded && !ingame.isCancelled) {
if (!ingame.isEndedOrCancelled) {
// Do not unload running clock games until they are finished
return;
}
Expand Down

0 comments on commit d2bd61b

Please sign in to comment.