* PlayerZone empty class removed

* PlayerZoneComesIntoPlay is now PlayerZoneBattlefield
* PlayerZone is R/O Iterable on its cards
* ante code no longer depends on get*Player
This commit is contained in:
Maxmtg
2012-10-05 21:44:05 +00:00
parent d87491d4e8
commit df4cfea74d
11 changed files with 521 additions and 553 deletions

3
.gitattributes vendored
View File

@@ -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/PlayerType.java svneol=native#text/plain
src/main/java/forge/game/player/PlayerUtil.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/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/IPlayerZone.java svneol=native#text/plain
src/main/java/forge/game/zone/MagicStack.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/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/ZoneType.java -text
src/main/java/forge/game/zone/package-info.java svneol=native#text/plain src/main/java/forge/game/zone/package-info.java svneol=native#text/plain
src/main/java/forge/gui/CardContainer.java svneol=native#text/plain src/main/java/forge/gui/CardContainer.java svneol=native#text/plain

View File

@@ -38,7 +38,7 @@ import forge.card.CardManaCost;
import forge.card.EditionInfo; import forge.card.EditionInfo;
import forge.card.mana.ManaCost; import forge.card.mana.ManaCost;
import forge.control.input.InputPayManaCostUtil; import forge.control.input.InputPayManaCostUtil;
import forge.game.zone.DefaultPlayerZone; import forge.game.zone.PlayerZone;
import forge.game.zone.ZoneType; import forge.game.zone.ZoneType;
import forge.gui.GuiDisplayUtil; import forge.gui.GuiDisplayUtil;
import forge.item.CardPrinted; import forge.item.CardPrinted;
@@ -627,10 +627,10 @@ public final class CardUtil {
final Card src) { final Card src) {
List<Card> res = new ArrayList<Card>(); List<Card> res = new ArrayList<Card>();
if (to != ZoneType.Stack) { if (to != ZoneType.Stack) {
res.addAll(((DefaultPlayerZone) AllZone.getComputerPlayer().getZone(to)).getCardsAddedThisTurn(from)); res.addAll(((PlayerZone) AllZone.getComputerPlayer().getZone(to)).getCardsAddedThisTurn(from));
res.addAll(((DefaultPlayerZone) AllZone.getHumanPlayer().getZone(to)).getCardsAddedThisTurn(from)); res.addAll(((PlayerZone) AllZone.getHumanPlayer().getZone(to)).getCardsAddedThisTurn(from));
} else { } else {
res.addAll(((DefaultPlayerZone) AllZone.getStackZone()).getCardsAddedThisTurn(from)); res.addAll(((PlayerZone) AllZone.getStackZone()).getCardsAddedThisTurn(from));
} }
res = CardLists.getValidCards(res, valid, src.getController(), src); res = CardLists.getValidCards(res, valid, src.getController(), src);

View File

@@ -56,7 +56,7 @@ import forge.game.phase.PhaseHandler;
import forge.game.player.ComputerUtil; import forge.game.player.ComputerUtil;
import forge.game.player.Player; import forge.game.player.Player;
import forge.game.zone.PlayerZone; import forge.game.zone.PlayerZone;
import forge.game.zone.PlayerZoneComesIntoPlay; import forge.game.zone.PlayerZoneBattlefield;
import forge.game.zone.ZoneType; import forge.game.zone.ZoneType;
import forge.gui.GuiChoose; import forge.gui.GuiChoose;
import forge.gui.match.ViewWinLose; import forge.gui.match.ViewWinLose;
@@ -409,8 +409,8 @@ public class GameAction {
} }
AllZone.getTriggerHandler().suppressMode(TriggerType.ChangesZone); AllZone.getTriggerHandler().suppressMode(TriggerType.ChangesZone);
((PlayerZoneComesIntoPlay) AllZone.getHumanPlayer().getZone(ZoneType.Battlefield)).setTriggers(false); ((PlayerZoneBattlefield) AllZone.getHumanPlayer().getZone(ZoneType.Battlefield)).setTriggers(false);
((PlayerZoneComesIntoPlay) AllZone.getComputerPlayer().getZone(ZoneType.Battlefield)).setTriggers(false); ((PlayerZoneBattlefield) AllZone.getComputerPlayer().getZone(ZoneType.Battlefield)).setTriggers(false);
final int tiz = c.getTurnInZone(); final int tiz = c.getTurnInZone();
@@ -429,8 +429,8 @@ public class GameAction {
AllZone.getTriggerHandler().runTrigger(TriggerType.ChangesController, runParams); AllZone.getTriggerHandler().runTrigger(TriggerType.ChangesController, runParams);
AllZone.getTriggerHandler().clearSuppression(TriggerType.ChangesZone); AllZone.getTriggerHandler().clearSuppression(TriggerType.ChangesZone);
((PlayerZoneComesIntoPlay) AllZone.getHumanPlayer().getZone(ZoneType.Battlefield)).setTriggers(true); ((PlayerZoneBattlefield) AllZone.getHumanPlayer().getZone(ZoneType.Battlefield)).setTriggers(true);
((PlayerZoneComesIntoPlay) AllZone.getComputerPlayer().getZone(ZoneType.Battlefield)).setTriggers(true); ((PlayerZoneBattlefield) AllZone.getComputerPlayer().getZone(ZoneType.Battlefield)).setTriggers(true);
} }
/** /**

View File

@@ -284,26 +284,14 @@ public class GameNew {
private static void newMatchCleanup() { private static void newMatchCleanup() {
if (Singletons.getModel().getMatchState().getGamesPlayedCount() != 0) { return; } 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<VField> allFields = VMatchUI.SINGLETON_INSTANCE.getFieldViews();
for (final VField field : allFields) { // TODO restore this functionality!!!
((FLabel) field.getLblHand()).setHoverable(true); //VMatchUI.SINGLETON_INSTANCE.getViewDevMode().getDocument().setVisible(Preferences.DEV_MODE);
((FLabel) field.getLblLibrary()).setHoverable(true); final List<VField> allFields = VMatchUI.SINGLETON_INSTANCE.getFieldViews();
}
}
else {
// TODO restore this functionality!!!
//VMatchUI.SINGLETON_INSTANCE.getViewDevMode().getDocument().setVisible(false);
final List<VField> allFields = VMatchUI.SINGLETON_INSTANCE.getFieldViews();
for (final VField field : allFields) { for (final VField field : allFields) {
((FLabel) field.getLblHand()).setHoverable(false); ((FLabel) field.getLblHand()).setHoverable(Preferences.DEV_MODE);
((FLabel) field.getLblLibrary()).setHoverable(false); ((FLabel) field.getLblLibrary()).setHoverable(Preferences.DEV_MODE);
}
} }
VAntes.SINGLETON_INSTANCE.clearAnteCards(); VAntes.SINGLETON_INSTANCE.clearAnteCards();

View File

@@ -31,9 +31,8 @@ import forge.game.phase.Upkeep;
import forge.game.player.AIPlayer; import forge.game.player.AIPlayer;
import forge.game.player.HumanPlayer; import forge.game.player.HumanPlayer;
import forge.game.player.Player; import forge.game.player.Player;
import forge.game.zone.DefaultPlayerZone;
import forge.game.zone.MagicStack;
import forge.game.zone.PlayerZone; import forge.game.zone.PlayerZone;
import forge.game.zone.MagicStack;
import forge.game.zone.ZoneType; import forge.game.zone.ZoneType;
/** /**
@@ -64,7 +63,7 @@ public class GameState {
private final GameLog gameLog = new GameLog(); private final GameLog gameLog = new GameLog();
private boolean gameOver = false; 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 long timestamp = 0;
private GameSummary gameSummary; private GameSummary gameSummary;

View File

@@ -52,9 +52,8 @@ import forge.card.trigger.TriggerType;
import forge.deck.Deck; import forge.deck.Deck;
import forge.game.GameLossReason; import forge.game.GameLossReason;
import forge.game.phase.PhaseHandler; import forge.game.phase.PhaseHandler;
import forge.game.zone.DefaultPlayerZone;
import forge.game.zone.PlayerZone; import forge.game.zone.PlayerZone;
import forge.game.zone.PlayerZoneComesIntoPlay; import forge.game.zone.PlayerZoneBattlefield;
import forge.game.zone.ZoneType; import forge.game.zone.ZoneType;
import forge.gui.GuiChoose; import forge.gui.GuiChoose;
import forge.properties.ForgePreferences.FPref; import forge.properties.ForgePreferences.FPref;
@@ -181,8 +180,8 @@ public abstract class Player extends GameEntity implements Comparable<Player> {
*/ */
public Player(final String myName, final int myLife, final int myPoisonCounters) { public Player(final String myName, final int myLife, final int myPoisonCounters) {
for (final ZoneType z : Player.ALL_ZONES) { for (final ZoneType z : Player.ALL_ZONES) {
final PlayerZone toPut = z == ZoneType.Battlefield ? new PlayerZoneComesIntoPlay(z, this) final PlayerZone toPut = z == ZoneType.Battlefield ? new PlayerZoneBattlefield(z, this)
: new DefaultPlayerZone(z, this); : new PlayerZone(z, this);
this.zones.put(z, toPut); this.zones.put(z, toPut);
} }
@@ -2305,7 +2304,7 @@ public abstract class Player extends GameEntity implements Comparable<Player> {
* @return a boolean. * @return a boolean.
*/ */
public final boolean hasLandfall() { public final boolean hasLandfall() {
final List<Card> list = ((DefaultPlayerZone) this.getZone(ZoneType.Battlefield)).getCardsAddedThisTurn(null); final List<Card> list = ((PlayerZone) this.getZone(ZoneType.Battlefield)).getCardsAddedThisTurn(null);
return Iterables.any(list, CardPredicates.Presets.LANDS); return Iterables.any(list, CardPredicates.Presets.LANDS);
} }

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
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;
/**
* <p>
* DefaultPlayerZone class.
* </p>
*
* @author Forge
* @version $Id$
*/
public class DefaultPlayerZone extends PlayerZone implements java.io.Serializable {
/** Constant <code>serialVersionUID=-5687652485777639176L</code>. */
private static final long serialVersionUID = -5687652485777639176L;
/** The cards. */
private List<Card> cardList = new ArrayList<Card>();
private final ZoneType zoneName;
private final Player player;
private boolean update = true;
private final List<Card> cardsAddedThisTurn = new ArrayList<Card>();
private final ArrayList<ZoneType> cardsAddedThisTurnSource = new ArrayList<ZoneType>();
/**
* <p>
* Constructor for DefaultPlayerZone.
* </p>
*
* @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();
}
/**
* <p>
* Setter for the field <code>cards</code>.
* </p>
*
* @param c
* an array of {@link forge.Card} objects.
*/
@Override
public final void setCards(final Iterable<Card> cards) {
List<Card> toSet = new ArrayList<Card>();
for (Card c : cards) {
toSet.add(c);
}
this.setCardList(toSet);
this.update();
}
// removes all cards
/**
* <p>
* reset.
* </p>
*/
@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<ZoneType> 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));
}
/**
* <p>
* Getter for the field <code>player</code>.
* </p>
*
* @return a {@link forge.game.player.Player} object.
*/
@Override
public final Player getPlayer() {
return this.player;
}
/**
* <p>
* Getter for the field <code>zoneName</code>.
* </p>
*
* @return a {@link java.lang.String} object.
*/
@Override
public final ZoneType getZoneType() {
return this.zoneName;
}
/**
* <p>
* size.
* </p>
*
* @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);
}
/**
* <p>
* Getter for the field <code>cards</code>.
* </p>
*
* @return an array of {@link forge.Card} objects.
*/
@Override
public final List<Card> getCards() {
return this.getCards(true);
}
/*
* (non-Javadoc)
*
* @see forge.IPlayerZone#getCards(boolean)
*/
@Override
public List<Card> getCards(final boolean filter) {
// Non-Battlefield PlayerZones don't care about the filter
return new ArrayList<Card>(this.getCardList());
}
/*
* (non-Javadoc)
*
* @see forge.IPlayerZone#getCards(int)
*/
@Override
public final List<Card> 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();
}
/**
* <p>
* update.
* </p>
*/
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;
}
/**
* <p>
* Getter for the field <code>update</code>.
* </p>
*
* @return a boolean.
*/
@Override
public final boolean getUpdate() {
return this.update;
}
/**
* <p>
* toString.
* </p>
*
* @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();
}
/**
* <p>
* Getter for the field <code>cardsAddedThisTurn</code>.
* </p>
*
* @param origin
* a {@link java.lang.String} object.
* @return a {@link forge.CardList} object.
*/
public final List<Card> getCardsAddedThisTurn(final ZoneType origin) {
//System.out.print("Request cards put into " + this.getZoneType() + " from " + origin + ".Amount: ");
final List<Card> ret = new ArrayList<Card>();
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;
}
/**
* <p>
* resetCardsAddedThisTurn.
* </p>
*/
@Override
public final void resetCardsAddedThisTurn() {
this.cardsAddedThisTurn.clear();
this.cardsAddedThisTurnSource.clear();
}
/**
* Gets the card list.
*
* @return the cardList
*/
public List<Card> getCardList() {
return this.cardList;
}
/**
* Sets the card list.
*
* @param cardList0
* the cardList to set
*/
public void setCardList(final List<Card> cardList0) {
this.cardList = cardList0;
}
}

