diff --git a/.gitattributes b/.gitattributes index a2e15aa3fd6..e7ccce09ddf 100644 --- a/.gitattributes +++ b/.gitattributes @@ -12645,11 +12645,10 @@ src/main/java/forge/game/player/Player.java svneol=native#text/plain src/main/java/forge/game/player/PlayerType.java svneol=native#text/plain src/main/java/forge/game/player/PlayerUtil.java svneol=native#text/plain src/main/java/forge/game/player/package-info.java svneol=native#text/plain -src/main/java/forge/game/zone/DefaultPlayerZone.java svneol=native#text/plain src/main/java/forge/game/zone/IPlayerZone.java svneol=native#text/plain src/main/java/forge/game/zone/MagicStack.java svneol=native#text/plain src/main/java/forge/game/zone/PlayerZone.java svneol=native#text/plain -src/main/java/forge/game/zone/PlayerZoneComesIntoPlay.java svneol=native#text/plain +src/main/java/forge/game/zone/PlayerZoneBattlefield.java svneol=native#text/plain src/main/java/forge/game/zone/ZoneType.java -text src/main/java/forge/game/zone/package-info.java svneol=native#text/plain src/main/java/forge/gui/CardContainer.java svneol=native#text/plain diff --git a/src/main/java/forge/CardUtil.java b/src/main/java/forge/CardUtil.java index ba5a5e03cbc..70dd6465bbd 100644 --- a/src/main/java/forge/CardUtil.java +++ b/src/main/java/forge/CardUtil.java @@ -38,7 +38,7 @@ import forge.card.CardManaCost; import forge.card.EditionInfo; import forge.card.mana.ManaCost; import forge.control.input.InputPayManaCostUtil; -import forge.game.zone.DefaultPlayerZone; +import forge.game.zone.PlayerZone; import forge.game.zone.ZoneType; import forge.gui.GuiDisplayUtil; import forge.item.CardPrinted; @@ -627,10 +627,10 @@ public final class CardUtil { final Card src) { List res = new ArrayList(); if (to != ZoneType.Stack) { - res.addAll(((DefaultPlayerZone) AllZone.getComputerPlayer().getZone(to)).getCardsAddedThisTurn(from)); - res.addAll(((DefaultPlayerZone) AllZone.getHumanPlayer().getZone(to)).getCardsAddedThisTurn(from)); + res.addAll(((PlayerZone) AllZone.getComputerPlayer().getZone(to)).getCardsAddedThisTurn(from)); + res.addAll(((PlayerZone) AllZone.getHumanPlayer().getZone(to)).getCardsAddedThisTurn(from)); } else { - res.addAll(((DefaultPlayerZone) AllZone.getStackZone()).getCardsAddedThisTurn(from)); + res.addAll(((PlayerZone) AllZone.getStackZone()).getCardsAddedThisTurn(from)); } res = CardLists.getValidCards(res, valid, src.getController(), src); diff --git a/src/main/java/forge/GameAction.java b/src/main/java/forge/GameAction.java index e4b08da4f5a..cc9f22ef346 100644 --- a/src/main/java/forge/GameAction.java +++ b/src/main/java/forge/GameAction.java @@ -56,7 +56,7 @@ import forge.game.phase.PhaseHandler; import forge.game.player.ComputerUtil; import forge.game.player.Player; import forge.game.zone.PlayerZone; -import forge.game.zone.PlayerZoneComesIntoPlay; +import forge.game.zone.PlayerZoneBattlefield; import forge.game.zone.ZoneType; import forge.gui.GuiChoose; import forge.gui.match.ViewWinLose; @@ -409,8 +409,8 @@ public class GameAction { } AllZone.getTriggerHandler().suppressMode(TriggerType.ChangesZone); - ((PlayerZoneComesIntoPlay) AllZone.getHumanPlayer().getZone(ZoneType.Battlefield)).setTriggers(false); - ((PlayerZoneComesIntoPlay) AllZone.getComputerPlayer().getZone(ZoneType.Battlefield)).setTriggers(false); + ((PlayerZoneBattlefield) AllZone.getHumanPlayer().getZone(ZoneType.Battlefield)).setTriggers(false); + ((PlayerZoneBattlefield) AllZone.getComputerPlayer().getZone(ZoneType.Battlefield)).setTriggers(false); final int tiz = c.getTurnInZone(); @@ -429,8 +429,8 @@ public class GameAction { AllZone.getTriggerHandler().runTrigger(TriggerType.ChangesController, runParams); AllZone.getTriggerHandler().clearSuppression(TriggerType.ChangesZone); - ((PlayerZoneComesIntoPlay) AllZone.getHumanPlayer().getZone(ZoneType.Battlefield)).setTriggers(true); - ((PlayerZoneComesIntoPlay) AllZone.getComputerPlayer().getZone(ZoneType.Battlefield)).setTriggers(true); + ((PlayerZoneBattlefield) AllZone.getHumanPlayer().getZone(ZoneType.Battlefield)).setTriggers(true); + ((PlayerZoneBattlefield) AllZone.getComputerPlayer().getZone(ZoneType.Battlefield)).setTriggers(true); } /** diff --git a/src/main/java/forge/game/GameNew.java b/src/main/java/forge/game/GameNew.java index 6c307aca23a..ed0a9aaa4a4 100644 --- a/src/main/java/forge/game/GameNew.java +++ b/src/main/java/forge/game/GameNew.java @@ -284,26 +284,14 @@ public class GameNew { private static void newMatchCleanup() { if (Singletons.getModel().getMatchState().getGamesPlayedCount() != 0) { return; } - // Update mouse events in case of dev mode toggle - if (Preferences.DEV_MODE) { - // TODO restore this functionality!!! - //VMatchUI.SINGLETON_INSTANCE.getViewDevMode().getDocument().setVisible(true); - final List allFields = VMatchUI.SINGLETON_INSTANCE.getFieldViews(); - for (final VField field : allFields) { - ((FLabel) field.getLblHand()).setHoverable(true); - ((FLabel) field.getLblLibrary()).setHoverable(true); - } - } - else { - // TODO restore this functionality!!! - //VMatchUI.SINGLETON_INSTANCE.getViewDevMode().getDocument().setVisible(false); - final List allFields = VMatchUI.SINGLETON_INSTANCE.getFieldViews(); + // TODO restore this functionality!!! + //VMatchUI.SINGLETON_INSTANCE.getViewDevMode().getDocument().setVisible(Preferences.DEV_MODE); + final List allFields = VMatchUI.SINGLETON_INSTANCE.getFieldViews(); - for (final VField field : allFields) { - ((FLabel) field.getLblHand()).setHoverable(false); - ((FLabel) field.getLblLibrary()).setHoverable(false); - } + for (final VField field : allFields) { + ((FLabel) field.getLblHand()).setHoverable(Preferences.DEV_MODE); + ((FLabel) field.getLblLibrary()).setHoverable(Preferences.DEV_MODE); } VAntes.SINGLETON_INSTANCE.clearAnteCards(); diff --git a/src/main/java/forge/game/GameState.java b/src/main/java/forge/game/GameState.java index c5571c892f8..daf58460cb5 100644 --- a/src/main/java/forge/game/GameState.java +++ b/src/main/java/forge/game/GameState.java @@ -31,9 +31,8 @@ import forge.game.phase.Upkeep; import forge.game.player.AIPlayer; import forge.game.player.HumanPlayer; import forge.game.player.Player; -import forge.game.zone.DefaultPlayerZone; -import forge.game.zone.MagicStack; import forge.game.zone.PlayerZone; +import forge.game.zone.MagicStack; import forge.game.zone.ZoneType; /** @@ -64,7 +63,7 @@ public class GameState { private final GameLog gameLog = new GameLog(); private boolean gameOver = false; - private final PlayerZone stackZone = new DefaultPlayerZone(ZoneType.Stack, null); + private final PlayerZone stackZone = new PlayerZone(ZoneType.Stack, null); private long timestamp = 0; private GameSummary gameSummary; diff --git a/src/main/java/forge/game/player/Player.java b/src/main/java/forge/game/player/Player.java index 254e19c0a64..14d54e1de3f 100644 --- a/src/main/java/forge/game/player/Player.java +++ b/src/main/java/forge/game/player/Player.java @@ -52,9 +52,8 @@ import forge.card.trigger.TriggerType; import forge.deck.Deck; import forge.game.GameLossReason; import forge.game.phase.PhaseHandler; -import forge.game.zone.DefaultPlayerZone; import forge.game.zone.PlayerZone; -import forge.game.zone.PlayerZoneComesIntoPlay; +import forge.game.zone.PlayerZoneBattlefield; import forge.game.zone.ZoneType; import forge.gui.GuiChoose; import forge.properties.ForgePreferences.FPref; @@ -181,8 +180,8 @@ public abstract class Player extends GameEntity implements Comparable { */ public Player(final String myName, final int myLife, final int myPoisonCounters) { for (final ZoneType z : Player.ALL_ZONES) { - final PlayerZone toPut = z == ZoneType.Battlefield ? new PlayerZoneComesIntoPlay(z, this) - : new DefaultPlayerZone(z, this); + final PlayerZone toPut = z == ZoneType.Battlefield ? new PlayerZoneBattlefield(z, this) + : new PlayerZone(z, this); this.zones.put(z, toPut); } @@ -2305,7 +2304,7 @@ public abstract class Player extends GameEntity implements Comparable { * @return a boolean. */ public final boolean hasLandfall() { - final List list = ((DefaultPlayerZone) this.getZone(ZoneType.Battlefield)).getCardsAddedThisTurn(null); + final List list = ((PlayerZone) this.getZone(ZoneType.Battlefield)).getCardsAddedThisTurn(null); return Iterables.any(list, CardPredicates.Presets.LANDS); } diff --git a/src/main/java/forge/game/zone/DefaultPlayerZone.java b/src/main/java/forge/game/zone/DefaultPlayerZone.java deleted file mode 100644 index 72dd8937aee..00000000000 --- a/src/main/java/forge/game/zone/DefaultPlayerZone.java +++ /dev/null @@ -1,477 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 Forge Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package forge.game.zone; - -import java.util.ArrayList; -import java.util.List; -import java.util.Observable; - -import forge.AllZone; -import forge.Card; - -import forge.Singletons; -import forge.card.trigger.TriggerType; -import forge.game.player.Player; - -/** - *

