From 37819c508847db7f0686bffdb63d909ea76b7b24 Mon Sep 17 00:00:00 2001 From: BetaSteward Date: Mon, 22 Aug 2011 13:39:44 -0400 Subject: [PATCH 1/3] fix for issue 210 was causing issues for AI's - added getX() utility method instead --- .../src/mage/sets/conflux/MartialCoup.java | 6 +----- .../mage/sets/magic2010/ConsumeSpirit.java | 2 +- .../src/mage/sets/magic2010/Earthquake.java | 3 +-- .../src/mage/sets/magic2010/Fireball.java | 2 +- .../src/mage/sets/magic2010/MindSpring.java | 2 +- .../src/mage/sets/magic2010/ProteanHydra.java | 4 ++-- .../mage/sets/magic2011/VengefulArchon.java | 3 +-- .../mage/sets/magic2012/PrimordialHydra.java | 5 +---- .../mirrodinbesieged/BlackSunsZenith.java | 2 +- .../mirrodinbesieged/GreenSunsZenith.java | 2 +- .../sets/scarsofmirrodin/ChimericMass.java | 2 +- .../sets/scarsofmirrodin/Exsanguinate.java | 2 +- .../sets/scarsofmirrodin/GenesisWave.java | 2 +- .../sets/scarsofmirrodin/MyrBattlesphere.java | 2 +- .../sets/scarsofmirrodin/SteelHellkite.java | 2 +- .../sets/shardsofalara/FlameblastDragon.java | 2 +- .../shardsofalara/SigilOfDistinction.java | 2 +- .../mage/abilities/costs/mana/ManaCosts.java | 4 ++++ .../abilities/costs/mana/ManaCostsImpl.java | 19 ++++++++++++++---- .../common/ManacostVariableValue.java | 2 +- .../effects/common/DamageXTargetEffect.java | 2 +- .../BoostPowerToughnessXTargetEffect.java | 8 ++++---- .../continious/BoostPowerXSourceEffect.java | 20 +++++++++---------- 23 files changed, 52 insertions(+), 48 deletions(-) diff --git a/Mage.Sets/src/mage/sets/conflux/MartialCoup.java b/Mage.Sets/src/mage/sets/conflux/MartialCoup.java index 88516265eb4..540bb96df01 100644 --- a/Mage.Sets/src/mage/sets/conflux/MartialCoup.java +++ b/Mage.Sets/src/mage/sets/conflux/MartialCoup.java @@ -84,11 +84,7 @@ class MartialCoupEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - int amount = 0; - if (source.getManaCostsToPay().getVariableCosts().size() > 0) { - amount = source.getManaCostsToPay().getVariableCosts().get(0).getAmount(); - } - + int amount = source.getManaCostsToPay().getX(); if (amount > 4) { for (Permanent permanent: game.getBattlefield().getActivePermanents(FilterCreaturePermanent.getDefault(), source.getControllerId(), game)) { permanent.destroy(source.getSourceId(), game, false); diff --git a/Mage.Sets/src/mage/sets/magic2010/ConsumeSpirit.java b/Mage.Sets/src/mage/sets/magic2010/ConsumeSpirit.java index ba9ab6d221c..be55c050ee0 100644 --- a/Mage.Sets/src/mage/sets/magic2010/ConsumeSpirit.java +++ b/Mage.Sets/src/mage/sets/magic2010/ConsumeSpirit.java @@ -88,7 +88,7 @@ class ConsumeSpiritEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - int damage = source.getManaCostsToPay().getVariableCosts().get(0).getAmount(); + int damage = source.getManaCostsToPay().getX(); if (damage > 0) { Permanent permanent = game.getPermanent(getTargetPointer().getFirst(source)); if (permanent != null) { diff --git a/Mage.Sets/src/mage/sets/magic2010/Earthquake.java b/Mage.Sets/src/mage/sets/magic2010/Earthquake.java index 2cf19670e63..9e826d489b5 100644 --- a/Mage.Sets/src/mage/sets/magic2010/Earthquake.java +++ b/Mage.Sets/src/mage/sets/magic2010/Earthquake.java @@ -89,8 +89,7 @@ class EarthquakeEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - int amount = source.getManaCostsToPay().getVariableCosts().get(0).getAmount(); - + int amount = source.getManaCostsToPay().getX(); for (Permanent permanent: game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game)) { permanent.damage(amount, source.getId(), game, true, false); } diff --git a/Mage.Sets/src/mage/sets/magic2010/Fireball.java b/Mage.Sets/src/mage/sets/magic2010/Fireball.java index a864abb2d66..463031b058a 100644 --- a/Mage.Sets/src/mage/sets/magic2010/Fireball.java +++ b/Mage.Sets/src/mage/sets/magic2010/Fireball.java @@ -87,7 +87,7 @@ class FireballEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { int numTargets = source.getTargets().get(0).getTargets().size(); - int damage = source.getManaCostsToPay().getVariableCosts().get(0).getAmount(); + int damage = source.getManaCostsToPay().getX(); if (numTargets > 0) { int damagePer = damage/numTargets; if (damagePer > 0) { diff --git a/Mage.Sets/src/mage/sets/magic2010/MindSpring.java b/Mage.Sets/src/mage/sets/magic2010/MindSpring.java index 69e1bbb433c..eabb45db1e8 100644 --- a/Mage.Sets/src/mage/sets/magic2010/MindSpring.java +++ b/Mage.Sets/src/mage/sets/magic2010/MindSpring.java @@ -80,7 +80,7 @@ class MindSpringEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - int amount = source.getManaCostsToPay().getVariableCosts().get(0).getAmount(); + int amount = source.getManaCostsToPay().getX(); Player player = game.getPlayer(source.getControllerId()); if (player != null) { player.drawCards(amount, game); diff --git a/Mage.Sets/src/mage/sets/magic2010/ProteanHydra.java b/Mage.Sets/src/mage/sets/magic2010/ProteanHydra.java index 4f7b98ef448..c92165bb441 100644 --- a/Mage.Sets/src/mage/sets/magic2010/ProteanHydra.java +++ b/Mage.Sets/src/mage/sets/magic2010/ProteanHydra.java @@ -93,8 +93,8 @@ public class ProteanHydra extends CardImpl { @Override public boolean apply(Game game, Ability source) { Permanent permanent = game.getPermanent(source.getSourceId()); - if (permanent != null && source.getManaCostsToPay().getVariableCosts().size() > 0) { - int amount = source.getManaCostsToPay().getVariableCosts().get(0).getAmount(); + int amount = source.getManaCostsToPay().getX(); + if (permanent != null && amount > 0) { permanent.addCounters(CounterType.P1P1.createInstance(amount), game); } return true; diff --git a/Mage.Sets/src/mage/sets/magic2011/VengefulArchon.java b/Mage.Sets/src/mage/sets/magic2011/VengefulArchon.java index feb0400d418..9a17e626739 100644 --- a/Mage.Sets/src/mage/sets/magic2011/VengefulArchon.java +++ b/Mage.Sets/src/mage/sets/magic2011/VengefulArchon.java @@ -98,8 +98,7 @@ class VengefulArchonEffect extends PreventionEffectImpl { @Override public void init(Ability source, Game game) { super.init(source, game); - if (source.getManaCostsToPay().getVariableCosts().size() > 0) - amount = source.getManaCostsToPay().getVariableCosts().get(0).getAmount(); + amount = source.getManaCostsToPay().getX(); } @Override diff --git a/Mage.Sets/src/mage/sets/magic2012/PrimordialHydra.java b/Mage.Sets/src/mage/sets/magic2012/PrimordialHydra.java index 6045b8e1c5c..6cae91ad1cf 100644 --- a/Mage.Sets/src/mage/sets/magic2012/PrimordialHydra.java +++ b/Mage.Sets/src/mage/sets/magic2012/PrimordialHydra.java @@ -38,11 +38,8 @@ import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.BeginningOfUpkeepTriggeredAbility; import mage.abilities.common.EntersBattlefieldAbility; -import mage.abilities.common.SimpleStaticAbility; import mage.abilities.condition.common.HasCounterCondition; -import mage.abilities.decorator.ConditionalContinousEffect; import mage.abilities.decorator.ConditionalStaticAbility; -import mage.abilities.dynamicvalue.common.CountersCount; import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.continious.GainAbilitySourceEffect; import mage.abilities.keyword.TrampleAbility; @@ -96,7 +93,7 @@ class PrimordialHydraEntersEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - int amount = source.getManaCostsToPay().getVariableCosts().get(0).getAmount(); + int amount = source.getManaCostsToPay().getX(); for (Permanent permanent : game.getBattlefield().getAllActivePermanents()) { if (permanent != null && permanent.getCardType().contains(CardType.CREATURE)) { permanent.addCounters(CounterType.M1M1.createInstance(amount), game); diff --git a/Mage.Sets/src/mage/sets/mirrodinbesieged/GreenSunsZenith.java b/Mage.Sets/src/mage/sets/mirrodinbesieged/GreenSunsZenith.java index 203997ce5af..44441565143 100644 --- a/Mage.Sets/src/mage/sets/mirrodinbesieged/GreenSunsZenith.java +++ b/Mage.Sets/src/mage/sets/mirrodinbesieged/GreenSunsZenith.java @@ -87,7 +87,7 @@ class GreenSunsZenithSearchEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - int amount = source.getManaCostsToPay().getVariableCosts().get(0).getAmount(); + int amount = source.getManaCostsToPay().getX(); Permanent p = game.getPermanent(source.getSourceId()); if (p != null) { p.addCounters(CounterType.CHARGE.createInstance(amount), game); diff --git a/Mage.Sets/src/mage/sets/scarsofmirrodin/Exsanguinate.java b/Mage.Sets/src/mage/sets/scarsofmirrodin/Exsanguinate.java index 88c697ef70a..03b59a2d296 100644 --- a/Mage.Sets/src/mage/sets/scarsofmirrodin/Exsanguinate.java +++ b/Mage.Sets/src/mage/sets/scarsofmirrodin/Exsanguinate.java @@ -77,7 +77,7 @@ class ExsanguinateEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { int loseLife = 0; - int damage = source.getManaCostsToPay().getVariableCosts().get(0).getAmount(); + int damage = source.getManaCostsToPay().getX(); for (UUID opponentId : game.getOpponents(source.getControllerId())) { loseLife += game.getPlayer(opponentId).loseLife(damage, game); } diff --git a/Mage.Sets/src/mage/sets/scarsofmirrodin/GenesisWave.java b/Mage.Sets/src/mage/sets/scarsofmirrodin/GenesisWave.java index e8ea1341823..bff5cfe76e5 100644 --- a/Mage.Sets/src/mage/sets/scarsofmirrodin/GenesisWave.java +++ b/Mage.Sets/src/mage/sets/scarsofmirrodin/GenesisWave.java @@ -83,7 +83,7 @@ class GenesisWaveEffect extends OneShotEffect { public boolean apply(Game game, Ability source) { Player player = game.getPlayer(source.getControllerId()); Cards cards = new CardsImpl(Zone.PICK); - int count = source.getManaCostsToPay().getVariableCosts().get(0).getAmount(); + int count = source.getManaCostsToPay().getX(); for (int i = 0; i < count; i++) { Card card = player.getLibrary().removeFromTop(game); cards.add(card); diff --git a/Mage.Sets/src/mage/sets/scarsofmirrodin/MyrBattlesphere.java b/Mage.Sets/src/mage/sets/scarsofmirrodin/MyrBattlesphere.java index cf0c59b5bd1..8ccd629431a 100644 --- a/Mage.Sets/src/mage/sets/scarsofmirrodin/MyrBattlesphere.java +++ b/Mage.Sets/src/mage/sets/scarsofmirrodin/MyrBattlesphere.java @@ -143,7 +143,7 @@ class MyrBattlesphereEffect extends OneShotEffect { UUID defenderId = game.getCombat().getDefendingPlayer(source.getSourceId()); Player defender = game.getPlayer(defenderId); if (defender != null) { - defender.damage(source.getManaCostsToPay().getVariableCosts().get(0).getAmount(), source.getSourceId(), game, false, false); + defender.damage(source.getManaCostsToPay().getX(), source.getSourceId(), game, false, false); return true; } return false; diff --git a/Mage.Sets/src/mage/sets/scarsofmirrodin/SteelHellkite.java b/Mage.Sets/src/mage/sets/scarsofmirrodin/SteelHellkite.java index 242efd3005c..19dd4a51abb 100644 --- a/Mage.Sets/src/mage/sets/scarsofmirrodin/SteelHellkite.java +++ b/Mage.Sets/src/mage/sets/scarsofmirrodin/SteelHellkite.java @@ -101,7 +101,7 @@ class SteelHellkiteDestroyEffect extends OneShotEffect { SteelHellkiteWatcher watcher = (SteelHellkiteWatcher) game.getState().getWatchers().get(source.getControllerId(), "SteelHellkiteWatcher"); if (watcher != null && watcher.damagedPlayers.containsKey(source.getSourceId())) { Set players = watcher.damagedPlayers.get(source.getSourceId()); - int xValue = source.getManaCostsToPay().getVariableCosts().get(0).getAmount(); + int xValue = source.getManaCostsToPay().getX(); for (UUID uuid : players) { for (Permanent permanent: game.getBattlefield().getAllActivePermanents()) { if (permanent.getControllerId().equals(uuid) && permanent.getManaCost().convertedManaCost() == xValue) { diff --git a/Mage.Sets/src/mage/sets/shardsofalara/FlameblastDragon.java b/Mage.Sets/src/mage/sets/shardsofalara/FlameblastDragon.java index c258a2ccedd..d29e32f63c7 100644 --- a/Mage.Sets/src/mage/sets/shardsofalara/FlameblastDragon.java +++ b/Mage.Sets/src/mage/sets/shardsofalara/FlameblastDragon.java @@ -93,7 +93,7 @@ class FlameblastDragonEffect extends OneShotEffect { if (player.chooseUse(Constants.Outcome.Damage, "Pay " + cost.getText() + "? If you do, Flameblast Dragon deals X damage to target creature or player", game)) { cost.clearPaid(); if (cost.pay(source, game, source.getId(), source.getControllerId(), false)) { - int costX = ((VariableCost) cost.getVariableCosts().get(0)).getAmount(); + int costX = cost.getX(); Permanent permanent = game.getPermanent(source.getFirstTarget()); if (permanent != null) { permanent.damage(costX, source.getId(), game, true, false); diff --git a/Mage.Sets/src/mage/sets/shardsofalara/SigilOfDistinction.java b/Mage.Sets/src/mage/sets/shardsofalara/SigilOfDistinction.java index a256f68adcc..708b4e99e12 100644 --- a/Mage.Sets/src/mage/sets/shardsofalara/SigilOfDistinction.java +++ b/Mage.Sets/src/mage/sets/shardsofalara/SigilOfDistinction.java @@ -84,7 +84,7 @@ class SigilOfDistinctionEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - int amount = source.getManaCostsToPay().getVariableCosts().get(0).getAmount(); + int amount = source.getManaCostsToPay().getX(); Permanent p = game.getPermanent(source.getSourceId()); if (p != null) { p.addCounters(CounterType.CHARGE.createInstance(amount), game); diff --git a/Mage/src/mage/abilities/costs/mana/ManaCosts.java b/Mage/src/mage/abilities/costs/mana/ManaCosts.java index d25190b74ed..2f36ee4eaef 100644 --- a/Mage/src/mage/abilities/costs/mana/ManaCosts.java +++ b/Mage/src/mage/abilities/costs/mana/ManaCosts.java @@ -40,8 +40,12 @@ public interface ManaCosts extends List, ManaCost { public ManaCosts getUnpaidVariableCosts(); public List getVariableCosts(); + public int getX(); public void load(String mana); public List getSymbols(); + + + @Override public Mana getMana(); @Override diff --git a/Mage/src/mage/abilities/costs/mana/ManaCostsImpl.java b/Mage/src/mage/abilities/costs/mana/ManaCostsImpl.java index 0a062658aad..a8a091d89c8 100644 --- a/Mage/src/mage/abilities/costs/mana/ManaCostsImpl.java +++ b/Mage/src/mage/abilities/costs/mana/ManaCostsImpl.java @@ -146,6 +146,8 @@ public class ManaCostsImpl extends ArrayList implements M return unpaid; } + + @Override public List getVariableCosts() { List variableCosts = new ArrayList(); @@ -153,13 +155,22 @@ public class ManaCostsImpl extends ArrayList implements M if (cost instanceof VariableCost) variableCosts.add((VariableCost) cost); } - if (variableCosts.size() == 0) { - // add empty cost (#Issue 210) - variableCosts.add(new VariableManaCost()); - } +// if (variableCosts.size() == 0) { +// // add empty cost (#Issue 210) +// variableCosts.add(new VariableManaCost()); +// } return variableCosts; } + @Override + public int getX() { + int amount = 0; + List variableCosts = getVariableCosts(); + if (!variableCosts.isEmpty()) + amount = variableCosts.get(0).getAmount(); + return amount; + } + @Override public void setPayment(Mana mana) { } diff --git a/Mage/src/mage/abilities/dynamicvalue/common/ManacostVariableValue.java b/Mage/src/mage/abilities/dynamicvalue/common/ManacostVariableValue.java index 96c728473ab..bb4fa60d143 100644 --- a/Mage/src/mage/abilities/dynamicvalue/common/ManacostVariableValue.java +++ b/Mage/src/mage/abilities/dynamicvalue/common/ManacostVariableValue.java @@ -7,7 +7,7 @@ import mage.game.Game; public class ManacostVariableValue implements DynamicValue { @Override public int calculate(Game game, Ability sourceAbility) { - return sourceAbility.getManaCostsToPay().getVariableCosts().get(0).getAmount(); + return sourceAbility.getManaCostsToPay().getX(); } @Override diff --git a/Mage/src/mage/abilities/effects/common/DamageXTargetEffect.java b/Mage/src/mage/abilities/effects/common/DamageXTargetEffect.java index 9b56fd3d4c4..73fff3effb1 100644 --- a/Mage/src/mage/abilities/effects/common/DamageXTargetEffect.java +++ b/Mage/src/mage/abilities/effects/common/DamageXTargetEffect.java @@ -57,7 +57,7 @@ public class DamageXTargetEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - int amount = source.getManaCostsToPay().getVariableCosts().get(0).getAmount(); + int amount = source.getManaCostsToPay().getX(); Permanent permanent = game.getPermanent(source.getFirstTarget()); if (permanent != null) { permanent.damage(amount, source.getId(), game, true, false); diff --git a/Mage/src/mage/abilities/effects/common/continious/BoostPowerToughnessXTargetEffect.java b/Mage/src/mage/abilities/effects/common/continious/BoostPowerToughnessXTargetEffect.java index 8af5be5f6b3..ec22a15ec24 100644 --- a/Mage/src/mage/abilities/effects/common/continious/BoostPowerToughnessXTargetEffect.java +++ b/Mage/src/mage/abilities/effects/common/continious/BoostPowerToughnessXTargetEffect.java @@ -61,14 +61,14 @@ public class BoostPowerToughnessXTargetEffect extends ContinuousEffectImpl 0) { - int amountX = source.getManaCostsToPay().getVariableCosts().get(0).getAmount(); - if (amountX == 0) { - return false; - } - Permanent target = (Permanent) game.getPermanent(source.getSourceId()); - if (target != null) { - target.addPower(amountX); - return true; - } - } + int amountX = source.getManaCostsToPay().getX(); + if (amountX == 0) { + return false; + } + Permanent target = (Permanent) game.getPermanent(source.getSourceId()); + if (target != null) { + target.addPower(amountX); + return true; + } return false; } From 91124ad813018775d505438883832d257e224e37 Mon Sep 17 00:00:00 2001 From: BetaSteward Date: Mon, 22 Aug 2011 13:44:04 -0400 Subject: [PATCH 2/3] missed a card --- Mage.Sets/src/mage/sets/scarsofmirrodin/VigilForTheLost.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Mage.Sets/src/mage/sets/scarsofmirrodin/VigilForTheLost.java b/Mage.Sets/src/mage/sets/scarsofmirrodin/VigilForTheLost.java index 224dca33c4c..bca4dfc837b 100644 --- a/Mage.Sets/src/mage/sets/scarsofmirrodin/VigilForTheLost.java +++ b/Mage.Sets/src/mage/sets/scarsofmirrodin/VigilForTheLost.java @@ -119,7 +119,7 @@ class VigilForTheLostEffect extends OneShotEffect { cost.clearPaid(); if (cost.pay(source, game, source.getId(), source.getControllerId(), false)) { Player player = game.getPlayer(source.getControllerId()); - player.gainLife(((VariableCost)cost.getVariableCosts().get(0)).getAmount(), game); + player.gainLife(cost.getX(), game); return true; } else { return false; From aecdbe0778df26c83206d7f6ad3e5ce3bbcc3f0c Mon Sep 17 00:00:00 2001 From: BetaSteward Date: Mon, 22 Aug 2011 13:54:55 -0400 Subject: [PATCH 3/3] added SimpleCardView - will reduce the amount of data passed between client and server --- .../main/java/mage/client/cards/Cards.java | 11 +++- .../mage/client/dialog/ShowCardsDialog.java | 8 ++- .../java/mage/client/draft/DraftPanel.java | 7 +- .../main/java/mage/client/game/GamePanel.java | 13 ++-- .../java/mage/client/util/CardsViewUtil.java | 57 ++++++++++++++++ .../main/java/mage/client/util/DeckUtil.java | 13 ++-- Mage.Common/src/mage/view/CardView.java | 22 +++---- Mage.Common/src/mage/view/CardsView.java | 1 - Mage.Common/src/mage/view/DeckView.java | 16 ++--- Mage.Common/src/mage/view/DraftPickView.java | 12 ++-- Mage.Common/src/mage/view/ExileView.java | 4 +- Mage.Common/src/mage/view/GameView.java | 14 ++-- Mage.Common/src/mage/view/LookedAtView.java | 6 +- Mage.Common/src/mage/view/PlayerView.java | 6 +- Mage.Common/src/mage/view/RevealedView.java | 6 +- Mage.Common/src/mage/view/SimpleCardView.java | 66 +++++++++++++++++++ .../src/mage/view/SimpleCardsView.java | 50 ++++++++++++++ .../java/mage/server/game/GameSession.java | 7 +- Mage.Sets/src/mage/sets/Sets.java | 21 +++++- Mage/src/mage/cards/ExpansionSet.java | 7 +- 20 files changed, 273 insertions(+), 74 deletions(-) create mode 100644 Mage.Client/src/main/java/mage/client/util/CardsViewUtil.java create mode 100644 Mage.Common/src/mage/view/SimpleCardView.java create mode 100644 Mage.Common/src/mage/view/SimpleCardsView.java 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();