View File

@@ -17,19 +17,458 @@
*/ */
package forge.game.zone; 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 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; import forge.util.MyObservable;
//PlayerZone observers the cards that are added to its zone
/** /**
* <p> * <p>
* Abstract PlayerZone class. * DefaultPlayerZone class.
* </p> * </p>
* *
* @author Forge * @author Forge
* @version $Id$ * @version $Id$
*/ */
public abstract class PlayerZone extends MyObservable implements IPlayerZone, Observer { public class PlayerZone extends MyObservable implements IPlayerZone, Observer, java.io.Serializable, Iterable<Card> {
/** Constant <code>serialVersionUID=-5687652485777639176L</code>. */
private static final long serialVersionUID = -5687652485777639176L;
/** The cards. */
protected final List<Card> cardList;
protected final Collection<Card> roCardList;
private final ZoneType zoneName;
private final Player player;
private boolean update = true;
private final List<Card> cardsAddedThisTurn = new ArrayList<Card>();
private final ArrayList<ZoneType> cardsAddedThisTurnSource = new ArrayList<ZoneType>();
/**
* <p>
* Constructor for DefaultPlayerZone.
* </p>
*
* @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<Card>();
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();
}
/**
* <p>
* Setter for the field <code>cards</code>.
* </p>
*
* @param c
* an array of {@link forge.Card} objects.
*/
@Override
public final void setCards(final Iterable<Card> cards) {
cardList.clear();
for(Card c : cards)
cardList.add(c);
this.update();
}
// removes all cards
/**
* <p>
* reset.
* </p>
*/
@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<ZoneType> 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));
}
/**
* <p>
* Getter for the field <code>player</code>.
* </p>
*
* @return a {@link forge.game.player.Player} object.
*/
@Override
public final Player getPlayer() {
return this.player;
}
/**
* <p>
* Getter for the field <code>zoneName</code>.
* </p>
*
* @return a {@link java.lang.String} object.
*/
@Override
public final ZoneType getZoneType() {
return this.zoneName;
}
/**
* <p>
* size.
* </p>
*
* @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);
}
/**
* <p>
* Getter for the field <code>cards</code>.
* </p>
*
* @return an array of {@link forge.Card} objects.
*/
@Override
public final List<Card> getCards() {
return this.getCards(true);
}
/*
* (non-Javadoc)
*
* @see forge.IPlayerZone#getCards(boolean)
*/
@Override
public List<Card> getCards(final boolean filter) {
// Non-Battlefield PlayerZones don't care about the filter
return new ArrayList<Card>(this.cardList);
}
/*
* (non-Javadoc)
*
* @see forge.IPlayerZone#getCards(int)
*/
@Override
public final List<Card> 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();
}
/**
* <p>
* update.
* </p>
*/
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;
}
/**
* <p>
* Getter for the field <code>update</code>.
* </p>
*
* @return a boolean.
*/
@Override
public final boolean getUpdate() {
return this.update;
}
/**
* <p>
* toString.
* </p>
*
* @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();
}
/**
* <p>
* Getter for the field <code>cardsAddedThisTurn</code>.
* </p>
*
* @param origin
* a {@link java.lang.String} object.
* @return a {@link forge.CardList} object.
*/
public final List<Card> getCardsAddedThisTurn(final ZoneType origin) {
//System.out.print("Request cards put into " + this.getZoneType() + " from " + origin + ".Amount: ");
final List<Card> ret = new ArrayList<Card>();
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;
}
/**
* <p>
* resetCardsAddedThisTurn.
* </p>
*/
@Override
public final void resetCardsAddedThisTurn() {
this.cardsAddedThisTurn.clear();
this.cardsAddedThisTurnSource.clear();
}
/* (non-Javadoc)
* @see java.lang.Iterable#iterator()
*/
@Override
public Iterator<Card> iterator() {
return roCardList.iterator();
}
} }

