From c3c847c5ffc5f668845cbedfe81b9e2bc3b7e8c2 Mon Sep 17 00:00:00 2001 From: Maxmtg Date: Wed, 3 Jul 2013 10:45:01 +0000 Subject: [PATCH] * Zone classes cleanup, they now have reference to game, can contain only cards, used shared code to add cards, generate GameEventZone --- .../card/cardfactory/CardFactoryUtil.java | 5 +- .../spellability/HumanPlaySpellAbility.java | 2 +- .../control/FControlGameEventHandler.java | 38 ++- src/main/java/forge/game/Game.java | 2 +- src/main/java/forge/game/GameNew.java | 4 +- .../forge/game/event/IGameEventVisitor.java | 6 +- src/main/java/forge/game/zone/IZone.java | 151 ++--------- src/main/java/forge/game/zone/PlayerZone.java | 54 +--- .../game/zone/PlayerZoneBattlefield.java | 106 +------- src/main/java/forge/game/zone/Zone.java | 238 +++++------------- src/main/java/forge/gui/match/CMatchUI.java | 16 +- 11 files changed, 132 insertions(+), 490 deletions(-) diff --git a/src/main/java/forge/card/cardfactory/CardFactoryUtil.java b/src/main/java/forge/card/cardfactory/CardFactoryUtil.java index c4a1a0de786..3b460bf98ca 100644 --- a/src/main/java/forge/card/cardfactory/CardFactoryUtil.java +++ b/src/main/java/forge/card/cardfactory/CardFactoryUtil.java @@ -699,9 +699,8 @@ public class CardFactoryUtil { return false; } - // Check if the target is in the zone it needs to be in to be - // targeted - if (!zone.is(tgt.getZone())) { + // Check if the target is in the zone it needs to be in to be targeted + if (!tgt.getZone().contains(zone.getZoneType())) { return false; } } else { diff --git a/src/main/java/forge/card/spellability/HumanPlaySpellAbility.java b/src/main/java/forge/card/spellability/HumanPlaySpellAbility.java index 9aeea79ae4d..9df7b5b2169 100644 --- a/src/main/java/forge/card/spellability/HumanPlaySpellAbility.java +++ b/src/main/java/forge/card/spellability/HumanPlaySpellAbility.java @@ -59,7 +59,7 @@ public class HumanPlaySpellAbility { final Card c = this.ability.getSourceCard(); if (this.ability instanceof Spell && !c.isCopiedSpell()) { fromZone = game.getZoneOf(c); - zonePosition = fromZone.getPosition(c); + zonePosition = fromZone.getCards().indexOf(c); this.ability.setSourceCard(game.getAction().moveToStack(c)); } diff --git a/src/main/java/forge/control/FControlGameEventHandler.java b/src/main/java/forge/control/FControlGameEventHandler.java index 378f21e9fae..90e025fa648 100644 --- a/src/main/java/forge/control/FControlGameEventHandler.java +++ b/src/main/java/forge/control/FControlGameEventHandler.java @@ -14,7 +14,6 @@ import forge.game.Game; import forge.game.event.GameEvent; import forge.game.event.GameEventAnteCardsSelected; import forge.game.event.GameEventCardAttachment; -import forge.game.event.GameEventCardChangeZone; import forge.game.event.GameEventCardCounters; import forge.game.event.GameEventCardDamaged; import forge.game.event.GameEventCardStatsChanged; @@ -31,12 +30,14 @@ import forge.game.event.GameEventSpellRemovedFromStack; import forge.game.event.GameEventSpellResolved; import forge.game.event.GameEventTurnBegan; import forge.game.event.GameEventTurnPhase; +import forge.game.event.GameEventZone; import forge.game.event.IGameEventVisitor; import forge.game.phase.PhaseHandler; import forge.game.phase.PhaseType; import forge.game.player.Player; import forge.game.zone.PlayerZone; import forge.game.zone.Zone; +import forge.game.zone.ZoneType; import forge.gui.GuiDialog; import forge.gui.SOverlayUtils; import forge.gui.match.CMatchUI; @@ -190,7 +191,7 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base { - private final List zonesToUpdate = new Vector(); + private final List> zonesToUpdate = new Vector>(); private final Runnable updZones = new Runnable() { @Override public void run() { synchronized (zonesToUpdate) { @@ -201,25 +202,13 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base { }; @Override - public Void visit(GameEventCardChangeZone event) { - updateTwoZones(event.from, event.to); + public Void visit(GameEventZone event) { + if ( event.player != null ) { + // anything except stack will get here + updateZone(Pair.of(event.player, event.zoneType)); + } return null; } - - private void updateTwoZones(Zone z1, Zone z2) { - boolean needUpdate = false; - synchronized (zonesToUpdate) { - needUpdate = zonesToUpdate.isEmpty(); - if ( z1 instanceof PlayerZone && !zonesToUpdate.contains(z1) ) { - zonesToUpdate.add((PlayerZone)z1); - } - if ( z2 instanceof PlayerZone && !zonesToUpdate.contains(z2) ) { - zonesToUpdate.add((PlayerZone)z2); - } - } - if( needUpdate ) - FThreads.invokeInEdtNowOrLater(updZones); - } @Override public Void visit(GameEventCardAttachment event) { @@ -228,7 +217,8 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base { PlayerZone zEq = (PlayerZone)game.getZoneOf(event.equipment); Zone z1 = event.oldEntiy instanceof Card ? game.getZoneOf((Card)event.oldEntiy) : null; Zone z2 = event.newTarget instanceof Card ? game.getZoneOf((Card)event.newTarget) : null; - updateTwoZones(z1, z2); + if ( z1 instanceof PlayerZone ) updateZone((PlayerZone) z1); + if ( z2 instanceof PlayerZone ) updateZone((PlayerZone) z2); return updateZone(zEq); } @@ -251,11 +241,15 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base { } private Void updateZone(PlayerZone z) { + return updateZone(Pair.of(z.getPlayer(), z.getZoneType())); + } + + private Void updateZone(Pair kv) { boolean needUpdate = false; synchronized (zonesToUpdate) { needUpdate = zonesToUpdate.isEmpty(); - if ( !zonesToUpdate.contains(z) ) { - zonesToUpdate.add(z); + if ( !zonesToUpdate.contains(kv) ) { + zonesToUpdate.add(kv); } } if( needUpdate ) diff --git a/src/main/java/forge/game/Game.java b/src/main/java/forge/game/Game.java index 9b9d0952e76..1646f593ff9 100644 --- a/src/main/java/forge/game/Game.java +++ b/src/main/java/forge/game/Game.java @@ -75,7 +75,7 @@ public class Game { private final GameLog gameLog = new GameLog(); private final ColorChanger colorChanger = new ColorChanger(); - private final Zone stackZone = new Zone(ZoneType.Stack); + private final Zone stackZone = new Zone(ZoneType.Stack, this); private long timestamp = 0; public final GameAction action; diff --git a/src/main/java/forge/game/GameNew.java b/src/main/java/forge/game/GameNew.java index b8d07c87bf8..9a586e4cfde 100644 --- a/src/main/java/forge/game/GameNew.java +++ b/src/main/java/forge/game/GameNew.java @@ -57,7 +57,7 @@ public class GameNew { for (final IPaperCard cp : cards) { Card c = cp.toForgeCard(player); c.setOwner(player); - bf.add(c, false); + bf.add(c); c.setSickness(true); c.setStartsGameInPlay(true); c.refreshUniqueNumber(); @@ -71,7 +71,7 @@ public class GameNew { // Mainly for avatar, but might find something else here for (final IPaperCard c : psc.getCardsInCommand(player)) { - com.add(c.toForgeCard(player), false); + com.add(c.toForgeCard(player)); } // Schemes diff --git a/src/main/java/forge/game/event/IGameEventVisitor.java b/src/main/java/forge/game/event/IGameEventVisitor.java index bea9c00b40e..5ad0074861f 100644 --- a/src/main/java/forge/game/event/IGameEventVisitor.java +++ b/src/main/java/forge/game/event/IGameEventVisitor.java @@ -39,8 +39,9 @@ public interface IGameEventVisitor { T visit(GameEventTurnBegan gameEventTurnBegan); T visit(GameEventTurnEnded event); T visit(GameEventTurnPhase event); - - + T visit(GameEventZone event); + + // This is base class for all visitors. public static class Base implements IGameEventVisitor{ public T visit(GameEventAnteCardsSelected event) { return null; } @@ -77,6 +78,7 @@ public interface IGameEventVisitor { public T visit(GameEventTurnEnded event) { return null; } public T visit(GameEventTurnPhase event) { return null; } public T visit(GameEventPlayerDamaged event) { return null; } + public T visit(GameEventZone event) { return null; } } diff --git a/src/main/java/forge/game/zone/IZone.java b/src/main/java/forge/game/zone/IZone.java index e3876cd0974..d0ef44ad261 100644 --- a/src/main/java/forge/game/zone/IZone.java +++ b/src/main/java/forge/game/zone/IZone.java @@ -22,6 +22,7 @@ import java.util.List; import com.google.common.base.Predicate; import forge.Card; +import forge.game.player.Player; /** *

