mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 18:28:00 +00:00
* 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:
@@ -699,9 +699,8 @@ public class CardFactoryUtil {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if the target is in the zone it needs to be in to be
|
||||
// targeted
|
||||
if (!zone.is(tgt.getZone())) {
|
||||
// Check if the target is in the zone it needs to be in to be targeted
|
||||
if (!tgt.getZone().contains(zone.getZoneType())) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -59,7 +59,7 @@ public class HumanPlaySpellAbility {
|
||||
final Card c = this.ability.getSourceCard();
|
||||
if (this.ability instanceof Spell && !c.isCopiedSpell()) {
|
||||
fromZone = game.getZoneOf(c);
|
||||
zonePosition = fromZone.getPosition(c);
|
||||
zonePosition = fromZone.getCards().indexOf(c);
|
||||
this.ability.setSourceCard(game.getAction().moveToStack(c));
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@ import forge.game.Game;
|
||||
import forge.game.event.GameEvent;
|
||||
import forge.game.event.GameEventAnteCardsSelected;
|
||||
import forge.game.event.GameEventCardAttachment;
|
||||
import forge.game.event.GameEventCardChangeZone;
|
||||
import forge.game.event.GameEventCardCounters;
|
||||
import forge.game.event.GameEventCardDamaged;
|
||||
import forge.game.event.GameEventCardStatsChanged;
|
||||
@@ -31,12 +30,14 @@ import forge.game.event.GameEventSpellRemovedFromStack;
|
||||
import forge.game.event.GameEventSpellResolved;
|
||||
import forge.game.event.GameEventTurnBegan;
|
||||
import forge.game.event.GameEventTurnPhase;
|
||||
import forge.game.event.GameEventZone;
|
||||
import forge.game.event.IGameEventVisitor;
|
||||
import forge.game.phase.PhaseHandler;
|
||||
import forge.game.phase.PhaseType;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.zone.PlayerZone;
|
||||
import forge.game.zone.Zone;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.gui.GuiDialog;
|
||||
import forge.gui.SOverlayUtils;
|
||||
import forge.gui.match.CMatchUI;
|
||||
@@ -190,7 +191,7 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<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() {
|
||||
@Override public void run() {
|
||||
synchronized (zonesToUpdate) {
|
||||
@@ -201,25 +202,13 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
|
||||
};
|
||||
|
||||
@Override
|
||||
public Void visit(GameEventCardChangeZone event) {
|
||||
updateTwoZones(event.from, event.to);
|
||||
public Void visit(GameEventZone event) {
|
||||
if ( event.player != null ) {
|
||||
// anything except stack will get here
|
||||
updateZone(Pair.of(event.player, event.zoneType));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void updateTwoZones(Zone z1, Zone z2) {
|
||||
boolean needUpdate = false;
|
||||
synchronized (zonesToUpdate) {
|
||||
needUpdate = zonesToUpdate.isEmpty();
|
||||
if ( z1 instanceof PlayerZone && !zonesToUpdate.contains(z1) ) {
|
||||
zonesToUpdate.add((PlayerZone)z1);
|
||||
}
|
||||
if ( z2 instanceof PlayerZone && !zonesToUpdate.contains(z2) ) {
|
||||
zonesToUpdate.add((PlayerZone)z2);
|
||||
}
|
||||
}
|
||||
if( needUpdate )
|
||||
FThreads.invokeInEdtNowOrLater(updZones);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visit(GameEventCardAttachment event) {
|
||||
@@ -228,7 +217,8 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
|
||||
PlayerZone zEq = (PlayerZone)game.getZoneOf(event.equipment);
|
||||
Zone z1 = event.oldEntiy instanceof Card ? game.getZoneOf((Card)event.oldEntiy) : null;
|
||||
Zone z2 = event.newTarget instanceof Card ? game.getZoneOf((Card)event.newTarget) : null;
|
||||
updateTwoZones(z1, z2);
|
||||
if ( z1 instanceof PlayerZone ) updateZone((PlayerZone) z1);
|
||||
if ( z2 instanceof PlayerZone ) updateZone((PlayerZone) z2);
|
||||
return updateZone(zEq);
|
||||
}
|
||||
|
||||
@@ -251,11 +241,15 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
|
||||
}
|
||||
|
||||
private Void updateZone(PlayerZone z) {
|
||||
return updateZone(Pair.of(z.getPlayer(), z.getZoneType()));
|
||||
}
|
||||
|
||||
private Void updateZone(Pair<Player, ZoneType> kv) {
|
||||
boolean needUpdate = false;
|
||||
synchronized (zonesToUpdate) {
|
||||
needUpdate = zonesToUpdate.isEmpty();
|
||||
if ( !zonesToUpdate.contains(z) ) {
|
||||
zonesToUpdate.add(z);
|
||||
if ( !zonesToUpdate.contains(kv) ) {
|
||||
zonesToUpdate.add(kv);
|
||||
}
|
||||
}
|
||||
if( needUpdate )
|
||||
|
||||
@@ -75,7 +75,7 @@ public class Game {
|
||||
private final GameLog gameLog = new GameLog();
|
||||
private final ColorChanger colorChanger = new ColorChanger();
|
||||
|
||||
private final Zone stackZone = new Zone(ZoneType.Stack);
|
||||
private final Zone stackZone = new Zone(ZoneType.Stack, this);
|
||||
|
||||
private long timestamp = 0;
|
||||
public final GameAction action;
|
||||
|
||||
@@ -57,7 +57,7 @@ public class GameNew {
|
||||
for (final IPaperCard cp : cards) {
|
||||
Card c = cp.toForgeCard(player);
|
||||
c.setOwner(player);
|
||||
bf.add(c, false);
|
||||
bf.add(c);
|
||||
c.setSickness(true);
|
||||
c.setStartsGameInPlay(true);
|
||||
c.refreshUniqueNumber();
|
||||
@@ -71,7 +71,7 @@ public class GameNew {
|
||||
|
||||
// Mainly for avatar, but might find something else here
|
||||
for (final IPaperCard c : psc.getCardsInCommand(player)) {
|
||||
com.add(c.toForgeCard(player), false);
|
||||
com.add(c.toForgeCard(player));
|
||||
}
|
||||
|
||||
// Schemes
|
||||
|
||||
@@ -39,8 +39,9 @@ public interface IGameEventVisitor<T> {
|
||||
T visit(GameEventTurnBegan gameEventTurnBegan);
|
||||
T visit(GameEventTurnEnded event);
|
||||
T visit(GameEventTurnPhase event);
|
||||
|
||||
|
||||
T visit(GameEventZone event);
|
||||
|
||||
|
||||
// This is base class for all visitors.
|
||||
public static class Base<T> implements IGameEventVisitor<T>{
|
||||
public T visit(GameEventAnteCardsSelected event) { return null; }
|
||||
@@ -77,6 +78,7 @@ public interface IGameEventVisitor<T> {
|
||||
public T visit(GameEventTurnEnded event) { return null; }
|
||||
public T visit(GameEventTurnPhase event) { return null; }
|
||||
public T visit(GameEventPlayerDamaged event) { return null; }
|
||||
public T visit(GameEventZone event) { return null; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.util.List;
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import forge.Card;
|
||||
import forge.game.player.Player;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -33,146 +34,26 @@ import forge.Card;
|
||||
*/
|
||||
interface IZone {
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* size.
|
||||
* </p>
|
||||
*
|
||||
* @return a int.
|
||||
*/
|
||||
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 contains(Card c);
|
||||
boolean contains(final Predicate<Card> condition);
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* is.
|
||||
* </p>
|
||||
*
|
||||
* @param zone
|
||||
* a {@link java.lang.String} object.
|
||||
* @return a boolean.
|
||||
*/
|
||||
void add(Card o);
|
||||
void add(Card c, int index);
|
||||
void remove(Card o);
|
||||
void setCards(Iterable<Card> c);
|
||||
|
||||
Card get(int index);
|
||||
List<Card> getCards(boolean filter);
|
||||
List<Card> getCards();
|
||||
|
||||
ZoneType getZoneType();
|
||||
Player getPlayer();
|
||||
boolean is(ZoneType zone);
|
||||
boolean is(ZoneType zone, Player player);
|
||||
|
||||
|
||||
/**
|
||||
* Checks if is.
|
||||
*
|
||||
* @param zones
|
||||
* the zones
|
||||
* @return true, if successful
|
||||
*/
|
||||
boolean is(List<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();
|
||||
}
|
||||
|
||||
@@ -87,40 +87,15 @@ 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) {
|
||||
super(zone);
|
||||
if ( inPlayer == null )
|
||||
throw new IllegalArgumentException("Player zone must be initialized with correct player");
|
||||
super(zone, inPlayer.getGame());
|
||||
this.player = inPlayer;
|
||||
}
|
||||
|
||||
// ************ BEGIN - these methods fire updateObservers() *************
|
||||
|
||||
@Override
|
||||
public void add(final Object o, boolean update) {
|
||||
final Card c = (Card) o;
|
||||
|
||||
// Immutable cards are usually emblems and effects - we don't want to log those.
|
||||
if (!c.isImmutable()) {
|
||||
this.cardsAddedThisTurn.add(c);
|
||||
final Zone zone = c.getGame().getZoneOf(c);
|
||||
if (zone != null) {
|
||||
this.cardsAddedThisTurnSource.add(zone.getZoneType());
|
||||
} else {
|
||||
this.cardsAddedThisTurnSource.add(null);
|
||||
}
|
||||
}
|
||||
|
||||
public void add(final Card c) {
|
||||
// WTF IS THIS? Replacement effects in zone.add code!
|
||||
|
||||
if (this.is(ZoneType.Graveyard)
|
||||
&& c.hasKeyword("If CARDNAME would be put into a graveyard "
|
||||
+ "from anywhere, reveal CARDNAME and shuffle it into its owner's library instead.")) {
|
||||
@@ -137,26 +112,7 @@ public class PlayerZone extends Zone {
|
||||
return;
|
||||
}
|
||||
|
||||
c.setTurnInZone(c.getGame().getPhaseHandler().getTurn());
|
||||
this.cardList.add(c);
|
||||
|
||||
if (!this.is(ZoneType.Battlefield)) {
|
||||
c.setTapped(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if is.
|
||||
*
|
||||
* @param zone
|
||||
* a {@link java.lang.String} object.
|
||||
* @param player
|
||||
* a {@link forge.game.player.Player} object.
|
||||
* @return a boolean
|
||||
*/
|
||||
public final boolean is(final ZoneType zone, final Player player) {
|
||||
return (zone == this.zoneType && this.player.equals(player));
|
||||
super.add(c);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -53,30 +53,18 @@ public class PlayerZoneBattlefield extends PlayerZone {
|
||||
private boolean trigger = 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) {
|
||||
super(zone, player);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public final void add(final Object o) {
|
||||
if (o == null) {
|
||||
public final void add(final Card c) {
|
||||
if (c == null) {
|
||||
throw new RuntimeException("PlayerZoneComesInto Play : add() object is null");
|
||||
}
|
||||
|
||||
super.add(o);
|
||||
|
||||
final Card c = (Card) o;
|
||||
super.add(c);
|
||||
|
||||
if (this.trigger) {
|
||||
if (c.hasKeyword("Hideaway")) {
|
||||
@@ -85,7 +73,7 @@ public class PlayerZoneBattlefield extends PlayerZone {
|
||||
c.setTapped(true);
|
||||
} else {
|
||||
// ETBTapped static abilities
|
||||
for (final Card ca : c.getGame().getCardsIn(ZoneType.listValueOf("Battlefield,Command"))) {
|
||||
for (final Card ca : game.getCardsIn(ZoneType.listValueOf("Battlefield,Command"))) {
|
||||
for (final StaticAbility stAb : ca.getStaticAbilities()) {
|
||||
if (stAb.applyAbility("ETBTapped", c)) {
|
||||
// it enters the battlefield this way, and should
|
||||
@@ -97,25 +85,6 @@ public class PlayerZoneBattlefield extends PlayerZone {
|
||||
}
|
||||
}
|
||||
|
||||
// cannot use addComesIntoPlayCommand - trigger might be set to false;
|
||||
// Keep track of max lands can play per turn
|
||||
/*int addMax = 0;
|
||||
|
||||
for (String keyword : c.getKeyword()) {
|
||||
if (keyword.startsWith("AdjustLandPlays")) {
|
||||
final String[] k = keyword.split(":");
|
||||
addMax = Integer.valueOf(k[2]);
|
||||
if (k[1].equals("Each")) {
|
||||
for( Player p : game.getPlayers() ){
|
||||
p.addMaxLandsToPlay(addMax);
|
||||
}
|
||||
} else {
|
||||
c.getController().addMaxLandsToPlay(addMax);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
final Game game = c.getGame();
|
||||
if (this.trigger) {
|
||||
c.setSickness(true); // summoning sickness
|
||||
c.executeTrigger(ZCTrigger.ENTERFIELD);
|
||||
@@ -168,54 +137,9 @@ public class PlayerZoneBattlefield extends PlayerZone {
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public final void remove(final Card o) {
|
||||
public final void remove(final Card c) {
|
||||
super.remove(c);
|
||||
|
||||
super.remove(o);
|
||||
|
||||
final Card c = (Card) o;
|
||||
|
||||
// Keep track of max lands can play per turn
|
||||
// int addMax = 0;
|
||||
|
||||
/*boolean adjustLandPlays = false;
|
||||
boolean eachPlayer = false;
|
||||
|
||||
if (c.getName().equals("Exploration") || c.getName().equals("Oracle of Mul Daya")) {
|
||||
addMax = -1;
|
||||
adjustLandPlays = true;
|
||||
} else if (c.getName().equals("Azusa, Lost but Seeking")) {
|
||||
addMax = -2;
|
||||
adjustLandPlays = true;
|
||||
} else if (c.getName().equals("Storm Cauldron") || c.getName().equals("Rites of Flourishing")) {
|
||||
adjustLandPlays = true;
|
||||
eachPlayer = true;
|
||||
addMax = -1;
|
||||
}
|
||||
|
||||
if (adjustLandPlays) {
|
||||
if (eachPlayer) {
|
||||
AllZone.getHumanPlayer().addMaxLandsToPlay(addMax);
|
||||
AllZone.getComputerPlayer().addMaxLandsToPlay(addMax);
|
||||
} else {
|
||||
c.getController().addMaxLandsToPlay(addMax);
|
||||
}
|
||||
}*/
|
||||
|
||||
/*for (String keyword : c.getKeyword()) {
|
||||
if (keyword.startsWith("AdjustLandPlays")) {
|
||||
final String[] k = keyword.split(":");
|
||||
addMax = -Integer.valueOf(k[2]);
|
||||
if (k[1].equals("Each")) {
|
||||
for(Player p: game.getPlayers())
|
||||
p.addMaxLandsToPlay(addMax);
|
||||
} else {
|
||||
c.getController().addMaxLandsToPlay(addMax);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
final Game game = c.getGame();
|
||||
|
||||
if (this.leavesTrigger) {
|
||||
c.executeTrigger(ZCTrigger.LEAVEFIELD);
|
||||
}
|
||||
@@ -233,14 +157,7 @@ public class PlayerZoneBattlefield extends PlayerZone {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* setTriggers.
|
||||
* </p>
|
||||
*
|
||||
* @param b
|
||||
* a boolean.
|
||||
*/
|
||||
|
||||
public final void setTriggers(final boolean b) {
|
||||
this.trigger = b;
|
||||
this.leavesTrigger = b;
|
||||
@@ -251,14 +168,9 @@ public class PlayerZoneBattlefield extends PlayerZone {
|
||||
public boolean apply(Card crd) {
|
||||
return !crd.isPhasedOut();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see forge.DefaultPlayerZone#getCards(boolean)
|
||||
*/
|
||||
|
||||
@Override
|
||||
public final List<Card> getCards(final boolean filter) {
|
||||
// Battlefield filters out Phased Out cards by default. Needs to call
|
||||
@@ -267,7 +179,7 @@ public class PlayerZoneBattlefield extends PlayerZone {
|
||||
if (!filter) {
|
||||
return super.getCards(false);
|
||||
}
|
||||
return Lists.newArrayList(Iterables.filter(cardList, isNotPhased));
|
||||
return Lists.newArrayList(Iterables.filter(roCardList, isNotPhased));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package forge.game.zone;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
@@ -25,9 +26,16 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import forge.Card;
|
||||
import forge.game.Game;
|
||||
import forge.game.event.EventValueChangeType;
|
||||
import forge.game.event.GameEventZone;
|
||||
import forge.game.player.Player;
|
||||
import forge.util.maps.CollectionSuppliers;
|
||||
import forge.util.maps.EnumMapOfLists;
|
||||
import forge.util.maps.MapOfLists;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -42,108 +50,63 @@ public class Zone implements IZone, java.io.Serializable, Iterable<Card> {
|
||||
private static final long serialVersionUID = -5687652485777639176L;
|
||||
|
||||
/** 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 ZoneType zoneType;
|
||||
protected final Game game;
|
||||
|
||||
protected final transient List<Card> cardsAddedThisTurn = new ArrayList<Card>();
|
||||
protected final ArrayList<ZoneType> cardsAddedThisTurnSource = new ArrayList<ZoneType>();
|
||||
protected final transient MapOfLists<ZoneType, Card> cardsAddedThisTurn = new EnumMapOfLists<>(ZoneType.class, CollectionSuppliers.<Card>arrayLists());
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* <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) {
|
||||
public Zone(final ZoneType zone, Game game) {
|
||||
this.zoneType = zone;
|
||||
this.game = game;
|
||||
this.roCardList = Collections.unmodifiableList(cardList);
|
||||
|
||||
//System.out.println(zoneName + " (ct) " + Integer.toHexString(System.identityHashCode(roCardList)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(final Object o, boolean update) {
|
||||
final Card c = (Card) o;
|
||||
|
||||
// Immutable cards are usually emblems,effects and the mana pool and we
|
||||
// don't want to log those.
|
||||
if (!c.isImmutable()) {
|
||||
this.cardsAddedThisTurn.add(c);
|
||||
final Zone zone = c.getGame().getZoneOf(c);
|
||||
if (zone != null) {
|
||||
this.cardsAddedThisTurnSource.add(zone.getZoneType());
|
||||
} else {
|
||||
this.cardsAddedThisTurnSource.add(null);
|
||||
}
|
||||
}
|
||||
|
||||
c.setTurnInZone(c.getGame().getPhaseHandler().getTurn());
|
||||
c.setTapped(false);
|
||||
|
||||
this.cardList.add(c);
|
||||
public Player getPlayer() { // generic zones like stack have no player associated
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds the.
|
||||
*
|
||||
* @param o
|
||||
* a {@link java.lang.Object} object.
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void add(final Object o) {
|
||||
this.add(o, true);
|
||||
public void add(final Card c) {
|
||||
logCardAdded(c);
|
||||
updateCardState(c);
|
||||
this.cardList.add(c);
|
||||
game.fireEvent(new GameEventZone(zoneType, getPlayer(), EventValueChangeType.Added, c));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the.
|
||||
*
|
||||
* @param c
|
||||
* a {@link forge.Card} object.
|
||||
* @param index
|
||||
* a int.
|
||||
*/
|
||||
|
||||
@Override
|
||||
public final void add(final Card c, final int index) {
|
||||
// Immutable cards are usually emblems,effects and the mana pool and we
|
||||
// don't want to log those.
|
||||
if (!c.isImmutable()) {
|
||||
this.cardsAddedThisTurn.add(c);
|
||||
final Zone zone = c.getGame().getZoneOf(c);
|
||||
if (zone != null) {
|
||||
this.cardsAddedThisTurnSource.add(zone.getZoneType());
|
||||
} else {
|
||||
this.cardsAddedThisTurnSource.add(null);
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.is(ZoneType.Battlefield)) {
|
||||
c.setTapped(false);
|
||||
}
|
||||
|
||||
logCardAdded(c);
|
||||
updateCardState(c);
|
||||
this.cardList.add(index, c);
|
||||
c.setTurnInZone(c.getGame().getPhaseHandler().getTurn());
|
||||
game.fireEvent(new GameEventZone(zoneType, getPlayer(), EventValueChangeType.Added, c));
|
||||
}
|
||||
|
||||
// Sets turn in zone... why not to add current zone reference into the card itself?
|
||||
private void updateCardState(final Card c) {
|
||||
c.setTurnInZone(game.getPhaseHandler().getTurn());
|
||||
if (zoneType != ZoneType.Battlefield) {
|
||||
c.setTapped(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void logCardAdded(final Card c) {
|
||||
// Immutable cards are usually emblems,effects and the mana pool and we
|
||||
// don't want to log those.
|
||||
if (c.isImmutable()) return;
|
||||
|
||||
final Zone oldZone = game.getZoneOf(c);
|
||||
// if any tokens come to battlefield, consider they are from stack. Plain "null" cannot be a key of EnumMap
|
||||
final ZoneType zt = oldZone == null ? ZoneType.Stack : oldZone.getZoneType();
|
||||
cardsAddedThisTurn.add(zt, c);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see forge.IPlayerZone#contains(forge.Card)
|
||||
*/
|
||||
/**
|
||||
* Contains.
|
||||
*
|
||||
* @param c
|
||||
* Card
|
||||
* @return boolean
|
||||
*/
|
||||
@Override
|
||||
public final boolean contains(final Card c) {
|
||||
return this.cardList.contains(c);
|
||||
@@ -153,120 +116,54 @@ public class Zone implements IZone, java.io.Serializable, Iterable<Card> {
|
||||
return Iterables.any(this.cardList, condition);
|
||||
}
|
||||
|
||||
public final int getPosition(final Card c) {
|
||||
return this.cardList.indexOf(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the.
|
||||
*
|
||||
* @param c
|
||||
* an Object
|
||||
*/
|
||||
@Override
|
||||
public void remove(final Card c) {
|
||||
this.cardList.remove(c);
|
||||
game.fireEvent(new GameEventZone(zoneType, getPlayer(), EventValueChangeType.Removed, c));
|
||||
}
|
||||
|
||||
/**
|
||||
* <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);
|
||||
}
|
||||
game.fireEvent(new GameEventZone(zoneType, getPlayer(), EventValueChangeType.ComplexUpdate, null));
|
||||
|
||||
}
|
||||
|
||||
// ************ END - these methods fire updateObservers() *************
|
||||
|
||||
/**
|
||||
* Checks if is.
|
||||
*
|
||||
* @param zone
|
||||
* a {@link java.lang.String} object.
|
||||
* @return a boolean
|
||||
*/
|
||||
@Override
|
||||
public final boolean is(final ZoneType zone) {
|
||||
return zone == this.zoneType;
|
||||
}
|
||||
|
||||
// PlayerZone should override it with a correct implementation
|
||||
public boolean is(final ZoneType zone, final Player player) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see forge.IPlayerZone#is(java.util.List)
|
||||
*/
|
||||
@Override
|
||||
public final boolean is(final List<ZoneType> zones) {
|
||||
return zones.contains(this.zoneType);
|
||||
public final boolean is(final ZoneType zone, final Player player) {
|
||||
return zoneType == zone && player == getPlayer();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Getter for the field <code>zoneName</code>.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
@Override
|
||||
public final ZoneType getZoneType() {
|
||||
return this.zoneType;
|
||||
}
|
||||
|
||||
/**
|
||||
* <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() {
|
||||
//System.out.println(zoneName + ": " + Integer.toHexString(System.identityHashCode(roCardList)));
|
||||
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
|
||||
@@ -283,18 +180,6 @@ public class Zone implements IZone, java.io.Serializable, Iterable<Card> {
|
||||
return this.cardList.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* toString.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.zoneType.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 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) {
|
||||
//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>();
|
||||
for (int i = 0; i < this.cardsAddedThisTurn.size(); i++) {
|
||||
if ((this.cardsAddedThisTurnSource.get(i) == origin) || (origin == null)) {
|
||||
ret.add(this.cardsAddedThisTurn.get(i));
|
||||
}
|
||||
}
|
||||
//System.out.println(ret.size());
|
||||
for(Collection<Card> kv : cardsAddedThisTurn.values())
|
||||
ret.addAll(kv);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -324,7 +209,6 @@ public class Zone implements IZone, java.io.Serializable, Iterable<Card> {
|
||||
@Override
|
||||
public final void resetCardsAddedThisTurn() {
|
||||
this.cardsAddedThisTurn.clear();
|
||||
this.cardsAddedThisTurnSource.clear();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -339,6 +223,18 @@ public class Zone implements IZone, java.io.Serializable, Iterable<Card> {
|
||||
{
|
||||
Collections.shuffle(cardList);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* toString.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.zoneType.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -26,6 +26,8 @@ import java.util.Set;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import forge.Card;
|
||||
@@ -37,7 +39,6 @@ import forge.game.combat.Combat;
|
||||
import forge.game.phase.PhaseType;
|
||||
import forge.game.player.LobbyPlayer;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.zone.PlayerZone;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.gui.framework.EDocID;
|
||||
import forge.gui.framework.SDisplayUtil;
|
||||
@@ -298,19 +299,20 @@ public enum CMatchUI {
|
||||
return highlitedCards.contains(card);
|
||||
}
|
||||
|
||||
public void updateZones(List<PlayerZone> zonesToUpdate) {
|
||||
public void updateZones(List<Pair<Player, ZoneType>> zonesToUpdate) {
|
||||
//System.out.println("updateZones " + zonesToUpdate);
|
||||
for(PlayerZone z : zonesToUpdate) {
|
||||
Player owner = z.getPlayer();
|
||||
for(Pair<Player, ZoneType> kv : zonesToUpdate) {
|
||||
Player owner = kv.getKey();
|
||||
ZoneType zt = kv.getValue();
|
||||
|
||||
if ( z.is(ZoneType.Command) )
|
||||
if ( zt == ZoneType.Command )
|
||||
getCommandFor(owner).getTabletop().setupPlayZone();
|
||||
else if ( z.is(ZoneType.Hand) ) {
|
||||
else if ( zt == ZoneType.Hand ) {
|
||||
VHand vHand = getHandFor(owner);
|
||||
if (null != vHand)
|
||||
vHand.getLayoutControl().updateHand();
|
||||
getFieldViewFor(owner).getDetailsPanel().updateZones();
|
||||
} else if ( z.is(ZoneType.Battlefield) )
|
||||
} else if ( zt == ZoneType.Battlefield )
|
||||
getFieldViewFor(owner).getTabletop().setupPlayZone();
|
||||
else
|
||||
getFieldViewFor(owner).getDetailsPanel().updateZones();
|
||||
|
||||
Reference in New Issue
Block a user