- * DefaultPlayerZone class. - *

- * - * @author Forge - * @version $Id$ - */ -public class DefaultPlayerZone extends PlayerZone implements java.io.Serializable { - /** Constant serialVersionUID=-5687652485777639176L. */ - private static final long serialVersionUID = -5687652485777639176L; - - /** The cards. */ - private List cardList = new ArrayList(); - private final ZoneType zoneName; - private final Player player; - private boolean update = true; - - private final List cardsAddedThisTurn = new ArrayList(); - private final ArrayList cardsAddedThisTurnSource = new ArrayList(); - - /** - *

- * Constructor for DefaultPlayerZone. - *

- * - * @param zone - * a {@link java.lang.String} object. - * @param inPlayer - * a {@link forge.game.player.Player} object. - */ - public DefaultPlayerZone(final ZoneType zone, final Player inPlayer) { - this.zoneName = zone; - 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,effects and the mana pool and we - // don't want to log those. - if (!c.isImmutable()) { - this.cardsAddedThisTurn.add(c); - final PlayerZone zone = AllZone.getZoneOf(c); - if (zone != null) { - this.cardsAddedThisTurnSource.add(zone.getZoneType()); - } else { - this.cardsAddedThisTurnSource.add(null); - } - } - - 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.")) { - final PlayerZone lib = c.getOwner().getZone(ZoneType.Library); - lib.add(c); - c.getOwner().shuffle(); - return; - } - - if (c.isUnearthed() && (this.is(ZoneType.Graveyard) || this.is(ZoneType.Hand) || this.is(ZoneType.Library))) { - final PlayerZone removed = c.getOwner().getZone(ZoneType.Exile); - removed.add(c); - c.setUnearthed(false); - return; - } - - c.addObserver(this); - - c.setTurnInZone(Singletons.getModel().getGameState().getPhaseHandler().getTurn()); - - if (!this.is(ZoneType.Battlefield) && c.isTapped()) { - AllZone.getTriggerHandler().suppressMode(TriggerType.Untaps); - c.untap(); - AllZone.getTriggerHandler().clearSuppression(TriggerType.Untaps); - } - - this.getCardList().add(c); - - if (update) { - this.update(); - } - } - - - /** - * Adds the. - * - * @param o - * a {@link java.lang.Object} object. - */ - @Override - public void add(final Object o) { - this.add(o, true); - } - - /** - * Update. - * - * @param ob - * an Observable - * @param object - * an Object - */ - @Override - public final void update(final Observable ob, final Object object) { - this.update(); - } - - /** - * 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 PlayerZone zone = AllZone.getZoneOf(c); - if (zone != null) { - this.cardsAddedThisTurnSource.add(zone.getZoneType()); - } else { - this.cardsAddedThisTurnSource.add(null); - } - } - - if (!this.is(ZoneType.Battlefield) && c.isTapped()) { - AllZone.getTriggerHandler().suppressMode(TriggerType.Untaps); - c.untap(); - AllZone.getTriggerHandler().clearSuppression(TriggerType.Untaps); - } - - this.getCardList().add(index, c); - c.setTurnInZone(Singletons.getModel().getGameState().getPhaseHandler().getTurn()); - this.update(); - } - - /* - * (non-Javadoc) - * - * @see forge.IPlayerZone#contains(forge.Card) - */ - /** - * Contains. - * - * @param c - * Card - * @return boolean - */ - @Override - public final boolean contains(final Card c) { - return this.getCardList().contains(c); - } - - /* - * (non-Javadoc) - * - * @see forge.IPlayerZone#getPosition(forge.Card) - */ - @Override - public final Integer getPosition(final Card c) { - int index = this.getCardList().indexOf(c); - if (index == -1) { - return null; - } - return index; - } - - /** - * Removes the. - * - * @param c - * an Object - */ - @Override - public void remove(final Object c) { - this.getCardList().remove(c); - this.update(); - } - - /** - *

- * Setter for the field cards. - *

- * - * @param c - * an array of {@link forge.Card} objects. - */ - @Override - public final void setCards(final Iterable cards) { - List toSet = new ArrayList(); - for (Card c : cards) { - toSet.add(c); - } - this.setCardList(toSet); - this.update(); - } - - // removes all cards - /** - *

- * reset. - *

- */ - @Override - public final void reset() { - this.cardsAddedThisTurn.clear(); - this.cardsAddedThisTurnSource.clear(); - this.getCardList().clear(); - this.update(); - } - - // ************ 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.equals(this.zoneName); - } - - /* - * (non-Javadoc) - * - * @see forge.IPlayerZone#is(java.util.List) - */ - @Override - public final boolean is(final List zones) { - return zones.contains(this.zoneName); - } - - /** - * Checks if is. - * - * @param zone - * a {@link java.lang.String} object. - * @param player - * a {@link forge.game.player.Player} object. - * @return a boolean - */ - @Override - public final boolean is(final ZoneType zone, final Player player) { - return (zone.equals(this.zoneName) && this.player.equals(player)); - } - - /** - *

- * Getter for the field player. - *

- * - * @return a {@link forge.game.player.Player} object. - */ - @Override - public final Player getPlayer() { - return this.player; - } - - /** - *

- * Getter for the field zoneName. - *

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

- * size. - *

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

- * Getter for the field cards. - *

- * - * @return an array of {@link forge.Card} objects. - */ - @Override - public final List getCards() { - 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 - return new ArrayList(this.getCardList()); - } - - /* - * (non-Javadoc) - * - * @see forge.IPlayerZone#getCards(int) - */ - @Override - public final List getCards(final int n) { - return this.getCardList().subList(0, Math.min(this.getCardList().size(), n)); - } - - /* - * (non-Javadoc) - * - * @see forge.IPlayerZone#isEmpty() - */ - @Override - public final boolean isEmpty() { - return this.getCardList().isEmpty(); - } - - /** - *

- * update. - *

- */ - public final void update() { - if (this.update) { - this.updateObservers(); - } - } - - /** - * Sets the update. - * - * @param b - * a boolean. - */ - @Override - public final void setUpdate(final boolean b) { - this.update = b; - } - - /** - *

- * Getter for the field update. - *

- * - * @return a boolean. - */ - @Override - public final boolean getUpdate() { - return this.update; - } - - /** - *

- * toString. - *

- * - * @return a {@link java.lang.String} object. - */ - @Override - public final String toString() { - return this.player != null ? String.format("%s %s", this.player, this.zoneName) : this.zoneName.toString(); - } - - /** - *

- * Getter for the field cardsAddedThisTurn. - *

- * - * @param origin - * a {@link java.lang.String} object. - * @return a {@link forge.CardList} object. - */ - public final List getCardsAddedThisTurn(final ZoneType origin) { - //System.out.print("Request cards put into " + this.getZoneType() + " from " + origin + ".Amount: "); - 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()); - return ret; - } - - /** - *

- * resetCardsAddedThisTurn. - *

- */ - @Override - public final void resetCardsAddedThisTurn() { - this.cardsAddedThisTurn.clear(); - this.cardsAddedThisTurnSource.clear(); - } - - /** - * Gets the card list. - * - * @return the cardList - */ - public List getCardList() { - return this.cardList; - } - - /** - * Sets the card list. - * - * @param cardList0 - * the cardList to set - */ - public void setCardList(final List cardList0) { - this.cardList = cardList0; - } - -} diff --git a/src/main/java/forge/game/zone/PlayerZone.java b/src/main/java/forge/game/zone/PlayerZone.java index 6067fbf6eac..aa639e00ca4 100644 --- a/src/main/java/forge/game/zone/PlayerZone.java +++ b/src/main/java/forge/game/zone/PlayerZone.java @@ -17,19 +17,458 @@ */ package forge.game.zone; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Observable; import java.util.Observer; +import forge.AllZone; +import forge.Card; + +import forge.Singletons; +import forge.card.trigger.TriggerType; +import forge.game.player.Player; import forge.util.MyObservable; -//PlayerZone observers the cards that are added to its zone /** *

- * Abstract PlayerZone class. + * DefaultPlayerZone class. *

* * @author Forge * @version $Id$ */ -public abstract class PlayerZone extends MyObservable implements IPlayerZone, Observer { +public class PlayerZone extends MyObservable implements IPlayerZone, Observer, java.io.Serializable, Iterable { + /** Constant serialVersionUID=-5687652485777639176L. */ + private static final long serialVersionUID = -5687652485777639176L; + + /** The cards. */ + protected final List cardList; + protected final Collection roCardList; + private final ZoneType zoneName; + private final Player player; + private boolean update = true; + + private final List cardsAddedThisTurn = new ArrayList(); + private final ArrayList cardsAddedThisTurnSource = new ArrayList(); + + + + /** + *

+ * 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) { + this.zoneName = zone; + this.player = inPlayer; + this.cardList = new ArrayList(); + this.roCardList = Collections.unmodifiableCollection(cardList); + } + + // ************ BEGIN - these methods fire updateObservers() ************* + + @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 PlayerZone zone = AllZone.getZoneOf(c); + if (zone != null) { + this.cardsAddedThisTurnSource.add(zone.getZoneType()); + } else { + this.cardsAddedThisTurnSource.add(null); + } + } + + 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.")) { + final PlayerZone lib = c.getOwner().getZone(ZoneType.Library); + lib.add(c); + c.getOwner().shuffle(); + return; + } + + if (c.isUnearthed() && (this.is(ZoneType.Graveyard) || this.is(ZoneType.Hand) || this.is(ZoneType.Library))) { + final PlayerZone removed = c.getOwner().getZone(ZoneType.Exile); + removed.add(c); + c.setUnearthed(false); + return; + } + + c.addObserver(this); + + c.setTurnInZone(Singletons.getModel().getGameState().getPhaseHandler().getTurn()); + + if (!this.is(ZoneType.Battlefield) && c.isTapped()) { + AllZone.getTriggerHandler().suppressMode(TriggerType.Untaps); + c.untap(); + AllZone.getTriggerHandler().clearSuppression(TriggerType.Untaps); + } + + this.cardList.add(c); + + if (update) { + this.update(); + } + } + + + /** + * Adds the. + * + * @param o + * a {@link java.lang.Object} object. + */ + @Override + public void add(final Object o) { + this.add(o, true); + } + + /** + * Update. + * + * @param ob + * an Observable + * @param object + * an Object + */ + @Override + public final void update(final Observable ob, final Object object) { + this.update(); + } + + /** + * 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 PlayerZone zone = AllZone.getZoneOf(c); + if (zone != null) { + this.cardsAddedThisTurnSource.add(zone.getZoneType()); + } else { + this.cardsAddedThisTurnSource.add(null); + } + } + + if (!this.is(ZoneType.Battlefield) && c.isTapped()) { + AllZone.getTriggerHandler().suppressMode(TriggerType.Untaps); + c.untap(); + AllZone.getTriggerHandler().clearSuppression(TriggerType.Untaps); + } + + this.cardList.add(index, c); + c.setTurnInZone(Singletons.getModel().getGameState().getPhaseHandler().getTurn()); + this.update(); + } + + /* + * (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); + } + + /* + * (non-Javadoc) + * + * @see forge.IPlayerZone#getPosition(forge.Card) + */ + @Override + public final Integer getPosition(final Card c) { + int index = this.cardList.indexOf(c); + if (index == -1) { + return null; + } + return index; + } + + /** + * Removes the. + * + * @param c + * an Object + */ + @Override + public void remove(final Object c) { + this.cardList.remove(c); + this.update(); + } + + /** + *

+ * 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); + this.update(); + } + + // removes all cards + /** + *

+ * reset. + *

+ */ + @Override + public final void reset() { + this.cardsAddedThisTurn.clear(); + this.cardsAddedThisTurnSource.clear(); + this.cardList.clear(); + this.update(); + } + + // ************ 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.equals(this.zoneName); + } + + /* + * (non-Javadoc) + * + * @see forge.IPlayerZone#is(java.util.List) + */ + @Override + public final boolean is(final List zones) { + return zones.contains(this.zoneName); + } + + /** + * Checks if is. + * + * @param zone + * a {@link java.lang.String} object. + * @param player + * a {@link forge.game.player.Player} object. + * @return a boolean + */ + @Override + public final boolean is(final ZoneType zone, final Player player) { + return (zone.equals(this.zoneName) && this.player.equals(player)); + } + + /** + *

+ * Getter for the field player. + *

+ * + * @return a {@link forge.game.player.Player} object. + */ + @Override + public final Player getPlayer() { + return this.player; + } + + /** + *

+ * Getter for the field zoneName. + *

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

+ * 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() { + 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 + return new ArrayList(this.cardList); + } + + /* + * (non-Javadoc) + * + * @see forge.IPlayerZone#getCards(int) + */ + @Override + public final List getCards(final int n) { + return this.cardList.subList(0, Math.min(this.cardList.size(), n)); + } + + /* + * (non-Javadoc) + * + * @see forge.IPlayerZone#isEmpty() + */ + @Override + public final boolean isEmpty() { + return this.cardList.isEmpty(); + } + + /** + *

+ * update. + *

+ */ + public final void update() { + if (this.update) { + this.updateObservers(); + } + } + + /** + * Sets the update. + * + * @param b + * a boolean. + */ + @Override + public final void setUpdate(final boolean b) { + this.update = b; + } + + /** + *

+ * Getter for the field update. + *

+ * + * @return a boolean. + */ + @Override + public final boolean getUpdate() { + return this.update; + } + + /** + *

+ * toString. + *

+ * + * @return a {@link java.lang.String} object. + */ + @Override + public final String toString() { + return this.player != null ? String.format("%s %s", this.player, this.zoneName) : this.zoneName.toString(); + } + + /** + *

+ * Getter for the field cardsAddedThisTurn. + *

+ * + * @param origin + * a {@link java.lang.String} object. + * @return a {@link forge.CardList} object. + */ + public final List getCardsAddedThisTurn(final ZoneType origin) { + //System.out.print("Request cards put into " + this.getZoneType() + " from " + origin + ".Amount: "); + 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()); + return ret; + } + + /** + *

+ * resetCardsAddedThisTurn. + *

+ */ + @Override + public final void resetCardsAddedThisTurn() { + this.cardsAddedThisTurn.clear(); + this.cardsAddedThisTurnSource.clear(); + } + + /* (non-Javadoc) + * @see java.lang.Iterable#iterator() + */ + @Override + public Iterator iterator() { + return roCardList.iterator(); + } } diff --git a/src/main/java/forge/game/zone/PlayerZoneComesIntoPlay.java b/src/main/java/forge/game/zone/PlayerZoneBattlefield.java similarity index 94% rename from src/main/java/forge/game/zone/PlayerZoneComesIntoPlay.java rename to src/main/java/forge/game/zone/PlayerZoneBattlefield.java index 915f6c1700c..d28fe77acba 100644 --- a/src/main/java/forge/game/zone/PlayerZoneComesIntoPlay.java +++ b/src/main/java/forge/game/zone/PlayerZoneBattlefield.java @@ -20,6 +20,10 @@ package forge.game.zone; import java.util.ArrayList; import java.util.List; +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; + import forge.AllZone; import forge.AllZoneUtil; import forge.Card; @@ -41,7 +45,7 @@ import forge.game.player.Player; * @author Forge * @version $Id$ */ -public class PlayerZoneComesIntoPlay extends DefaultPlayerZone { +public class PlayerZoneBattlefield extends PlayerZone { /** Constant serialVersionUID=5750837078903423978L. */ private static final long serialVersionUID = 5750837078903423978L; @@ -58,7 +62,7 @@ public class PlayerZoneComesIntoPlay extends DefaultPlayerZone { * @param player * a {@link forge.game.player.Player} object. */ - public PlayerZoneComesIntoPlay(final ZoneType zone, final Player player) { + public PlayerZoneBattlefield(final ZoneType zone, final Player player) { super(zone, player); } @@ -278,6 +282,14 @@ public class PlayerZoneComesIntoPlay extends DefaultPlayerZone { this.leavesTrigger = b; } + private static Predicate isNotPhased = new Predicate(){ + @Override + public boolean apply(Card crd) { + return !crd.isPhasedOut(); + } + + }; + /* * (non-Javadoc) * @@ -289,16 +301,9 @@ public class PlayerZoneComesIntoPlay extends DefaultPlayerZone { // getCards(false) to get Phased Out cards if (!filter) { - return new ArrayList(this.getCardList()); + return new ArrayList(cardList); } + return Lists.newArrayList(Iterables.filter(cardList, isNotPhased)); - final ArrayList list = new ArrayList(); - for (Card crd : this.getCardList()) { - - if (!crd.isPhasedOut()) { - list.add(crd); - } - } - return list; } } diff --git a/src/main/java/forge/gui/match/ControlWinLose.java b/src/main/java/forge/gui/match/ControlWinLose.java index f2b606aea83..2eb7058241e 100644 --- a/src/main/java/forge/gui/match/ControlWinLose.java +++ b/src/main/java/forge/gui/match/ControlWinLose.java @@ -2,6 +2,7 @@ package forge.gui.match; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.util.ArrayList; import java.util.List; import javax.swing.JButton; @@ -13,8 +14,10 @@ import forge.Singletons; import forge.control.FControl; import forge.deck.Deck; import forge.game.GameNew; +import forge.game.GameSummary; import forge.game.GameType; import forge.game.PlayerStartsGame; +import forge.game.player.Player; import forge.game.zone.ZoneType; import forge.gui.GuiChoose; import forge.gui.SOverlayUtils; @@ -91,41 +94,54 @@ public class ControlWinLose { boolean isAnte = Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_ANTE); GameType gameType = Singletons.getModel().getMatchState().getGameType(); - Deck hDeck = AllZone.getHumanPlayer().getDeck(); - Deck cDeck = AllZone.getComputerPlayer().getDeck(); - //This is called from QuestWinLoseHandler also. If we're in a quest, this is already handled elsewhere if (isAnte && !gameType.equals(GameType.Quest)) { - if (Singletons.getModel().getMatchState().hasWonLastGame(AllZone.getHumanPlayer().getName())) { - List compAntes = AllZone.getComputerPlayer().getCardsIn(ZoneType.Ante); + executeAnte(); + } + Singletons.getModel().savePrefs(); + CMatchUI.SINGLETON_INSTANCE.initMatch(null); + GameNew.newGame( new PlayerStartsGame(AllZone.getHumanPlayer(), AllZone.getHumanPlayer().getDeck()), + new PlayerStartsGame(AllZone.getComputerPlayer(), AllZone.getComputerPlayer().getDeck())); + + } + + /** + * TODO: Write javadoc for this method. + * @param hDeck + * @param cDeck + */ + private void executeAnte() { + List games = Singletons.getModel().getMatchState().getGamesPlayed(); + GameSummary lastGame = games.get(games.size()-1); + for (Player p: AllZone.getPlayersInGame()) { + if (!p.getName().equals(lastGame.getWinner())) continue; // not a loser + + // remove all the lost cards from owners' decks + List losses = new ArrayList(); + for (Player loser: AllZone.getPlayersInGame()) { + if( loser.equals(p)) continue; // not a loser + + List compAntes = loser.getCardsIn(ZoneType.Ante); + Deck cDeck = loser.getDeck(); - //remove compy's ante cards form his deck for (Card c : compAntes) { CardPrinted toRemove = CardDb.instance().getCard(c); cDeck.getMain().remove(toRemove); } - - List o = GuiChoose.noneOrMany("Select cards to add to your deck", compAntes); + } + + // offer to winner, if he is human + if( p.isHuman() ) { + List o = GuiChoose.noneOrMany("Select cards to add to your deck", losses); if (null != o) { - for (Card c : o) { - hDeck.getMain().add(c); + for (CardPrinted c : o) { + p.getDeck().getMain().add(c); } } - - } else { //compy won - List humanAntes = AllZone.getHumanPlayer().getCardsIn(ZoneType.Ante); - - //remove humans ante cards form his deck - for (Card c : humanAntes) { - CardPrinted toRemove = CardDb.instance().getCard(c); - hDeck.getMain().remove(toRemove); - } } + + break; // expect no other winners } - Singletons.getModel().savePrefs(); - CMatchUI.SINGLETON_INSTANCE.initMatch(null); - GameNew.newGame( new PlayerStartsGame(AllZone.getHumanPlayer(), hDeck), - new PlayerStartsGame(AllZone.getComputerPlayer(), cDeck)); } diff --git a/src/main/java/forge/model/FMatchState.java b/src/main/java/forge/model/FMatchState.java index 53b98f41341..e1b54e182e5 100644 --- a/src/main/java/forge/model/FMatchState.java +++ b/src/main/java/forge/model/FMatchState.java @@ -68,8 +68,8 @@ public class FMatchState { * * @return the games played */ - public final GameSummary[] getGamesPlayed() { - return this.gamesPlayed.toArray(new GameSummary[this.gamesPlayed.size()]); + public final List getGamesPlayed() { + return this.gamesPlayed; } /**