diff --git a/Mage.Common/src/main/java/mage/view/CardView.java b/Mage.Common/src/main/java/mage/view/CardView.java index e5fd2d57df..de64900049 100644 --- a/Mage.Common/src/main/java/mage/view/CardView.java +++ b/Mage.Common/src/main/java/mage/view/CardView.java @@ -121,8 +121,17 @@ public class CardView extends SimpleCardView { protected Card originalCard = null; + /** + * Non game usage like deck editor + * + * @param card + */ public CardView(Card card) { - this(card, null, false); + this(card, (Game) null); + } + + public CardView(Card card, Game game) { + this(card, game, false); } public CardView(Card card, SimpleCardView simpleCardView) { @@ -450,7 +459,7 @@ public class CardView extends SimpleCardView { Card secondSideCard = card.getSecondCardFace(); if (secondSideCard != null) { - this.secondCardFace = new CardView(secondSideCard); + this.secondCardFace = new CardView(secondSideCard, game); this.alternateName = secondCardFace.getName(); this.originalName = card.getName(); } @@ -464,7 +473,7 @@ public class CardView extends SimpleCardView { if (card instanceof ModalDoubleFacesCard) { this.transformable = true; // enable GUI day/night button ModalDoubleFacesCard mdfCard = (ModalDoubleFacesCard) card; - this.secondCardFace = new CardView(mdfCard.getRightHalfCard()); + this.secondCardFace = new CardView(mdfCard.getRightHalfCard(), game); this.alternateName = mdfCard.getRightHalfCard().getName(); this.originalName = card.getName(); } diff --git a/Mage.Common/src/main/java/mage/view/CardsView.java b/Mage.Common/src/main/java/mage/view/CardsView.java index d83ac6a91e..084cd0895a 100644 --- a/Mage.Common/src/main/java/mage/view/CardsView.java +++ b/Mage.Common/src/main/java/mage/view/CardsView.java @@ -6,7 +6,6 @@ import mage.abilities.effects.Effect; import mage.cards.Card; import mage.constants.Zone; import mage.game.Game; -import mage.game.GameState; import mage.game.command.Emblem; import mage.game.command.Plane; import mage.game.permanent.Permanent; @@ -29,7 +28,7 @@ public class CardsView extends LinkedHashMap { } /** - * Uses for card render tests + * Non game usage like card render tests * * @param cardViews */ @@ -39,6 +38,11 @@ public class CardsView extends LinkedHashMap { } } + /** + * Non game usage like deck editor + * + * @param cards + */ public CardsView(Collection cards) { for (Card card : cards) { this.put(card.getId(), new CardView(card)); @@ -116,9 +120,9 @@ public class CardsView extends LinkedHashMap { if (abilityView == null) { CardView sourceCardView; if (isPermanent) { - sourceCardView = new CardView((Permanent) sourceObject); + sourceCardView = new CardView((Permanent) sourceObject, game); } else if (isCard) { - sourceCardView = new CardView((Card) sourceObject); + sourceCardView = new CardView((Card) sourceObject, game); } else { sourceCardView = new CardView(sourceObject, game); } @@ -164,14 +168,4 @@ public class CardsView extends LinkedHashMap { + abilities.stream().map(a -> a.getClass().getSimpleName() + " - " + a.getRule()).collect(Collectors.joining("\n"))); } } - - public CardsView(Collection abilities, GameState state) { - for (Ability ability : abilities) { - Card sourceCard = state.getPermanent(ability.getSourceId()); - if (sourceCard != null) { - this.put(ability.getId(), new AbilityView(ability, sourceCard.getName(), new CardView(sourceCard))); - } - } - } - } diff --git a/Mage.Common/src/main/java/mage/view/GameView.java b/Mage.Common/src/main/java/mage/view/GameView.java index 3f703c7678..14bd2c3405 100644 --- a/Mage.Common/src/main/java/mage/view/GameView.java +++ b/Mage.Common/src/main/java/mage/view/GameView.java @@ -94,7 +94,7 @@ public class GameView implements Serializable { stack.put(stackObject.getId(), new StackAbilityView(game, (StackAbility) stackObject, card.getName(), new CardView(card, game, false, false, false))); } } else { - stack.put(stackObject.getId(), new StackAbilityView(game, (StackAbility) stackObject, "", new CardView(card))); + stack.put(stackObject.getId(), new StackAbilityView(game, (StackAbility) stackObject, "", new CardView(card, game))); } if (card.isTransformable()) { updateLatestCardView(game, card, stackObject.getId()); @@ -103,7 +103,7 @@ public class GameView implements Serializable { } else if (object != null) { if (object instanceof PermanentToken) { PermanentToken token = (PermanentToken) object; - stack.put(stackObject.getId(), new StackAbilityView(game, (StackAbility) stackObject, token.getName(), new CardView(token))); + stack.put(stackObject.getId(), new StackAbilityView(game, (StackAbility) stackObject, token.getName(), new CardView(token, game))); checkPaid(stackObject.getId(), (StackAbility) stackObject); } else if (object instanceof Emblem) { CardView cardView = new CardView(new EmblemView((Emblem) object)); diff --git a/Mage.Common/src/main/java/mage/view/PermanentView.java b/Mage.Common/src/main/java/mage/view/PermanentView.java index 2031e797ee..c72f910a9b 100644 --- a/Mage.Common/src/main/java/mage/view/PermanentView.java +++ b/Mage.Common/src/main/java/mage/view/PermanentView.java @@ -1,9 +1,5 @@ - package mage.view; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.TurnFaceUpAbility; import mage.cards.Card; @@ -12,8 +8,11 @@ import mage.game.permanent.Permanent; import mage.game.permanent.PermanentToken; import mage.players.Player; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + /** - * * @author BetaSteward_at_googlemail.com */ public class PermanentView extends CardView { @@ -36,8 +35,8 @@ public class PermanentView extends CardView { private final boolean attachedToPermanent; public PermanentView(Permanent permanent, Card card, UUID createdForPlayerId, Game game) { - super(permanent, game, (permanent.getControllerId() == null) ? false : permanent.getControllerId().equals(createdForPlayerId)); - this.controlled = (permanent.getControllerId() == null) ? false : permanent.getControllerId().equals(createdForPlayerId); + super(permanent, game, permanent.getControllerId() != null && permanent.getControllerId().equals(createdForPlayerId)); + this.controlled = permanent.getControllerId() != null && permanent.getControllerId().equals(createdForPlayerId); this.rules = permanent.getRules(game); this.tapped = permanent.isTapped(); this.flipped = permanent.isFlipped(); @@ -59,7 +58,7 @@ public class PermanentView extends CardView { } else { if (card != null) { // original may not be face down - original = new CardView(card); + original = new CardView(card, game); } else { original = null; } diff --git a/Mage.Common/src/main/java/mage/view/PlayerView.java b/Mage.Common/src/main/java/mage/view/PlayerView.java index 2269530dc6..fd31146a6c 100644 --- a/Mage.Common/src/main/java/mage/view/PlayerView.java +++ b/Mage.Common/src/main/java/mage/view/PlayerView.java @@ -1,13 +1,5 @@ - package mage.view; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.ConcurrentModificationException; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; import mage.cards.Card; import mage.counters.Counters; import mage.designations.Designation; @@ -22,6 +14,9 @@ import mage.game.permanent.Permanent; import mage.players.Player; import mage.players.net.UserData; +import java.io.Serializable; +import java.util.*; + /** * @author BetaSteward_at_googlemail.com */ @@ -105,7 +100,7 @@ public class PlayerView implements Serializable { } Card cardOnTop = (player.isTopCardRevealed() && player.getLibrary().hasCards()) ? player.getLibrary().getFromTop(game) : null; - this.topCard = cardOnTop != null ? new CardView(cardOnTop) : null; + this.topCard = cardOnTop != null ? new CardView(cardOnTop, game) : null; if (player.getUserData() != null) { this.userData = player.getUserData(); } else { diff --git a/Mage.Server/src/main/java/mage/server/game/GameController.java b/Mage.Server/src/main/java/mage/server/game/GameController.java index ab3b8fcb8d..3de2c5f5cd 100644 --- a/Mage.Server/src/main/java/mage/server/game/GameController.java +++ b/Mage.Server/src/main/java/mage/server/game/GameController.java @@ -784,7 +784,7 @@ public class GameController implements GameCallback { } private synchronized void choosePile(UUID playerId, final String message, final List pile1, final List pile2) throws MageException { - perform(playerId, playerId1 -> getGameSession(playerId1).choosePile(message, new CardsView(pile1), new CardsView(pile2))); + perform(playerId, playerId1 -> getGameSession(playerId1).choosePile(message, new CardsView(game, pile1), new CardsView(game, pile2))); } private synchronized void chooseMode(UUID playerId, final Map modes, final String message) throws MageException {