diff --git a/Mage.Client/src/main/java/mage/client/cards/Cards.java b/Mage.Client/src/main/java/mage/client/cards/Cards.java index db24e324e32..0db601295f3 100644 --- a/Mage.Client/src/main/java/mage/client/cards/Cards.java +++ b/Mage.Client/src/main/java/mage/client/cards/Cards.java @@ -41,7 +41,6 @@ import java.util.Map; import java.util.UUID; import java.util.Map.Entry; -import mage.cards.CardDimensions; import mage.cards.MageCard; import mage.client.plugins.impl.Plugins; import mage.client.util.Config; @@ -50,9 +49,11 @@ import mage.view.CardsView; import mage.view.PermanentView; import mage.view.StackAbilityView; -import javax.swing.*; import javax.swing.border.Border; -import javax.swing.border.EmptyBorder; +import mage.client.util.CardsViewUtil; +import mage.sets.Sets; +import mage.view.SimpleCardView; +import mage.view.SimpleCardsView; /** * @@ -113,6 +114,10 @@ public class Cards extends javax.swing.JPanel { } } + public boolean loadCards(SimpleCardsView cardsView, BigCard bigCard, UUID gameId) { + return loadCards(CardsViewUtil.convertSimple(cardsView), bigCard, gameId); + } + public boolean loadCards(CardsView cardsView, BigCard bigCard, UUID gameId) { boolean changed = false; diff --git a/Mage.Client/src/main/java/mage/client/dialog/ShowCardsDialog.java b/Mage.Client/src/main/java/mage/client/dialog/ShowCardsDialog.java index de59bb1c6d6..1424c891cb7 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/ShowCardsDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/ShowCardsDialog.java @@ -51,6 +51,8 @@ import java.awt.*; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.util.UUID; +import mage.client.util.CardsViewUtil; +import mage.view.SimpleCardsView; /** * @author BetaSteward_at_googlemail.com @@ -67,7 +69,11 @@ public class ShowCardsDialog extends MageDialog implements MouseListener { this.setModal(false); } - public void loadCards(String name, CardsView showCards, BigCard bigCard, CardDimensions dimension, UUID gameId, boolean modal) { + public void loadCards(String name, SimpleCardsView showCards, BigCard bigCard, CardDimensions dimension, UUID gameId, boolean modal) { + loadCards(name, CardsViewUtil.convertSimple(showCards), bigCard, dimension, gameId, modal); + } + + public void loadCards(String name, CardsView showCards, BigCard bigCard, CardDimensions dimension, UUID gameId, boolean modal) { this.reloaded = true; this.title = name; cardArea.removeAll(); diff --git a/Mage.Client/src/main/java/mage/client/draft/DraftPanel.java b/Mage.Client/src/main/java/mage/client/draft/DraftPanel.java index 9fcea08721d..8d5596cdcd4 100644 --- a/Mage.Client/src/main/java/mage/client/draft/DraftPanel.java +++ b/Mage.Client/src/main/java/mage/client/draft/DraftPanel.java @@ -42,6 +42,7 @@ import javax.swing.Timer; import mage.client.MageFrame; import mage.client.constants.Constants.SortBy; import mage.client.plugins.impl.Plugins; +import mage.client.util.CardsViewUtil; import mage.remote.Session; import mage.client.util.Event; import mage.client.util.Listener; @@ -101,8 +102,8 @@ public class DraftPanel extends javax.swing.JPanel { } public void loadBooster(DraftPickView draftPickView) { - draftBooster.loadBooster(draftPickView.getBooster(), bigCard); - draftPicks.loadCards(draftPickView.getPicks(), bigCard, null); + draftBooster.loadBooster(CardsViewUtil.convertSimple(draftPickView.getBooster()), bigCard); + draftPicks.loadCards(CardsViewUtil.convertSimple(draftPickView.getPicks()), bigCard, null); this.draftBooster.clearCardEventListeners(); this.draftBooster.addCardEventListener( new Listener () { @@ -113,7 +114,7 @@ public class DraftPanel extends javax.swing.JPanel { if (view != null) { //draftBooster.loadBooster(view.getBooster(), bigCard); draftBooster.loadBooster(emptyView, bigCard); - draftPicks.loadCards(view.getPicks(), bigCard, null); + draftPicks.loadCards(CardsViewUtil.convertSimple(view.getPicks()), bigCard, null); Plugins.getInstance().getActionCallback().hidePopup(); setMessage("Waiting for other players"); } diff --git a/Mage.Client/src/main/java/mage/client/game/GamePanel.java b/Mage.Client/src/main/java/mage/client/game/GamePanel.java index d2631191369..3dd6395ac82 100644 --- a/Mage.Client/src/main/java/mage/client/game/GamePanel.java +++ b/Mage.Client/src/main/java/mage/client/game/GamePanel.java @@ -307,7 +307,7 @@ public class GamePanel extends javax.swing.JPanel { // Get opponents hand cards if available if (game.getOpponentHands() != null) { - for (Map.Entry hand: game.getOpponentHands().entrySet()) { + for (Map.Entry hand: game.getOpponentHands().entrySet()) { handCards.put(hand.getKey(), hand.getValue()); } } @@ -577,7 +577,7 @@ public class GamePanel extends javax.swing.JPanel { jTabbedPane1 = new JTabbedPane(); hand.setCardDimension(getHandCardDimension()); - handCards = new HashMap(); + handCards = new HashMap(); jSplitPane1.setBorder(null); jSplitPane1.setDividerSize(7); @@ -882,7 +882,7 @@ public class GamePanel extends javax.swing.JPanel { if (chosenHandKey != null && chosenHandKey.length() > 0) { this.chosenHandKey = chosenHandKey; - CardsView cards = handCards.get(chosenHandKey); + SimpleCardsView cards = handCards.get(chosenHandKey); this.hand.loadCards(cards, bigCard, gameId); hand.setPreferredSize(new java.awt.Dimension((getHandCardDimension().width + 5) * cards.size() + 5, getHandCardDimension().height + 20)); // for scroll } @@ -983,8 +983,6 @@ public class GamePanel extends javax.swing.JPanel { private mage.client.chat.ChatPanel gameChatPanel; private mage.client.game.FeedbackPanel feedbackPanel; private mage.client.chat.ChatPanel userChatPanel; - private mage.client.cards.Cards hand; - private Map handCards; private javax.swing.JPanel jPanel3; private javax.swing.JSplitPane jSplitPane1; private javax.swing.JLabel lblActivePlayer; @@ -995,7 +993,6 @@ public class GamePanel extends javax.swing.JPanel { private javax.swing.JPanel pnlBattlefield; private javax.swing.JPanel pnlGameInfo; private javax.swing.JPanel pnlReplay; - private mage.client.cards.Cards stack; private javax.swing.JLabel txtActivePlayer; private javax.swing.JLabel txtPhase; private javax.swing.JLabel txtPriority; @@ -1003,6 +1000,10 @@ public class GamePanel extends javax.swing.JPanel { private javax.swing.JLabel txtTurn; // End of variables declaration//GEN-END:variables + private mage.client.cards.Cards hand; + private Map handCards; + private mage.client.cards.Cards stack; + private JTabbedPane jTabbedPane1; private Border emptyBorder = new EmptyBorder(0,0,0,0); private Color prevBGColor; diff --git a/Mage.Client/src/main/java/mage/client/util/CardsViewUtil.java b/Mage.Client/src/main/java/mage/client/util/CardsViewUtil.java new file mode 100644 index 00000000000..1cd315f0999 --- /dev/null +++ b/Mage.Client/src/main/java/mage/client/util/CardsViewUtil.java @@ -0,0 +1,57 @@ +/* +* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without modification, are +* permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright notice, this list of +* conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright notice, this list +* of conditions and the following disclaimer in the documentation and/or other materials +* provided with the distribution. +* +* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED +* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR +* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +* The views and conclusions contained in the software and documentation are those of the +* authors and should not be interpreted as representing official policies, either expressed +* or implied, of BetaSteward_at_googlemail.com. +*/ + +package mage.client.util; + +import mage.sets.Sets; +import mage.view.CardView; +import mage.view.CardsView; +import mage.view.SimpleCardView; +import mage.view.SimpleCardsView; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class CardsViewUtil { + + public static CardsView convertSimple(SimpleCardsView view) { + CardsView cards = new CardsView(); + + for (SimpleCardView simple: view.values()) { + mage.cards.Card card = Sets.findCard(simple.getExpansionSetCode(), simple.getCardNumber()); + if (card != null) { + + cards.put(simple.getId(), new CardView(card, simple.getId())); + } + } + + return cards; + } + +} diff --git a/Mage.Client/src/main/java/mage/client/util/DeckUtil.java b/Mage.Client/src/main/java/mage/client/util/DeckUtil.java index bea93dee76f..9cf8a629865 100644 --- a/Mage.Client/src/main/java/mage/client/util/DeckUtil.java +++ b/Mage.Client/src/main/java/mage/client/util/DeckUtil.java @@ -34,6 +34,7 @@ import mage.cards.decks.Deck; import mage.sets.Sets; import mage.view.CardView; import mage.view.DeckView; +import mage.view.SimpleCardView; import org.apache.log4j.Logger; /** @@ -50,25 +51,25 @@ public class DeckUtil { public static Deck construct(DeckView view) { Deck deck = new Deck(); - for (CardView cardView : view.getCards().values()) { + for (SimpleCardView cardView : view.getCards().values()) { ExpansionSet set = Sets.findSet(cardView.getExpansionSetCode()); if (set != null) { - Card card = set.findCard(cardView.getName(), cardView.getCardNumber()); + Card card = set.findCard(cardView.getCardNumber()); if (card != null) { deck.getCards().add(card); } else { - log.fatal("(Deck constructing) Couldn't find card: " + cardView.getName() + ", set=" + cardView.getExpansionSetCode() + ", cid=" + Integer.valueOf(cardView.getCardNumber())); + log.fatal("(Deck constructing) Couldn't find card: set=" + cardView.getExpansionSetCode() + ", cid=" + Integer.valueOf(cardView.getCardNumber())); } } } - for (CardView cardView : view.getSideboard().values()) { + for (SimpleCardView cardView : view.getSideboard().values()) { ExpansionSet set = Sets.findSet(cardView.getExpansionSetCode()); if (set != null) { - Card card = set.findCard(cardView.getName(), cardView.getCardNumber()); + Card card = set.findCard(cardView.getCardNumber()); if (card != null) { deck.getSideboard().add(card); } else { - log.fatal("(Deck constructing) Couldn't find card: " + cardView.getName() + ", set=" + cardView.getExpansionSetCode() + ", cid=" + Integer.valueOf(cardView.getCardNumber())); + log.fatal("(Deck constructing) Couldn't find card: set=" + cardView.getExpansionSetCode() + ", cid=" + Integer.valueOf(cardView.getCardNumber())); } } } diff --git a/Mage.Common/src/mage/view/CardView.java b/Mage.Common/src/mage/view/CardView.java index 12548a431a5..041b798c968 100644 --- a/Mage.Common/src/mage/view/CardView.java +++ b/Mage.Common/src/mage/view/CardView.java @@ -49,10 +49,9 @@ import mage.target.Targets; /** * @author BetaSteward_at_googlemail.com */ -public class CardView implements Serializable { +public class CardView extends SimpleCardView { private static final long serialVersionUID = 1L; - protected UUID id; protected UUID parentId; protected String name; protected List rules; @@ -66,17 +65,18 @@ public class CardView implements Serializable { protected List manaCost; protected int convertedManaCost; protected Rarity rarity; - protected String expansionSetCode; - protected int cardNumber; protected boolean isAbility; protected CardView ability; - protected boolean faceDown; public List targets; + public CardView(Card card, UUID cardId) { + this(card); + this.id = cardId; + } + public CardView(Card card) { - this.id = card.getId(); - this.faceDown = card.isFaceDown(); + super(card.getId(), card.getExpansionSetCode(), card.getCardNumber(), card.isFaceDown()); // no information available for face down cards if (this.faceDown) { @@ -106,8 +106,6 @@ public class CardView implements Serializable { } else { this.rarity = card.getRarity(); } - this.expansionSetCode = card.getExpansionSetCode(); - this.cardNumber = card.getCardNumber(); if (card instanceof Spell) { Spell spell = (Spell) card; @@ -118,7 +116,7 @@ public class CardView implements Serializable { } public CardView(MageObject card) { - this.id = card.getId(); + super(card.getId(), "", 0, false); this.name = card.getName(); if (card instanceof Permanent) { @@ -144,9 +142,10 @@ public class CardView implements Serializable { } protected CardView() { + super(null, "", 0, false); } - private void fillEmpty() { + private void fillEmpty() { this.name = "Face Down"; this.rules = new ArrayList(); this.power = ""; @@ -164,6 +163,7 @@ public class CardView implements Serializable { } CardView(Token token) { + super(token.getId(), "", 0, false); this.id = token.getId(); this.name = token.getName(); this.rules = token.getAbilities().getRules(this.name); diff --git a/Mage.Common/src/mage/view/CardsView.java b/Mage.Common/src/mage/view/CardsView.java index 56b02a011e0..8cc127eb7ef 100644 --- a/Mage.Common/src/mage/view/CardsView.java +++ b/Mage.Common/src/mage/view/CardsView.java @@ -36,7 +36,6 @@ import mage.abilities.Ability; import mage.cards.Card; import mage.game.Game; import mage.game.GameState; -import mage.game.permanent.Permanent; /** * diff --git a/Mage.Common/src/mage/view/DeckView.java b/Mage.Common/src/mage/view/DeckView.java index 5dff03d9034..6e4e140fdf5 100644 --- a/Mage.Common/src/mage/view/DeckView.java +++ b/Mage.Common/src/mage/view/DeckView.java @@ -27,13 +27,9 @@ */ package mage.view; -import mage.cards.Card; -import mage.cards.Cards; import mage.cards.decks.Deck; import java.io.Serializable; -import java.util.LinkedHashSet; -import java.util.Set; /** * @author nantuko @@ -41,24 +37,24 @@ import java.util.Set; public class DeckView implements Serializable { private String name; - private CardsView cards; - private CardsView sideboard; + private SimpleCardsView cards; + private SimpleCardsView sideboard; public DeckView(Deck deck) { name = deck.getName(); - cards = new CardsView(deck.getCards()); - sideboard = new CardsView(deck.getSideboard()); + cards = new SimpleCardsView(deck.getCards()); + sideboard = new SimpleCardsView(deck.getSideboard()); } public String getName() { return name; } - public CardsView getCards() { + public SimpleCardsView getCards() { return cards; } - public CardsView getSideboard() { + public SimpleCardsView getSideboard() { return sideboard; } } diff --git a/Mage.Common/src/mage/view/DraftPickView.java b/Mage.Common/src/mage/view/DraftPickView.java index ddb7b0dc2e2..990b1125fe3 100644 --- a/Mage.Common/src/mage/view/DraftPickView.java +++ b/Mage.Common/src/mage/view/DraftPickView.java @@ -38,23 +38,23 @@ import mage.game.draft.DraftPlayer; public class DraftPickView implements Serializable { private static final long serialVersionUID = 1L; - protected CardsView booster; - protected CardsView picks; + protected SimpleCardsView booster; + protected SimpleCardsView picks; protected boolean picking; protected int timeout; public DraftPickView(DraftPlayer player, int timeout) { - this.booster = new CardsView(player.getBooster()); - this.picks = new CardsView(player.getDeck().getSideboard()); + this.booster = new SimpleCardsView(player.getBooster()); + this.picks = new SimpleCardsView(player.getDeck().getSideboard()); this.picking = player.isPicking(); this.timeout = timeout; } - public CardsView getBooster() { + public SimpleCardsView getBooster() { return booster; } - public CardsView getPicks() { + public SimpleCardsView getPicks() { return picks; } diff --git a/Mage.Common/src/mage/view/ExileView.java b/Mage.Common/src/mage/view/ExileView.java index 99ec6080464..cda9ca9a398 100644 --- a/Mage.Common/src/mage/view/ExileView.java +++ b/Mage.Common/src/mage/view/ExileView.java @@ -37,7 +37,7 @@ import mage.game.Game; * * @author BetaSteward_at_googlemail.com */ -public class ExileView extends CardsView { +public class ExileView extends SimpleCardsView { private static final long serialVersionUID = 1L; private String name; @@ -47,7 +47,7 @@ public class ExileView extends CardsView { this.name = exileZone.getName(); this.id = exileZone.getId(); for (Card card: exileZone.getCards(game)) { - this.put(card.getId(), new CardView(card)); + this.put(card.getId(), new SimpleCardView(card.getId(), card.getExpansionSetCode(), card.getCardNumber(), card.isFaceDown())); } } diff --git a/Mage.Common/src/mage/view/GameView.java b/Mage.Common/src/mage/view/GameView.java index 59c9d12ec99..c9fdb6ad5a1 100644 --- a/Mage.Common/src/mage/view/GameView.java +++ b/Mage.Common/src/mage/view/GameView.java @@ -32,13 +32,11 @@ import java.io.Serializable; import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.UUID; import mage.MageObject; import mage.Constants.PhaseStep; import mage.Constants.TurnPhase; import mage.cards.Card; -import mage.cards.Cards; import mage.game.ExileZone; import mage.game.Game; import mage.game.GameState; @@ -56,8 +54,8 @@ public class GameView implements Serializable { private static final long serialVersionUID = 1L; private List players = new ArrayList(); - private CardsView hand; - private Map opponentHands; + private SimpleCardsView hand; + private Map opponentHands; private CardsView stack = new CardsView(); private List exiles = new ArrayList(); private List revealed = new ArrayList(); @@ -118,19 +116,19 @@ public class GameView implements Serializable { return players; } - public CardsView getHand() { + public SimpleCardsView getHand() { return hand; } - public void setHand(CardsView hand) { + public void setHand(SimpleCardsView hand) { this.hand = hand; } - public Map getOpponentHands() { + public Map getOpponentHands() { return opponentHands; } - public void setOpponentHands(Map opponentHands) { + public void setOpponentHands(Map opponentHands) { this.opponentHands = opponentHands; } diff --git a/Mage.Common/src/mage/view/LookedAtView.java b/Mage.Common/src/mage/view/LookedAtView.java index 16853915d0f..2cf210e9442 100644 --- a/Mage.Common/src/mage/view/LookedAtView.java +++ b/Mage.Common/src/mage/view/LookedAtView.java @@ -41,12 +41,12 @@ import java.io.Serializable; public class LookedAtView implements Serializable { private String name; - private CardsView cards = new CardsView(); + private SimpleCardsView cards = new SimpleCardsView(); public LookedAtView(String name, Cards cards, Game game) { this.name = name; for (Card card: cards.getCards(game)) { - this.cards.put(card.getId(), new CardView(card)); + this.cards.put(card.getId(), new SimpleCardView(card.getId(), card.getExpansionSetCode(), card.getCardNumber(), card.isFaceDown())); } } @@ -54,7 +54,7 @@ public class LookedAtView implements Serializable { return name; } - public CardsView getCards() { + public SimpleCardsView getCards() { return cards; } } diff --git a/Mage.Common/src/mage/view/PlayerView.java b/Mage.Common/src/mage/view/PlayerView.java index 3eb7c0945b6..99bd3729156 100644 --- a/Mage.Common/src/mage/view/PlayerView.java +++ b/Mage.Common/src/mage/view/PlayerView.java @@ -55,7 +55,7 @@ public class PlayerView implements Serializable { private boolean isActive; private boolean hasLeft; private ManaPoolView manaPool; - private CardsView graveyard = new CardsView(); + private SimpleCardsView graveyard = new SimpleCardsView(); private Map battlefield = new HashMap(); public PlayerView(Player player, GameState state, Game game) { @@ -69,7 +69,7 @@ public class PlayerView implements Serializable { this.isActive = (player.getId().equals(state.getActivePlayerId())); this.hasLeft = player.hasLeft(); for (Card card: player.getGraveyard().getCards(game)) { - graveyard.put(card.getId(), new CardView(card)); + graveyard.put(card.getId(), new SimpleCardView(card.getId(), card.getExpansionSetCode(), card.getCardNumber(), card.isFaceDown())); } for (Permanent permanent: state.getBattlefield().getAllPermanents()) { if (showInBattlefield(permanent, state)) { @@ -113,7 +113,7 @@ public class PlayerView implements Serializable { return this.manaPool; } - public CardsView getGraveyard() { + public SimpleCardsView getGraveyard() { return this.graveyard; } diff --git a/Mage.Common/src/mage/view/RevealedView.java b/Mage.Common/src/mage/view/RevealedView.java index 15670c94c0f..27144da221a 100644 --- a/Mage.Common/src/mage/view/RevealedView.java +++ b/Mage.Common/src/mage/view/RevealedView.java @@ -40,12 +40,12 @@ import mage.game.Game; public class RevealedView implements Serializable { private String name; - private CardsView cards = new CardsView(); + private SimpleCardsView cards = new SimpleCardsView(); public RevealedView(String name, Cards cards, Game game) { this.name = name; for (Card card: cards.getCards(game)) { - this.cards.put(card.getId(), new CardView(card)); + this.cards.put(card.getId(), new SimpleCardView(card.getId(), card.getExpansionSetCode(), card.getCardNumber(), card.isFaceDown())); } } @@ -53,7 +53,7 @@ public class RevealedView implements Serializable { return name; } - public CardsView getCards() { + public SimpleCardsView getCards() { return cards; } } diff --git a/Mage.Common/src/mage/view/SimpleCardView.java b/Mage.Common/src/mage/view/SimpleCardView.java new file mode 100644 index 00000000000..f9a999818f6 --- /dev/null +++ b/Mage.Common/src/mage/view/SimpleCardView.java @@ -0,0 +1,66 @@ +/* +* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without modification, are +* permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright notice, this list of +* conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright notice, this list +* of conditions and the following disclaimer in the documentation and/or other materials +* provided with the distribution. +* +* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED +* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR +* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +* The views and conclusions contained in the software and documentation are those of the +* authors and should not be interpreted as representing official policies, either expressed +* or implied, of BetaSteward_at_googlemail.com. +*/ + +package mage.view; + +import java.io.Serializable; +import java.util.UUID; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class SimpleCardView implements Serializable { + protected UUID id; + protected String expansionSetCode; + protected int cardNumber; + protected boolean faceDown; + + public SimpleCardView(UUID id, String expansionSetCode, int cardNumber, boolean faceDown) { + this.id = id; + this.expansionSetCode = expansionSetCode; + this.cardNumber = cardNumber; + this.faceDown = faceDown; + } + + public UUID getId() { + return id; + } + + public String getExpansionSetCode() { + return expansionSetCode; + } + + public int getCardNumber() { + return cardNumber; + } + + public boolean isFaceDown() { + return faceDown; + } +} diff --git a/Mage.Common/src/mage/view/SimpleCardsView.java b/Mage.Common/src/mage/view/SimpleCardsView.java new file mode 100644 index 00000000000..0befd9cd7cd --- /dev/null +++ b/Mage.Common/src/mage/view/SimpleCardsView.java @@ -0,0 +1,50 @@ +/* +* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without modification, are +* permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright notice, this list of +* conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright notice, this list +* of conditions and the following disclaimer in the documentation and/or other materials +* provided with the distribution. +* +* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED +* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR +* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +* The views and conclusions contained in the software and documentation are those of the +* authors and should not be interpreted as representing official policies, either expressed +* or implied, of BetaSteward_at_googlemail.com. +*/ + +package mage.view; + +import java.util.Collection; +import java.util.HashMap; +import java.util.UUID; +import mage.cards.Card; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class SimpleCardsView extends HashMap { + + public SimpleCardsView() {} + + public SimpleCardsView(Collection cards) { + for (Card card: cards) { + this.put(card.getId(), new SimpleCardView(card.getId(), card.getExpansionSetCode(), card.getCardNumber(), card.isFaceDown())); + } + } + +} diff --git a/Mage.Server/src/main/java/mage/server/game/GameSession.java b/Mage.Server/src/main/java/mage/server/game/GameSession.java index 1076bf3cfa3..9e06b668b7d 100644 --- a/Mage.Server/src/main/java/mage/server/game/GameSession.java +++ b/Mage.Server/src/main/java/mage/server/game/GameSession.java @@ -47,6 +47,7 @@ import mage.view.CardsView; import mage.view.GameClientMessage; import mage.view.GameView; import mage.view.LookedAtView; +import mage.view.SimpleCardsView; /** * @@ -196,13 +197,13 @@ public class GameSession extends GameWatcher { public GameView getGameView() { Player player = game.getPlayer(playerId); GameView gameView = new GameView(game.getState(), game); - gameView.setHand(new CardsView(player.getHand().getCards(game))); + gameView.setHand(new SimpleCardsView(player.getHand().getCards(game))); if (player.getPlayersUnderYourControl().size() > 0) { - Map handCards = new HashMap(); + Map handCards = new HashMap(); for (UUID playerId : player.getPlayersUnderYourControl()) { Player opponent = game.getPlayer(playerId); - handCards.put(opponent.getName(), new CardsView(opponent.getHand().getCards(game))); + handCards.put(opponent.getName(), new SimpleCardsView(opponent.getHand().getCards(game))); } gameView.setOpponentHands(handCards); } diff --git a/Mage.Sets/src/mage/sets/Sets.java b/Mage.Sets/src/mage/sets/Sets.java index e2458189987..17d0b62e91b 100644 --- a/Mage.Sets/src/mage/sets/Sets.java +++ b/Mage.Sets/src/mage/sets/Sets.java @@ -57,6 +57,7 @@ public class Sets extends HashMap { private static Set nonLandNames; private static Set creatureTypes; private static List cards; + private static Map cardMap; protected static Random rnd = new Random(); public static Sets getInstance() { @@ -67,6 +68,7 @@ public class Sets extends HashMap { names = new TreeSet(); nonLandNames = new TreeSet(); cards = new ArrayList(); + cardMap = new HashMap(); creatureTypes = new TreeSet(); this.addSet(AlaraReborn.getInstance()); this.addSet(Apocalypse.getInstance()); @@ -243,6 +245,23 @@ public class Sets extends HashMap { } return null; } + + public static Card findCard(String expansionsetCode, int cardNum) { + if (cardMap.containsKey(expansionsetCode + Integer.toString(cardNum))) { + return cardMap.get(expansionsetCode + Integer.toString(cardNum)); + } + if (fINSTANCE.containsKey(expansionsetCode)) { + ExpansionSet set = fINSTANCE.get(expansionsetCode); + Card card = set.findCard(cardNum); + if (card != null) { + cardMap.put(expansionsetCode + Integer.toString(cardNum), card); + return card; + } + } + logger.warn("Could not find card: set=" + expansionsetCode + "cardNum=" + Integer.toString(cardNum)); + return null; + + } public static Card createCard(Class clazz) { try { @@ -280,7 +299,7 @@ public class Sets extends HashMap { String setCode = m.group(3); int cardNum = Integer.parseInt(m.group(4)); ExpansionSet set = Sets.findSet(setCode); - String card = set.findCard(cardNum); + String card = set.findCardName(cardNum); for (int i = 0; i < count; i++) { if (!sideboard) { deckList.getCards().add(card); diff --git a/Mage/src/mage/cards/ExpansionSet.java b/Mage/src/mage/cards/ExpansionSet.java index 3f9ccf68284..c7fe8b0d869 100644 --- a/Mage/src/mage/cards/ExpansionSet.java +++ b/Mage/src/mage/cards/ExpansionSet.java @@ -41,7 +41,6 @@ import java.net.URL; import java.net.URLClassLoader; import java.net.URLDecoder; import java.util.*; -import java.util.concurrent.ThreadPoolExecutor; import java.util.jar.JarEntry; import java.util.jar.JarInputStream; import org.apache.log4j.Logger; @@ -132,9 +131,9 @@ public abstract class ExpansionSet implements Serializable { return null; } - public Card findCard(String name, int cardNum) { + public Card findCard(int cardNum) { for (Card card : cards) { - if (cardNum == card.getCardNumber() && name.equalsIgnoreCase(card.getName())) { + if (cardNum == card.getCardNumber()) { Card newCard = card.copy(); newCard.assignNewId(); return newCard; @@ -158,7 +157,7 @@ public abstract class ExpansionSet implements Serializable { return null; } - public String findCard(int cardNum) { + public String findCardName(int cardNum) { for (Card card : cards) { if (card.getCardNumber() == cardNum) return card.getClass().getCanonicalName();