diff --git a/Mage/src/mage/cards/Cards.java b/Mage/src/mage/cards/Cards.java index b742bb17922..a18cab22f31 100644 --- a/Mage/src/mage/cards/Cards.java +++ b/Mage/src/mage/cards/Cards.java @@ -49,6 +49,7 @@ public interface Cards extends Set, Serializable { public Collection getUniqueCards(Game game); public Card getRandom(Game game); public int count(FilterCard filter, Game game); + public int count(FilterCard filter, UUID playerId, Game game); public void checkTriggers(GameEvent event, Game game); diff --git a/Mage/src/mage/cards/CardsImpl.java b/Mage/src/mage/cards/CardsImpl.java index db390048ce1..bfad6acdc7f 100644 --- a/Mage/src/mage/cards/CardsImpl.java +++ b/Mage/src/mage/cards/CardsImpl.java @@ -123,6 +123,16 @@ public class CardsImpl extends LinkedHashSet implements Cards, Serializabl return result; } + @Override + public int count(FilterCard filter, UUID playerId, Game game) { + int result = 0; + for (UUID card: this) { + if (filter.match(game.getCard(card), playerId, game)) + result++; + } + return result; + } + @Override public void checkTriggers(GameEvent event, Game game) { for (UUID card: this) { diff --git a/Mage/src/mage/filter/FilterCard.java b/Mage/src/mage/filter/FilterCard.java index ba1aac9a20c..334b2b03b10 100644 --- a/Mage/src/mage/filter/FilterCard.java +++ b/Mage/src/mage/filter/FilterCard.java @@ -33,7 +33,9 @@ import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.UUID; +import mage.Constants.TargetController; import mage.cards.Card; +import mage.game.Game; /** * @@ -47,6 +49,7 @@ public class FilterCard> extends FilterObject expansionSetCode = new ArrayList(); protected boolean notExpansionSetCode; + protected TargetController owner = TargetController.ANY; /** * Text that appears on card. @@ -72,6 +75,7 @@ public class FilterCard> extends FilterObject> extends FilterObject getOwnerId() { return ownerId; @@ -136,6 +164,10 @@ public class FilterCard> extends FilterObject 0 && ownerId.contains(testOwnerId) == notOwner) return false; diff --git a/Mage/src/mage/filter/FilterObject.java b/Mage/src/mage/filter/FilterObject.java index efbc7b181bf..ae906fabed1 100644 --- a/Mage/src/mage/filter/FilterObject.java +++ b/Mage/src/mage/filter/FilterObject.java @@ -30,6 +30,7 @@ package mage.filter; import java.util.ArrayList; import java.util.List; +import java.util.UUID; import mage.Constants.CardType; import mage.MageObject; import mage.ObjectColor; @@ -180,8 +181,18 @@ public class FilterObject> ex return notFilter; } - if (abilities.size() > 0 && object.getAbilities().containsAll(abilities) == notAbilities) { - return notFilter; + if (abilities.size() > 0) { + List test = new ArrayList(abilities); + for (Ability ability: object.getAbilities()) { + for (Ability abilityTest: test) { + if (ability == abilityTest || ability.getClass().equals(abilityTest.getClass())) { + test.remove(abilityTest); + break; + } + } + } + if (test.isEmpty() == notAbilities) + return notFilter; } if (convertedManaCostComparison != null) { diff --git a/Mage/src/mage/filter/FilterPermanent.java b/Mage/src/mage/filter/FilterPermanent.java index 766f17062b0..d1fd737eb4d 100644 --- a/Mage/src/mage/filter/FilterPermanent.java +++ b/Mage/src/mage/filter/FilterPermanent.java @@ -53,6 +53,7 @@ public class FilterPermanent> extends FilterObject< protected boolean usePhased; protected boolean phasedIn; protected TargetController controller = TargetController.ANY; + protected TargetController owner = TargetController.ANY; public FilterPermanent() { super("permanent"); @@ -77,6 +78,7 @@ public class FilterPermanent> extends FilterObject< this.usePhased = filter.usePhased; this.phasedIn = filter.phasedIn; this.controller = filter.controller; + this.owner = filter.owner; } public FilterPermanent(String name) { @@ -130,7 +132,24 @@ public class FilterPermanent> extends FilterObject< } } - if (another) { + if (owner != TargetController.ANY && playerId != null) { + switch(owner) { + case YOU: + if (!permanent.getOwnerId().equals(playerId)) + return notFilter; + break; + case OPPONENT: + if (!game.getOpponents(playerId).contains(permanent.getOwnerId())) + return notFilter; + break; + case NOT_YOU: + if (permanent.getOwnerId().equals(playerId)) + return notFilter; + break; + } + } + + if (another) { // filter out itself if (permanent.getId().equals(sourceId)) { return notFilter; @@ -184,25 +203,9 @@ public class FilterPermanent> extends FilterObject< this.controller = controller; } -// public void setController(UUID playerId, Game game) { -// controllerId.clear(); -// switch (controller) { -// case ANY: -// break; -// case YOU: -// controllerId.add(playerId); -// notController = false; -// break; -// case NOT_YOU: -// controllerId.add(playerId); -// notController = true; -// break; -// case OPPONENT: -// controllerId.addAll(game.getOpponents(playerId)); -// notController = false; -// break; -// } -// } + public void setTargetOwner(TargetController owner) { + this.owner = owner; + } public boolean matchOwner(UUID testOwnerId) { if (ownerId.size() > 0 && ownerId.contains(testOwnerId) == notOwner) diff --git a/Mage/src/mage/target/TargetCard.java b/Mage/src/mage/target/TargetCard.java index da2d9709257..1f4cc6ef364 100644 --- a/Mage/src/mage/target/TargetCard.java +++ b/Mage/src/mage/target/TargetCard.java @@ -104,17 +104,21 @@ public class TargetCard> extends TargetObject= this.minNumberOfTargets) + if (player.getHand().count(filter, player.getId(), game) >= this.minNumberOfTargets) return true; break; case GRAVEYARD: - if (player.getGraveyard().count(filter, game) >= this.minNumberOfTargets) + if (player.getGraveyard().count(filter, player.getId(), game) >= this.minNumberOfTargets) return true; break; case LIBRARY: if (player.getLibrary().count(filter, game) >= this.minNumberOfTargets) return true; break; + case EXILED: + if (game.getExile().getPermanentExile().count(filter, player.getId(), game) >= this.minNumberOfTargets) + return true; + break; } } } @@ -149,6 +153,12 @@ public class TargetCard> extends TargetObject