View File

@@ -20,6 +20,10 @@ package forge.game.zone;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; 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.AllZone;
import forge.AllZoneUtil; import forge.AllZoneUtil;
import forge.Card; import forge.Card;
@@ -41,7 +45,7 @@ import forge.game.player.Player;
* @author Forge * @author Forge
* @version $Id$ * @version $Id$
*/ */
public class PlayerZoneComesIntoPlay extends DefaultPlayerZone { public class PlayerZoneBattlefield extends PlayerZone {
/** Constant <code>serialVersionUID=5750837078903423978L</code>. */ /** Constant <code>serialVersionUID=5750837078903423978L</code>. */
private static final long serialVersionUID = 5750837078903423978L; private static final long serialVersionUID = 5750837078903423978L;
@@ -58,7 +62,7 @@ public class PlayerZoneComesIntoPlay extends DefaultPlayerZone {
* @param player * @param player
* a {@link forge.game.player.Player} object. * 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); super(zone, player);
} }
@@ -278,6 +282,14 @@ public class PlayerZoneComesIntoPlay extends DefaultPlayerZone {
this.leavesTrigger = b; this.leavesTrigger = b;
} }
private static Predicate<Card> isNotPhased = new Predicate<Card>(){
@Override
public boolean apply(Card crd) {
return !crd.isPhasedOut();
}
};
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
@@ -289,16 +301,9 @@ public class PlayerZoneComesIntoPlay extends DefaultPlayerZone {
// getCards(false) to get Phased Out cards // getCards(false) to get Phased Out cards
if (!filter) { if (!filter) {
return new ArrayList<Card>(this.getCardList()); return new ArrayList<Card>(cardList);
} }
return Lists.newArrayList(Iterables.filter(cardList, isNotPhased));
final ArrayList<Card> list = new ArrayList<Card>();
for (Card crd : this.getCardList()) {
if (!crd.isPhasedOut()) {
list.add(crd);
}
}
return list;
} }
} }

