Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions forge-game/src/main/java/forge/game/GameView.java
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ public int getGamesWonBy(LobbyPlayer questPlayer) {
}

public Deck getDeck(final PlayerView pv) {
if (getMatch() == null) { // transient, null on network clients after deserialization
return null;
}
for (final RegisteredPlayer rp : getMatch().getPlayers()) {
if (pv.isLobbyPlayer(rp.getPlayer())) {
return rp.getDeck();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public void viewDeckList() {
if (!isInGame() || getCurrentPlayer() == null) {
return;
}
final Deck deck = getGameView().getDeck(getCurrentPlayer());
final Deck deck = getDeckForPlayer(getCurrentPlayer());
if (deck != null) {
FDeckViewer.show(deck);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@
import forge.gui.framework.DragTab;
import forge.gui.framework.EDocID;
import forge.gui.framework.IVDoc;
import forge.localinstance.properties.ForgePreferences.FPref;
import forge.localinstance.skin.FSkinProp;
import forge.model.FModel;
import forge.screens.match.CMatchUI;
import forge.screens.match.controllers.CField;
import forge.toolbox.FLabel;
Expand Down Expand Up @@ -450,11 +448,11 @@ private String getCommanderBracketTooltipLine() {
if (gameType == GameType.Adventure || gameType == GameType.AdventureEvent) {
return null;
}
final int maximumBracket = FModel.getPreferences().getPrefInt(FPref.DECKGEN_MAXIMUM_COMMANDER_BRACKET);
final int maximumBracket = matchUI.getMaximumCommanderBracket();
if (maximumBracket < 1 || maximumBracket > 4) {
return null;
}
final Deck deck = matchUI.getGameView().getDeck(player);
final Deck deck = matchUI.getDeckForPlayer(player);
if (deck == null) {
return null;
}
Expand Down
33 changes: 33 additions & 0 deletions forge-gui/src/main/java/forge/gamemodes/match/AbstractGuiGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.common.collect.*;

import forge.deck.Deck;
import forge.game.GameEntityView;
import forge.game.GameEndReason;
import forge.game.GameLog;
Expand All @@ -21,6 +22,8 @@
import forge.gui.interfaces.IGuiGame;
import forge.gui.interfaces.IMayViewCards;
import forge.interfaces.IGameController;
import forge.localinstance.properties.ForgePreferences.FPref;
import forge.model.FModel;
import forge.player.PlayerControllerHuman;
import forge.player.PlayerZoneUpdate;
import forge.trackable.TrackableCollection;
Expand Down Expand Up @@ -106,6 +109,36 @@ public final GameView getGameView() {
return gameView;
}

// Network clients have no server-side match, so decks are only reachable through the lobby.
// Null on the host and in local games, where getGameView().getDeck() works directly.
private GameLobby clientLobby;

public final void setClientLobby(final GameLobby lobby) {
clientLobby = lobby;
}

public final Deck getDeckForPlayer(final PlayerView player) {
if (player == null) {
return null;
}
if (clientLobby != null) {
for (int i = 0; i < clientLobby.getNumberOfSlots(); i++) {
final LobbySlot slot = clientLobby.getSlot(i);
if (slot != null && player.getLobbyPlayerName().equals(slot.getName())) {
return slot.getDeck();
}
}
return null;
}
return gameView == null ? null : gameView.getDeck(player);
}

public final int getMaximumCommanderBracket() {
return clientLobby != null
? clientLobby.getData().getMaximumCommanderBracket()
: FModel.getPreferences().getPrefInt(FPref.DECKGEN_MAXIMUM_COMMANDER_BRACKET);
}

/**
* Receives a {@link GameView} snapshot and installs it as the GUI's view of game state.
* Called at game lifecycle boundaries (start, restart, recovery) and when a remote
Expand Down
7 changes: 7 additions & 0 deletions forge-gui/src/main/java/forge/gamemodes/match/GameLobby.java
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@ public final static class GameLobbyData implements Serializable {
private boolean limitedMode;
private String activeEventId;
private boolean activeConformance;
private int maximumCommanderBracket = 5; // mirrors DECKGEN_MAXIMUM_COMMANDER_BRACKET default (off)

public GameLobbyData() {
}
Expand Down Expand Up @@ -602,5 +603,11 @@ public boolean isActiveConformance() {
public void setActiveConformance(final boolean conformance) {
this.activeConformance = conformance;
}
public int getMaximumCommanderBracket() {
return maximumCommanderBracket;
}
public void setMaximumCommanderBracket(final int bracket) {
this.maximumCommanderBracket = bracket;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package forge.gamemodes.net;

import forge.gamemodes.match.AbstractGuiGame;
import forge.gamemodes.match.GameLobby.GameLobbyData;
import forge.gamemodes.match.LobbySlotType;
import forge.gamemodes.net.client.ClientGameLobby;
Expand Down Expand Up @@ -181,6 +182,9 @@ public static ChatMessage join(final String url, final IOnlineLobby onlineLobby,
final ClientGameLobby lobby = new ClientGameLobby();
final ILobbyView view = onlineLobby.setLobby(lobby);
lobby.setListener(view);
if (gui instanceof AbstractGuiGame agg) {
agg.setClientLobby(lobby);
}
client.addLobbyListener(new ILobbyListener() {
@Override
public void message(final String source, final String message, final ChatMessage.MessageType type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import forge.gui.util.SOptionPane;
import forge.interfaces.IGameController;
import forge.interfaces.ILobbyListener;
import forge.localinstance.properties.ForgePreferences.FPref;
import forge.model.FModel;
import forge.player.PlayerControllerHuman;
import forge.util.BuildInfo;
Expand Down Expand Up @@ -437,6 +438,8 @@ public void setDraftHandler(final IDraftEventHandler handler) {
}

public void updateLobbyState() {
localLobby.getData().setMaximumCommanderBracket(
FModel.getPreferences().getPrefInt(FPref.DECKGEN_MAXIMUM_COMMANDER_BRACKET));
final LobbyUpdateEvent event = new LobbyUpdateEvent(localLobby.getData());
broadcast(event);
}
Expand Down
Loading