From 1bd2df2d28c879ca872947b2795825c48d849fb2 Mon Sep 17 00:00:00 2001 From: drdev Date: Thu, 13 Mar 2014 22:32:58 +0000 Subject: [PATCH] Ensure cards hidden if you shouldn't be able to see them --- .../src/main/java/forge/game/card/Card.java | 42 +++++++++++++++---- .../src/forge/screens/match/FControl.java | 19 ++++++++- 2 files changed, 51 insertions(+), 10 deletions(-) diff --git a/forge-game/src/main/java/forge/game/card/Card.java b/forge-game/src/main/java/forge/game/card/Card.java index 1e3166e9a27..2fdce652699 100644 --- a/forge-game/src/main/java/forge/game/card/Card.java +++ b/forge-game/src/main/java/forge/game/card/Card.java @@ -8528,19 +8528,43 @@ public class Card extends GameEntity implements Comparable { } public boolean canBeShownTo(final Player viewer) { - if (!isFaceDown()) { + Zone zone = this.getZone(); + if (zone == null) { return false; } //cards can't be shown if they're not in a zone + + switch (zone.getZoneType()) { + case Ante: + case Command: + case Exile: + case Battlefield: + case Graveyard: + case Stack: + //cards in these zones are visible to all + if (isFaceDown() && getController().isOpponentOf(viewer) && !hasKeyword("Your opponent may look at this card.")) { + break; //exception is face down cards controlled by opponents + } return true; - } - if (getController() == viewer && isInZone(ZoneType.Battlefield)) { + case Hand: + case Sideboard: + //face-up cards in these zones are hidden to opponents unless they specify otherwise + if (getController().isOpponentOf(viewer) && !hasKeyword("Your opponent may look at this card.")) { + break; + } return true; + case Library: + case PlanarDeck: + case SchemeDeck: + //cards in these zones are hidden to all unless they specify otherwise + if (getController() == viewer && hasKeyword("You may look at this card.")) { + return true; + } + if (getController().isOpponentOf(viewer) && hasKeyword("Your opponent may look at this card.")) { + return true; + } + break; } + + //one last check to see if card can be shown final Game game = this.getGame(); - if (getController() == viewer && hasKeyword("You may look at this card.")) { - return true; - } - if (getController().isOpponentOf(viewer) && hasKeyword("Your opponent may look at this card.")) { - return true; - } for (Card host : game.getCardsIn(ZoneType.Battlefield)) { final ArrayList staticAbilities = host.getStaticAbilities(); for (final StaticAbility stAb : staticAbilities) { diff --git a/forge-m-base/src/forge/screens/match/FControl.java b/forge-m-base/src/forge/screens/match/FControl.java index 07dfac485c0..9f6b3b8c44f 100644 --- a/forge-m-base/src/forge/screens/match/FControl.java +++ b/forge-m-base/src/forge/screens/match/FControl.java @@ -223,8 +223,25 @@ public class FControl { } } + public static Player getCurrentPlayer() { + // try current priority + Player currentPriority = game.getPhaseHandler().getPriorityPlayer(); + if (null != currentPriority && currentPriority.getLobbyPlayer() == FServer.getLobby().getGuiPlayer()) { + return currentPriority; + } + + // otherwise find just any player, belonging to this lobbyplayer + for (Player p : game.getPlayers()) { + if (p.getLobbyPlayer() == FServer.getLobby().getGuiPlayer()) { + return p; + } + } + + return null; + } + public static boolean mayShowCard(Card c) { - return true;// game == null || !gameHasHumanPlayer || c.canBeShownTo(getCurrentPlayer()); + return game == null || !gameHasHumanPlayer || c.canBeShownTo(getCurrentPlayer()); } public static void showCombat(Combat combat) {