View File

@@ -2,6 +2,7 @@ package forge.gui.match;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.swing.JButton; import javax.swing.JButton;
@@ -13,8 +14,10 @@ import forge.Singletons;
import forge.control.FControl; import forge.control.FControl;
import forge.deck.Deck; import forge.deck.Deck;
import forge.game.GameNew; import forge.game.GameNew;
import forge.game.GameSummary;
import forge.game.GameType; import forge.game.GameType;
import forge.game.PlayerStartsGame; import forge.game.PlayerStartsGame;
import forge.game.player.Player;
import forge.game.zone.ZoneType; import forge.game.zone.ZoneType;
import forge.gui.GuiChoose; import forge.gui.GuiChoose;
import forge.gui.SOverlayUtils; import forge.gui.SOverlayUtils;
@@ -91,41 +94,54 @@ public class ControlWinLose {
boolean isAnte = Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_ANTE); boolean isAnte = Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_ANTE);
GameType gameType = Singletons.getModel().getMatchState().getGameType(); 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 //This is called from QuestWinLoseHandler also. If we're in a quest, this is already handled elsewhere
if (isAnte && !gameType.equals(GameType.Quest)) { if (isAnte && !gameType.equals(GameType.Quest)) {
if (Singletons.getModel().getMatchState().hasWonLastGame(AllZone.getHumanPlayer().getName())) { executeAnte();
List<Card> compAntes = AllZone.getComputerPlayer().getCardsIn(ZoneType.Ante); }
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<GameSummary> 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<CardPrinted> losses = new ArrayList<CardPrinted>();
for (Player loser: AllZone.getPlayersInGame()) {
if( loser.equals(p)) continue; // not a loser
List<Card> compAntes = loser.getCardsIn(ZoneType.Ante);
Deck cDeck = loser.getDeck();
//remove compy's ante cards form his deck
for (Card c : compAntes) { for (Card c : compAntes) {
CardPrinted toRemove = CardDb.instance().getCard(c); CardPrinted toRemove = CardDb.instance().getCard(c);
cDeck.getMain().remove(toRemove); cDeck.getMain().remove(toRemove);
} }
}
List<Card> o = GuiChoose.noneOrMany("Select cards to add to your deck", compAntes);
// offer to winner, if he is human
if( p.isHuman() ) {
List<CardPrinted> o = GuiChoose.noneOrMany("Select cards to add to your deck", losses);
if (null != o) { if (null != o) {
for (Card c : o) { for (CardPrinted c : o) {
hDeck.getMain().add(c); p.getDeck().getMain().add(c);
} }
} }
} else { //compy won
List<Card> 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));
} }

View File

@@ -68,8 +68,8 @@ public class FMatchState {
* *
* @return the games played * @return the games played
*/ */
public final GameSummary[] getGamesPlayed() { public final List<GameSummary> getGamesPlayed() {
return this.gamesPlayed.toArray(new GameSummary[this.gamesPlayed.size()]); return this.gamesPlayed;
} }
/** /**