@@ -33,146 +34,26 @@ import forge.Card; */ interface IZone { - /** - *

- * size. - *

- * - * @return a int. - */ int size(); - - /** - *

- * add. - *

- * - * @param o - * a {@link java.lang.Object} object. - */ - void add(Object o); - - void add(Object o, boolean b); - - /** - *

- * add. - *

- * - * @param c - * a {@link forge.Card} object. - * @param index - * a int. - */ - void add(Card c, int index); - - /** - *

- * get. - *

- * - * @param index - * a int. - * @return a {@link forge.Card} object. - */ - Card get(int index); - - /** - *

- * remove. - *

- * - * @param o - * a {@link java.lang.Object} object. - */ - void remove(Card o); - - /** - *

- * setCards. - *

- * - * @param c - * an array of {@link forge.Card} objects. - */ - void setCards(Iterable c); - - /** - *

- * getCards. - *

- * - * @param filter - * the filter - * @return an array of {@link forge.Card} objects. - */ - List getCards(boolean filter); - - /** - * Gets the cards. - * - * @return the cards - */ - List getCards(); - - /** - * Contains. - * - * @param c - * the c - * @return true, if successful - */ - boolean contains(Card c); - boolean contains(final Predicate condition); - /** - * isEmpty returns true if given zone contains no cards. - * - * @return true, if is empty - */ boolean isEmpty(); + boolean contains(Card c); + boolean contains(final Predicate condition); - /** - *

- * is. - *

- * - * @param zone - * a {@link java.lang.String} object. - * @return a boolean. - */ + void add(Card o); + void add(Card c, int index); + void remove(Card o); + void setCards(Iterable c); + + Card get(int index); + List getCards(boolean filter); + List getCards(); + + ZoneType getZoneType(); + Player getPlayer(); boolean is(ZoneType zone); + boolean is(ZoneType zone, Player player); + - /** - * Checks if is. - * - * @param zones - * the zones - * @return true, if successful - */ - boolean is(List zones); - - /** - *

- * getZoneName. - *

- * - * @return a {@link java.lang.String} object. - */ - ZoneType getZoneType(); // returns the Zone's name like Graveyard - - /** - *

- * toString. - *

- * - * @return a {@link java.lang.String} object. - */ - @Override - String toString(); - - /** - * Reset cards added this turn. - */ void resetCardsAddedThisTurn(); } diff --git a/src/main/java/forge/game/zone/PlayerZone.java b/src/main/java/forge/game/zone/PlayerZone.java index dd58edba706..6bdf55eb22a 100644 --- a/src/main/java/forge/game/zone/PlayerZone.java +++ b/src/main/java/forge/game/zone/PlayerZone.java @@ -87,40 +87,15 @@ public class PlayerZone extends Zone { - /** - *

- * Constructor for DefaultPlayerZone. - *

- * - * @param zone - * a {@link java.lang.String} object. - * @param inPlayer - * a {@link forge.game.player.Player} object. - */ public PlayerZone(final ZoneType zone, final Player inPlayer) { - super(zone); - if ( inPlayer == null ) - throw new IllegalArgumentException("Player zone must be initialized with correct player"); + super(zone, inPlayer.getGame()); this.player = inPlayer; } - // ************ BEGIN - these methods fire updateObservers() ************* - @Override - public void add(final Object o, boolean update) { - final Card c = (Card) o; - - // Immutable cards are usually emblems and effects - we don't want to log those. - if (!c.isImmutable()) { - this.cardsAddedThisTurn.add(c); - final Zone zone = c.getGame().getZoneOf(c); - if (zone != null) { - this.cardsAddedThisTurnSource.add(zone.getZoneType()); - } else { - this.cardsAddedThisTurnSource.add(null); - } - } - + public void add(final Card c) { + // WTF IS THIS? Replacement effects in zone.add code! + if (this.is(ZoneType.Graveyard) && c.hasKeyword("If CARDNAME would be put into a graveyard " + "from anywhere, reveal CARDNAME and shuffle it into its owner's library instead.")) { @@ -137,26 +112,7 @@ public class PlayerZone extends Zone { return; } - c.setTurnInZone(c.getGame().getPhaseHandler().getTurn()); - this.cardList.add(c); - - if (!this.is(ZoneType.Battlefield)) { - c.setTapped(false); - } - } - - - /** - * Checks if is. - * - * @param zone - * a {@link java.lang.String} object. - * @param player - * a {@link forge.game.player.Player} object. - * @return a boolean - */ - public final boolean is(final ZoneType zone, final Player player) { - return (zone == this.zoneType && this.player.equals(player)); + super.add(c); } /** diff --git a/src/main/java/forge/game/zone/PlayerZoneBattlefield.java b/src/main/java/forge/game/zone/PlayerZoneBattlefield.java index 723699fbba7..32f260c2ebe 100644 --- a/src/main/java/forge/game/zone/PlayerZoneBattlefield.java +++ b/src/main/java/forge/game/zone/PlayerZoneBattlefield.java @@ -53,30 +53,18 @@ public class PlayerZoneBattlefield extends PlayerZone { private boolean trigger = true; private boolean leavesTrigger = true; - /** - *

- * Constructor for PlayerZoneComesIntoPlay. - *

- * - * @param zone - * a {@link java.lang.String} object. - * @param player - * a {@link forge.game.player.Player} object. - */ public PlayerZoneBattlefield(final ZoneType zone, final Player player) { super(zone, player); } /** {@inheritDoc} */ @Override - public final void add(final Object o) { - if (o == null) { + public final void add(final Card c) { + if (c == null) { throw new RuntimeException("PlayerZoneComesInto Play : add() object is null"); } - super.add(o); - - final Card c = (Card) o; + super.add(c); if (this.trigger) { if (c.hasKeyword("Hideaway")) { @@ -85,7 +73,7 @@ public class PlayerZoneBattlefield extends PlayerZone { c.setTapped(true); } else { // ETBTapped static abilities - for (final Card ca : c.getGame().getCardsIn(ZoneType.listValueOf("Battlefield,Command"))) { + for (final Card ca : game.getCardsIn(ZoneType.listValueOf("Battlefield,Command"))) { for (final StaticAbility stAb : ca.getStaticAbilities()) { if (stAb.applyAbility("ETBTapped", c)) { // it enters the battlefield this way, and should @@ -97,25 +85,6 @@ public class PlayerZoneBattlefield extends PlayerZone { } } - // cannot use addComesIntoPlayCommand - trigger might be set to false; - // Keep track of max lands can play per turn - /*int addMax = 0; - - for (String keyword : c.getKeyword()) { - if (keyword.startsWith("AdjustLandPlays")) { - final String[] k = keyword.split(":"); - addMax = Integer.valueOf(k[2]); - if (k[1].equals("Each")) { - for( Player p : game.getPlayers() ){ - p.addMaxLandsToPlay(addMax); - } - } else { - c.getController().addMaxLandsToPlay(addMax); - } - } - }*/ - - final Game game = c.getGame(); if (this.trigger) { c.setSickness(true); // summoning sickness c.executeTrigger(ZCTrigger.ENTERFIELD); @@ -168,54 +137,9 @@ public class PlayerZoneBattlefield extends PlayerZone { /** {@inheritDoc} */ @Override - public final void remove(final Card o) { + public final void remove(final Card c) { + super.remove(c); - super.remove(o); - - final Card c = (Card) o; - - // Keep track of max lands can play per turn - // int addMax = 0; - - /*boolean adjustLandPlays = false; - boolean eachPlayer = false; - - if (c.getName().equals("Exploration") || c.getName().equals("Oracle of Mul Daya")) { - addMax = -1; - adjustLandPlays = true; - } else if (c.getName().equals("Azusa, Lost but Seeking")) { - addMax = -2; - adjustLandPlays = true; - } else if (c.getName().equals("Storm Cauldron") || c.getName().equals("Rites of Flourishing")) { - adjustLandPlays = true; - eachPlayer = true; - addMax = -1; - } - - if (adjustLandPlays) { - if (eachPlayer) { - AllZone.getHumanPlayer().addMaxLandsToPlay(addMax); - AllZone.getComputerPlayer().addMaxLandsToPlay(addMax); - } else { - c.getController().addMaxLandsToPlay(addMax); - } - }*/ - - /*for (String keyword : c.getKeyword()) { - if (keyword.startsWith("AdjustLandPlays")) { - final String[] k = keyword.split(":"); - addMax = -Integer.valueOf(k[2]); - if (k[1].equals("Each")) { - for(Player p: game.getPlayers()) - p.addMaxLandsToPlay(addMax); - } else { - c.getController().addMaxLandsToPlay(addMax); - } - } - }*/ - - final Game game = c.getGame(); - if (this.leavesTrigger) { c.executeTrigger(ZCTrigger.LEAVEFIELD); } @@ -233,14 +157,7 @@ public class PlayerZoneBattlefield extends PlayerZone { } } - /** - *

- * setTriggers. - *

- * - * @param b - * a boolean. - */ + public final void setTriggers(final boolean b) { this.trigger = b; this.leavesTrigger = b; @@ -251,14 +168,9 @@ public class PlayerZoneBattlefield extends PlayerZone { public boolean apply(Card crd) { return !crd.isPhasedOut(); } - }; - /* - * (non-Javadoc) - * - * @see forge.DefaultPlayerZone#getCards(boolean) - */ + @Override public final List getCards(final boolean filter) { // Battlefield filters out Phased Out cards by default. Needs to call @@ -267,7 +179,7 @@ public class PlayerZoneBattlefield extends PlayerZone { if (!filter) { return super.getCards(false); } - return Lists.newArrayList(Iterables.filter(cardList, isNotPhased)); + return Lists.newArrayList(Iterables.filter(roCardList, isNotPhased)); } } diff --git a/src/main/java/forge/game/zone/Zone.java b/src/main/java/forge/game/zone/Zone.java index e99d8098d6d..33be1f6a26b 100644 --- a/src/main/java/forge/game/zone/Zone.java +++ b/src/main/java/forge/game/zone/Zone.java @@ -18,6 +18,7 @@ package forge.game.zone; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.Iterator; import java.util.List; @@ -25,9 +26,16 @@ import java.util.concurrent.CopyOnWriteArrayList; import com.google.common.base.Predicate; import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; import forge.Card; +import forge.game.Game; +import forge.game.event.EventValueChangeType; +import forge.game.event.GameEventZone; import forge.game.player.Player; +import forge.util.maps.CollectionSuppliers; +import forge.util.maps.EnumMapOfLists; +import forge.util.maps.MapOfLists; /** *

@@ -42,108 +50,63 @@ public class Zone implements IZone, java.io.Serializable, Iterable { private static final long serialVersionUID = -5687652485777639176L; /** The cards. */ - protected final transient List cardList = new CopyOnWriteArrayList(); + private final transient List cardList = new CopyOnWriteArrayList(); protected final transient List roCardList; protected final ZoneType zoneType; + protected final Game game; - protected final transient List cardsAddedThisTurn = new ArrayList(); - protected final ArrayList cardsAddedThisTurnSource = new ArrayList(); + protected final transient MapOfLists cardsAddedThisTurn = new EnumMapOfLists<>(ZoneType.class, CollectionSuppliers.arrayLists()); - - /** - *

- * Constructor for DefaultPlayerZone. - *

- * - * @param zone - * a {@link java.lang.String} object. - * @param inPlayer - * a {@link forge.game.player.Player} object. - */ - public Zone(final ZoneType zone) { + public Zone(final ZoneType zone, Game game) { this.zoneType = zone; + this.game = game; this.roCardList = Collections.unmodifiableList(cardList); //System.out.println(zoneName + " (ct) " + Integer.toHexString(System.identityHashCode(roCardList))); } @Override - public void add(final Object o, boolean update) { - final Card c = (Card) o; - - // Immutable cards are usually emblems,effects and the mana pool and we - // don't want to log those. - if (!c.isImmutable()) { - this.cardsAddedThisTurn.add(c); - final Zone zone = c.getGame().getZoneOf(c); - if (zone != null) { - this.cardsAddedThisTurnSource.add(zone.getZoneType()); - } else { - this.cardsAddedThisTurnSource.add(null); - } - } - - c.setTurnInZone(c.getGame().getPhaseHandler().getTurn()); - c.setTapped(false); - - this.cardList.add(c); + public Player getPlayer() { // generic zones like stack have no player associated + return null; } - - - /** - * Adds the. - * - * @param o - * a {@link java.lang.Object} object. - */ + @Override - public void add(final Object o) { - this.add(o, true); + public void add(final Card c) { + logCardAdded(c); + updateCardState(c); + this.cardList.add(c); + game.fireEvent(new GameEventZone(zoneType, getPlayer(), EventValueChangeType.Added, c)); } - /** - * Adds the. - * - * @param c - * a {@link forge.Card} object. - * @param index - * a int. - */ + @Override public final void add(final Card c, final int index) { - // Immutable cards are usually emblems,effects and the mana pool and we - // don't want to log those. - if (!c.isImmutable()) { - this.cardsAddedThisTurn.add(c); - final Zone zone = c.getGame().getZoneOf(c); - if (zone != null) { - this.cardsAddedThisTurnSource.add(zone.getZoneType()); - } else { - this.cardsAddedThisTurnSource.add(null); - } - } - - if (!this.is(ZoneType.Battlefield)) { - c.setTapped(false); - } - + logCardAdded(c); + updateCardState(c); this.cardList.add(index, c); - c.setTurnInZone(c.getGame().getPhaseHandler().getTurn()); + game.fireEvent(new GameEventZone(zoneType, getPlayer(), EventValueChangeType.Added, c)); + } + + // Sets turn in zone... why not to add current zone reference into the card itself? + private void updateCardState(final Card c) { + c.setTurnInZone(game.getPhaseHandler().getTurn()); + if (zoneType != ZoneType.Battlefield) { + c.setTapped(false); + } + } + + private void logCardAdded(final Card c) { + // Immutable cards are usually emblems,effects and the mana pool and we + // don't want to log those. + if (c.isImmutable()) return; + + final Zone oldZone = game.getZoneOf(c); + // if any tokens come to battlefield, consider they are from stack. Plain "null" cannot be a key of EnumMap + final ZoneType zt = oldZone == null ? ZoneType.Stack : oldZone.getZoneType(); + cardsAddedThisTurn.add(zt, c); } - /* - * (non-Javadoc) - * - * @see forge.IPlayerZone#contains(forge.Card) - */ - /** - * Contains. - * - * @param c - * Card - * @return boolean - */ @Override public final boolean contains(final Card c) { return this.cardList.contains(c); @@ -153,120 +116,54 @@ public class Zone implements IZone, java.io.Serializable, Iterable { return Iterables.any(this.cardList, condition); } - public final int getPosition(final Card c) { - return this.cardList.indexOf(c); - } - - /** - * Removes the. - * - * @param c - * an Object - */ @Override public void remove(final Card c) { this.cardList.remove(c); + game.fireEvent(new GameEventZone(zoneType, getPlayer(), EventValueChangeType.Removed, c)); } - /** - *

- * Setter for the field cards. - *

- * - * @param c - * an array of {@link forge.Card} objects. - */ @Override public final void setCards(final Iterable cards) { cardList.clear(); for (Card c : cards) { cardList.add(c); } + game.fireEvent(new GameEventZone(zoneType, getPlayer(), EventValueChangeType.ComplexUpdate, null)); + } - // ************ END - these methods fire updateObservers() ************* - - /** - * Checks if is. - * - * @param zone - * a {@link java.lang.String} object. - * @return a boolean - */ @Override public final boolean is(final ZoneType zone) { return zone == this.zoneType; } // PlayerZone should override it with a correct implementation - public boolean is(final ZoneType zone, final Player player) { - return false; - } - - /* - * (non-Javadoc) - * - * @see forge.IPlayerZone#is(java.util.List) - */ @Override - public final boolean is(final List zones) { - return zones.contains(this.zoneType); + public final boolean is(final ZoneType zone, final Player player) { + return zoneType == zone && player == getPlayer(); } - /** - *

- * Getter for the field zoneName. - *

- * - * @return a {@link java.lang.String} object. - */ @Override public final ZoneType getZoneType() { return this.zoneType; } - /** - *

- * size. - *

- * - * @return a int. - */ @Override public final int size() { return this.cardList.size(); } - /** - * Gets the. - * - * @param index - * a int. - * @return a int - */ @Override public final Card get(final int index) { return this.cardList.get(index); } - /** - *

- * Getter for the field cards. - *

- * - * @return an array of {@link forge.Card} objects. - */ @Override public final List getCards() { //System.out.println(zoneName + ": " + Integer.toHexString(System.identityHashCode(roCardList))); return this.getCards(true); } - /* - * (non-Javadoc) - * - * @see forge.IPlayerZone#getCards(boolean) - */ @Override public List getCards(final boolean filter) { // Non-Battlefield PlayerZones don't care about the filter @@ -283,18 +180,6 @@ public class Zone implements IZone, java.io.Serializable, Iterable { return this.cardList.isEmpty(); } - /** - *

- * toString. - *

- * - * @return a {@link java.lang.String} object. - */ - @Override - public String toString() { - return this.zoneType.toString(); - } - /** *

* Getter for the field cardsAddedThisTurn. @@ -306,13 +191,13 @@ public class Zone implements IZone, java.io.Serializable, Iterable { */ public final List getCardsAddedThisTurn(final ZoneType origin) { //System.out.print("Request cards put into " + this.getZoneType() + " from " + origin + ".Amount: "); + if (origin != null) + return Lists.newArrayList(cardsAddedThisTurn.get(origin)); + + // all cards if key == null final List ret = new ArrayList(); - for (int i = 0; i < this.cardsAddedThisTurn.size(); i++) { - if ((this.cardsAddedThisTurnSource.get(i) == origin) || (origin == null)) { - ret.add(this.cardsAddedThisTurn.get(i)); - } - } - //System.out.println(ret.size()); + for(Collection kv : cardsAddedThisTurn.values()) + ret.addAll(kv); return ret; } @@ -324,7 +209,6 @@ public class Zone implements IZone, java.io.Serializable, Iterable { @Override public final void resetCardsAddedThisTurn() { this.cardsAddedThisTurn.clear(); - this.cardsAddedThisTurnSource.clear(); } /* (non-Javadoc) @@ -339,6 +223,18 @@ public class Zone implements IZone, java.io.Serializable, Iterable { { Collections.shuffle(cardList); } + + /** + *

+ * toString. + *

+ * + * @return a {@link java.lang.String} object. + */ + @Override + public String toString() { + return this.zoneType.toString(); + } } diff --git a/src/main/java/forge/gui/match/CMatchUI.java b/src/main/java/forge/gui/match/CMatchUI.java index 6373bf696a8..f3fa28cefca 100644 --- a/src/main/java/forge/gui/match/CMatchUI.java +++ b/src/main/java/forge/gui/match/CMatchUI.java @@ -26,6 +26,8 @@ import java.util.Set; import javax.swing.ImageIcon; +import org.apache.commons.lang3.tuple.Pair; + import com.google.common.collect.Lists; import forge.Card; @@ -37,7 +39,6 @@ import forge.game.combat.Combat; import forge.game.phase.PhaseType; import forge.game.player.LobbyPlayer; import forge.game.player.Player; -import forge.game.zone.PlayerZone; import forge.game.zone.ZoneType; import forge.gui.framework.EDocID; import forge.gui.framework.SDisplayUtil; @@ -298,19 +299,20 @@ public enum CMatchUI { return highlitedCards.contains(card); } - public void updateZones(List zonesToUpdate) { + public void updateZones(List> zonesToUpdate) { //System.out.println("updateZones " + zonesToUpdate); - for(PlayerZone z : zonesToUpdate) { - Player owner = z.getPlayer(); + for(Pair kv : zonesToUpdate) { + Player owner = kv.getKey(); + ZoneType zt = kv.getValue(); - if ( z.is(ZoneType.Command) ) + if ( zt == ZoneType.Command ) getCommandFor(owner).getTabletop().setupPlayZone(); - else if ( z.is(ZoneType.Hand) ) { + else if ( zt == ZoneType.Hand ) { VHand vHand = getHandFor(owner); if (null != vHand) vHand.getLayoutControl().updateHand(); getFieldViewFor(owner).getDetailsPanel().updateZones(); - } else if ( z.is(ZoneType.Battlefield) ) + } else if ( zt == ZoneType.Battlefield ) getFieldViewFor(owner).getTabletop().setupPlayZone(); else getFieldViewFor(owner).getDetailsPanel().updateZones();