* Zone classes cleanup, they now have reference to game, can contain only cards, used shared code to add cards, generate GameEventZone

This commit is contained in:
Maxmtg
2013-07-03 10:45:01 +00:00
parent 2e4ec0e402
commit c3c847c5ff
11 changed files with 132 additions and 490 deletions

View File

@@ -699,9 +699,8 @@ public class CardFactoryUtil {
return false; return false;
} }
// Check if the target is in the zone it needs to be in to be // Check if the target is in the zone it needs to be in to be targeted
// targeted if (!tgt.getZone().contains(zone.getZoneType())) {
if (!zone.is(tgt.getZone())) {
return false; return false;
} }
} else { } else {

View File

@@ -59,7 +59,7 @@ public class HumanPlaySpellAbility {
final Card c = this.ability.getSourceCard(); final Card c = this.ability.getSourceCard();
if (this.ability instanceof Spell && !c.isCopiedSpell()) { if (this.ability instanceof Spell && !c.isCopiedSpell()) {
fromZone = game.getZoneOf(c); fromZone = game.getZoneOf(c);
zonePosition = fromZone.getPosition(c); zonePosition = fromZone.getCards().indexOf(c);
this.ability.setSourceCard(game.getAction().moveToStack(c)); this.ability.setSourceCard(game.getAction().moveToStack(c));
} }

View File

@@ -14,7 +14,6 @@ import forge.game.Game;
import forge.game.event.GameEvent; import forge.game.event.GameEvent;
import forge.game.event.GameEventAnteCardsSelected; import forge.game.event.GameEventAnteCardsSelected;
import forge.game.event.GameEventCardAttachment; import forge.game.event.GameEventCardAttachment;
import forge.game.event.GameEventCardChangeZone;
import forge.game.event.GameEventCardCounters; import forge.game.event.GameEventCardCounters;
import forge.game.event.GameEventCardDamaged; import forge.game.event.GameEventCardDamaged;
import forge.game.event.GameEventCardStatsChanged; import forge.game.event.GameEventCardStatsChanged;
@@ -31,12 +30,14 @@ import forge.game.event.GameEventSpellRemovedFromStack;
import forge.game.event.GameEventSpellResolved; import forge.game.event.GameEventSpellResolved;
import forge.game.event.GameEventTurnBegan; import forge.game.event.GameEventTurnBegan;
import forge.game.event.GameEventTurnPhase; import forge.game.event.GameEventTurnPhase;
import forge.game.event.GameEventZone;
import forge.game.event.IGameEventVisitor; import forge.game.event.IGameEventVisitor;
import forge.game.phase.PhaseHandler; import forge.game.phase.PhaseHandler;
import forge.game.phase.PhaseType; import forge.game.phase.PhaseType;
import forge.game.player.Player; import forge.game.player.Player;
import forge.game.zone.PlayerZone; import forge.game.zone.PlayerZone;
import forge.game.zone.Zone; import forge.game.zone.Zone;
import forge.game.zone.ZoneType;
import forge.gui.GuiDialog; import forge.gui.GuiDialog;
import forge.gui.SOverlayUtils; import forge.gui.SOverlayUtils;
import forge.gui.match.CMatchUI; import forge.gui.match.CMatchUI;
@@ -190,7 +191,7 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
private final List<PlayerZone> zonesToUpdate = new Vector<PlayerZone>(); private final List<Pair<Player, ZoneType>> zonesToUpdate = new Vector<Pair<Player, ZoneType>>();
private final Runnable updZones = new Runnable() { private final Runnable updZones = new Runnable() {
@Override public void run() { @Override public void run() {
synchronized (zonesToUpdate) { synchronized (zonesToUpdate) {
@@ -201,26 +202,14 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
}; };
@Override @Override
public Void visit(GameEventCardChangeZone event) { public Void visit(GameEventZone event) {
updateTwoZones(event.from, event.to); if ( event.player != null ) {
// anything except stack will get here
updateZone(Pair.of(event.player, event.zoneType));
}
return null; 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 @Override
public Void visit(GameEventCardAttachment event) { public Void visit(GameEventCardAttachment event) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
@@ -228,7 +217,8 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
PlayerZone zEq = (PlayerZone)game.getZoneOf(event.equipment); PlayerZone zEq = (PlayerZone)game.getZoneOf(event.equipment);
Zone z1 = event.oldEntiy instanceof Card ? game.getZoneOf((Card)event.oldEntiy) : null; Zone z1 = event.oldEntiy instanceof Card ? game.getZoneOf((Card)event.oldEntiy) : null;
Zone z2 = event.newTarget instanceof Card ? game.getZoneOf((Card)event.newTarget) : 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); return updateZone(zEq);
} }
@@ -251,11 +241,15 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
} }
private Void updateZone(PlayerZone z) { private Void updateZone(PlayerZone z) {
return updateZone(Pair.of(z.getPlayer(), z.getZoneType()));
}
private Void updateZone(Pair<Player, ZoneType> kv) {
boolean needUpdate = false; boolean needUpdate = false;
synchronized (zonesToUpdate) { synchronized (zonesToUpdate) {
needUpdate = zonesToUpdate.isEmpty(); needUpdate = zonesToUpdate.isEmpty();
if ( !zonesToUpdate.contains(z) ) { if ( !zonesToUpdate.contains(kv) ) {
zonesToUpdate.add(z); zonesToUpdate.add(kv);
} }
} }
if( needUpdate ) if( needUpdate )

View File

@@ -75,7 +75,7 @@ public class Game {
private final GameLog gameLog = new GameLog(); private final GameLog gameLog = new GameLog();
private final ColorChanger colorChanger = new ColorChanger(); 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; private long timestamp = 0;
public final GameAction action; public final GameAction action;

View File

@@ -57,7 +57,7 @@ public class GameNew {
for (final IPaperCard cp : cards) { for (final IPaperCard cp : cards) {
Card c = cp.toForgeCard(player); Card c = cp.toForgeCard(player);
c.setOwner(player); c.setOwner(player);
bf.add(c, false); bf.add(c);
c.setSickness(true); c.setSickness(true);
c.setStartsGameInPlay(true); c.setStartsGameInPlay(true);
c.refreshUniqueNumber(); c.refreshUniqueNumber();
@@ -71,7 +71,7 @@ public class GameNew {
// Mainly for avatar, but might find something else here // Mainly for avatar, but might find something else here
for (final IPaperCard c : psc.getCardsInCommand(player)) { for (final IPaperCard c : psc.getCardsInCommand(player)) {
com.add(c.toForgeCard(player), false); com.add(c.toForgeCard(player));
} }
// Schemes // Schemes

View File

@@ -39,6 +39,7 @@ public interface IGameEventVisitor<T> {
T visit(GameEventTurnBegan gameEventTurnBegan); T visit(GameEventTurnBegan gameEventTurnBegan);
T visit(GameEventTurnEnded event); T visit(GameEventTurnEnded event);
T visit(GameEventTurnPhase event); T visit(GameEventTurnPhase event);
T visit(GameEventZone event);
// This is base class for all visitors. // This is base class for all visitors.
@@ -77,6 +78,7 @@ public interface IGameEventVisitor<T> {
public T visit(GameEventTurnEnded event) { return null; } public T visit(GameEventTurnEnded event) { return null; }
public T visit(GameEventTurnPhase event) { return null; } public T visit(GameEventTurnPhase event) { return null; }
public T visit(GameEventPlayerDamaged event) { return null; } public T visit(GameEventPlayerDamaged event) { return null; }
public T visit(GameEventZone event) { return null; }
} }

View File

@@ -22,6 +22,7 @@ import java.util.List;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import forge.Card; import forge.Card;
import forge.game.player.Player;
/** /**
* <p> * <p>
@@ -33,146 +34,26 @@ import forge.Card;
*/ */
interface IZone { interface IZone {
/**
* <p>
* size.
* </p>
*
* @return a int.
*/
int size(); int size();
/**
* <p>
* add.
* </p>
*
* @param o
* a {@link java.lang.Object} object.
*/
void add(Object o);
void add(Object o, boolean b);
/**
* <p>
* add.
* </p>
*
* @param c
* a {@link forge.Card} object.
* @param index
* a int.
*/
void add(Card c, int index);
/**
* <p>
* get.
* </p>
*
* @param index
* a int.
* @return a {@link forge.Card} object.
*/
Card get(int index);
/**
* <p>
* remove.
* </p>
*
* @param o
* a {@link java.lang.Object} object.
*/
void remove(Card o);
/**
* <p>
* setCards.
* </p>
*
* @param c
* an array of {@link forge.Card} objects.
*/
void setCards(Iterable<Card> c);
/**
* <p>
* getCards.
* </p>
*
* @param filter
* the filter
* @return an array of {@link forge.Card} objects.
*/
List<Card> getCards(boolean filter);
/**
* Gets the cards.
*
* @return the cards
*/
List<Card> getCards();
/**
* Contains.
*
* @param c
* the c
* @return true, if successful
*/
boolean contains(Card c);
boolean contains(final Predicate<Card> condition);
/**
* isEmpty returns true if given zone contains no cards.
*
* @return true, if is empty
*/
boolean isEmpty(); boolean isEmpty();
boolean contains(Card c);
boolean contains(final Predicate<Card> condition);
/** void add(Card o);
* <p> void add(Card c, int index);
* is. void remove(Card o);
* </p> void setCards(Iterable<Card> c);
*
* @param zone Card get(int index);
* a {@link java.lang.String} object. List<Card> getCards(boolean filter);
* @return a boolean. List<Card> getCards();
*/
ZoneType getZoneType();
Player getPlayer();
boolean is(ZoneType zone); boolean is(ZoneType zone);
boolean is(ZoneType zone, Player player);
/**
* Checks if is.
*
* @param zones
* the zones
* @return true, if successful
*/
boolean is(List<ZoneType> zones);
/**
* <p>
* getZoneName.
* </p>
*
* @return a {@link java.lang.String} object.
*/
ZoneType getZoneType(); // returns the Zone's name like Graveyard
/**
* <p>
* toString.
* </p>
*
* @return a {@link java.lang.String} object.
*/
@Override
String toString();
/**
* Reset cards added this turn.
*/
void resetCardsAddedThisTurn(); void resetCardsAddedThisTurn();
} }

View File

@@ -87,39 +87,14 @@ public class PlayerZone extends Zone {
/**
* <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) { public PlayerZone(final ZoneType zone, final Player inPlayer) {
super(zone); super(zone, inPlayer.getGame());
if ( inPlayer == null )
throw new IllegalArgumentException("Player zone must be initialized with correct player");
this.player = inPlayer; this.player = inPlayer;
} }
// ************ BEGIN - these methods fire updateObservers() *************
@Override @Override
public void add(final Object o, boolean update) { public void add(final Card c) {
final Card c = (Card) o; // WTF IS THIS? Replacement effects in zone.add code!
// 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);
}
}
if (this.is(ZoneType.Graveyard) if (this.is(ZoneType.Graveyard)
&& c.hasKeyword("If CARDNAME would be put into a graveyard " && c.hasKeyword("If CARDNAME would be put into a graveyard "
@@ -137,26 +112,7 @@ public class PlayerZone extends Zone {
return; return;
} }
c.setTurnInZone(c.getGame().getPhaseHandler().getTurn()); super.add(c);
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));
} }
/** /**

View File

@@ -53,30 +53,18 @@ public class PlayerZoneBattlefield extends PlayerZone {
private boolean trigger = true; private boolean trigger = true;
private boolean leavesTrigger = true; private boolean leavesTrigger = true;
/**
* <p>
* Constructor for PlayerZoneComesIntoPlay.
* </p>
*
* @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) { public PlayerZoneBattlefield(final ZoneType zone, final Player player) {
super(zone, player); super(zone, player);
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public final void add(final Object o) { public final void add(final Card c) {
if (o == null) { if (c == null) {
throw new RuntimeException("PlayerZoneComesInto Play : add() object is null"); throw new RuntimeException("PlayerZoneComesInto Play : add() object is null");
} }
super.add(o); super.add(c);
final Card c = (Card) o;
if (this.trigger) { if (this.trigger) {
if (c.hasKeyword("Hideaway")) { if (c.hasKeyword("Hideaway")) {
@@ -85,7 +73,7 @@ public class PlayerZoneBattlefield extends PlayerZone {
c.setTapped(true); c.setTapped(true);
} else { } else {
// ETBTapped static abilities // 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()) { for (final StaticAbility stAb : ca.getStaticAbilities()) {
if (stAb.applyAbility("ETBTapped", c)) { if (stAb.applyAbility("ETBTapped", c)) {
// it enters the battlefield this way, and should // 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) { if (this.trigger) {
c.setSickness(true); // summoning sickness c.setSickness(true); // summoning sickness
c.executeTrigger(ZCTrigger.ENTERFIELD); c.executeTrigger(ZCTrigger.ENTERFIELD);
@@ -168,53 +137,8 @@ public class PlayerZoneBattlefield extends PlayerZone {
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @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) { if (this.leavesTrigger) {
c.executeTrigger(ZCTrigger.LEAVEFIELD); c.executeTrigger(ZCTrigger.LEAVEFIELD);
@@ -233,14 +157,7 @@ public class PlayerZoneBattlefield extends PlayerZone {
} }
} }
/**
* <p>
* setTriggers.
* </p>
*
* @param b
* a boolean.
*/
public final void setTriggers(final boolean b) { public final void setTriggers(final boolean b) {
this.trigger = b; this.trigger = b;
this.leavesTrigger = b; this.leavesTrigger = b;
@@ -251,14 +168,9 @@ public class PlayerZoneBattlefield extends PlayerZone {
public boolean apply(Card crd) { public boolean apply(Card crd) {
return !crd.isPhasedOut(); return !crd.isPhasedOut();
} }
}; };
/*
* (non-Javadoc)
*
* @see forge.DefaultPlayerZone#getCards(boolean)
*/
@Override @Override
public final List<Card> getCards(final boolean filter) { public final List<Card> getCards(final boolean filter) {
// Battlefield filters out Phased Out cards by default. Needs to call // Battlefield filters out Phased Out cards by default. Needs to call
@@ -267,7 +179,7 @@ public class PlayerZoneBattlefield extends PlayerZone {
if (!filter) { if (!filter) {
return super.getCards(false); return super.getCards(false);
} }
return Lists.newArrayList(Iterables.filter(cardList, isNotPhased)); return Lists.newArrayList(Iterables.filter(roCardList, isNotPhased));
} }
} }

View File

@@ -18,6 +18,7 @@
package forge.game.zone; package forge.game.zone;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@@ -25,9 +26,16 @@ import java.util.concurrent.CopyOnWriteArrayList;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import forge.Card; import forge.Card;
import forge.game.Game;
import forge.game.event.EventValueChangeType;
import forge.game.event.GameEventZone;
import forge.game.player.Player; import forge.game.player.Player;
import forge.util.maps.CollectionSuppliers;
import forge.util.maps.EnumMapOfLists;
import forge.util.maps.MapOfLists;
/** /**
* <p> * <p>
@@ -42,108 +50,63 @@ public class Zone implements IZone, java.io.Serializable, Iterable<Card> {
private static final long serialVersionUID = -5687652485777639176L; private static final long serialVersionUID = -5687652485777639176L;
/** The cards. */ /** The cards. */
protected final transient List<Card> cardList = new CopyOnWriteArrayList<Card>(); private final transient List<Card> cardList = new CopyOnWriteArrayList<Card>();
protected final transient List<Card> roCardList; protected final transient List<Card> roCardList;
protected final ZoneType zoneType; protected final ZoneType zoneType;
protected final Game game;
protected final transient List<Card> cardsAddedThisTurn = new ArrayList<Card>(); protected final transient MapOfLists<ZoneType, Card> cardsAddedThisTurn = new EnumMapOfLists<>(ZoneType.class, CollectionSuppliers.<Card>arrayLists());
protected final ArrayList<ZoneType> cardsAddedThisTurnSource = new ArrayList<ZoneType>();
public Zone(final ZoneType zone, Game game) {
/**
* <p>
* Constructor for DefaultPlayerZone.
* </p>
*
* @param zone
* a {@link java.lang.String} object.
* @param inPlayer
* a {@link forge.game.player.Player} object.
*/
public Zone(final ZoneType zone) {
this.zoneType = zone; this.zoneType = zone;
this.game = game;
this.roCardList = Collections.unmodifiableList(cardList); this.roCardList = Collections.unmodifiableList(cardList);
//System.out.println(zoneName + " (ct) " + Integer.toHexString(System.identityHashCode(roCardList))); //System.out.println(zoneName + " (ct) " + Integer.toHexString(System.identityHashCode(roCardList)));
} }
@Override @Override
public void add(final Object o, boolean update) { public Player getPlayer() { // generic zones like stack have no player associated
final Card c = (Card) o; return null;
// 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);
}
/**
* Adds the.
*
* @param o
* a {@link java.lang.Object} object.
*/
@Override @Override
public void add(final Object o) { public void add(final Card c) {
this.add(o, true); 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 @Override
public final void add(final Card c, final int index) { public final void add(final Card c, final int index) {
// Immutable cards are usually emblems,effects and the mana pool and we logCardAdded(c);
// don't want to log those. updateCardState(c);
if (!c.isImmutable()) { this.cardList.add(index, c);
this.cardsAddedThisTurn.add(c); game.fireEvent(new GameEventZone(zoneType, getPlayer(), EventValueChangeType.Added, 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)) { // 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); c.setTapped(false);
} }
this.cardList.add(index, c);
c.setTurnInZone(c.getGame().getPhaseHandler().getTurn());
} }
/* private void logCardAdded(final Card c) {
* (non-Javadoc) // Immutable cards are usually emblems,effects and the mana pool and we
* // don't want to log those.
* @see forge.IPlayerZone#contains(forge.Card) if (c.isImmutable()) return;
*/
/** final Zone oldZone = game.getZoneOf(c);
* Contains. // 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();
* @param c cardsAddedThisTurn.add(zt, c);
* Card }
* @return boolean
*/
@Override @Override
public final boolean contains(final Card c) { public final boolean contains(final Card c) {
return this.cardList.contains(c); return this.cardList.contains(c);
@@ -153,120 +116,54 @@ public class Zone implements IZone, java.io.Serializable, Iterable<Card> {
return Iterables.any(this.cardList, condition); 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 @Override
public void remove(final Card c) { public void remove(final Card c) {
this.cardList.remove(c); this.cardList.remove(c);
game.fireEvent(new GameEventZone(zoneType, getPlayer(), EventValueChangeType.Removed, c));
} }
/**
* <p>
* Setter for the field <code>cards</code>.
* </p>
*
* @param c
* an array of {@link forge.Card} objects.
*/
@Override @Override
public final void setCards(final Iterable<Card> cards) { public final void setCards(final Iterable<Card> cards) {
cardList.clear(); cardList.clear();
for (Card c : cards) { for (Card c : cards) {
cardList.add(c); 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 @Override
public final boolean is(final ZoneType zone) { public final boolean is(final ZoneType zone) {
return zone == this.zoneType; return zone == this.zoneType;
} }
// PlayerZone should override it with a correct implementation // 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 @Override
public final boolean is(final List<ZoneType> zones) { public final boolean is(final ZoneType zone, final Player player) {
return zones.contains(this.zoneType); return zoneType == zone && player == getPlayer();
} }
/**
* <p>
* Getter for the field <code>zoneName</code>.
* </p>
*
* @return a {@link java.lang.String} object.
*/
@Override @Override
public final ZoneType getZoneType() { public final ZoneType getZoneType() {
return this.zoneType; return this.zoneType;
} }
/**
* <p>
* size.
* </p>
*
* @return a int.
*/
@Override @Override
public final int size() { public final int size() {
return this.cardList.size(); return this.cardList.size();
} }
/**
* Gets the.
*
* @param index
* a int.
* @return a int
*/
@Override @Override
public final Card get(final int index) { public final Card get(final int index) {
return this.cardList.get(index); return this.cardList.get(index);
} }
/**
* <p>
* Getter for the field <code>cards</code>.
* </p>
*
* @return an array of {@link forge.Card} objects.
*/
@Override @Override
public final List<Card> getCards() { public final List<Card> getCards() {
//System.out.println(zoneName + ": " + Integer.toHexString(System.identityHashCode(roCardList))); //System.out.println(zoneName + ": " + Integer.toHexString(System.identityHashCode(roCardList)));
return this.getCards(true); return this.getCards(true);
} }
/*
* (non-Javadoc)
*
* @see forge.IPlayerZone#getCards(boolean)
*/
@Override @Override
public List<Card> getCards(final boolean filter) { public List<Card> getCards(final boolean filter) {
// Non-Battlefield PlayerZones don't care about the filter // Non-Battlefield PlayerZones don't care about the filter
@@ -283,18 +180,6 @@ public class Zone implements IZone, java.io.Serializable, Iterable<Card> {
return this.cardList.isEmpty(); return this.cardList.isEmpty();
} }
/**
* <p>
* toString.
* </p>
*
* @return a {@link java.lang.String} object.
*/
@Override
public String toString() {
return this.zoneType.toString();
}
/** /**
* <p> * <p>
* Getter for the field <code>cardsAddedThisTurn</code>. * Getter for the field <code>cardsAddedThisTurn</code>.
@@ -306,13 +191,13 @@ public class Zone implements IZone, java.io.Serializable, Iterable<Card> {
*/ */
public final List<Card> getCardsAddedThisTurn(final ZoneType origin) { public final List<Card> getCardsAddedThisTurn(final ZoneType origin) {
//System.out.print("Request cards put into " + this.getZoneType() + " from " + origin + ".Amount: "); //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<Card> ret = new ArrayList<Card>(); final List<Card> ret = new ArrayList<Card>();
for (int i = 0; i < this.cardsAddedThisTurn.size(); i++) { for(Collection<Card> kv : cardsAddedThisTurn.values())
if ((this.cardsAddedThisTurnSource.get(i) == origin) || (origin == null)) { ret.addAll(kv);
ret.add(this.cardsAddedThisTurn.get(i));
}
}
//System.out.println(ret.size());
return ret; return ret;
} }
@@ -324,7 +209,6 @@ public class Zone implements IZone, java.io.Serializable, Iterable<Card> {
@Override @Override
public final void resetCardsAddedThisTurn() { public final void resetCardsAddedThisTurn() {
this.cardsAddedThisTurn.clear(); this.cardsAddedThisTurn.clear();
this.cardsAddedThisTurnSource.clear();
} }
/* (non-Javadoc) /* (non-Javadoc)
@@ -340,5 +224,17 @@ public class Zone implements IZone, java.io.Serializable, Iterable<Card> {
Collections.shuffle(cardList); Collections.shuffle(cardList);
} }
/**
* <p>
* toString.
* </p>
*
* @return a {@link java.lang.String} object.
*/
@Override
public String toString() {
return this.zoneType.toString();
}
} }

View File

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