diff --git a/Mage.Client/src/main/java/mage/client/deckeditor/CardSelector.java b/Mage.Client/src/main/java/mage/client/deckeditor/CardSelector.java index 1d8d3a4775..11c2eff256 100644 --- a/Mage.Client/src/main/java/mage/client/deckeditor/CardSelector.java +++ b/Mage.Client/src/main/java/mage/client/deckeditor/CardSelector.java @@ -52,6 +52,8 @@ import mage.filter.predicate.Predicates; import mage.filter.predicate.mageobject.CardTypePredicate; import mage.filter.predicate.mageobject.ColorPredicate; import mage.filter.predicate.mageobject.ColorlessPredicate; +import mage.filter.predicate.other.CardTextPredicate; +import mage.filter.predicate.other.ExpansionSetPredicate; import mage.sets.Sets; import mage.view.CardsView; @@ -212,12 +214,16 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene filter.add(Predicates.or(predicates)); String name = jTextFieldSearch.getText().trim(); - filter.setText(name); + filter.add(new CardTextPredicate(name)); if (this.cbExpansionSet.getSelectedItem() instanceof ExpansionSet) { - filter.getExpansionSetCode().add(((ExpansionSet) this.cbExpansionSet.getSelectedItem()).getCode()); + filter.add(new ExpansionSetPredicate(((ExpansionSet) this.cbExpansionSet.getSelectedItem()).getCode())); } else if (this.cbExpansionSet.getSelectedItem().equals("-- Standard")) { - filter.getExpansionSetCode().addAll(ConstructedFormats.getSetsByFormat("Standard")); + ArrayList> expansionPredicates = new ArrayList>(); + for (String setCode : ConstructedFormats.getSetsByFormat("Standard")) { + expansionPredicates.add(new ExpansionSetPredicate(setCode)); + } + filter.add(Predicates.or(expansionPredicates)); } } @@ -228,14 +234,16 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene setCursor(new Cursor(Cursor.WAIT_CURSOR)); if (limited) { for (Card card: cards) { - if (filter.match(card, null)) + if (filter.match(card, null)) { filteredCards.add(card); + } } } else { for (Card card: CardsStorage.getAllCards()) { - if (filter.match(card, null)) + if (filter.match(card, null)) { filteredCards.add(card); + } } } this.currentView.loadCards(new CardsView(filteredCards), (SortBy) cbSortBy.getSelectedItem(), chkPiles.isSelected(), bigCard, null); diff --git a/Mage.Client/src/main/java/mage/client/deckeditor/table/CardTableSelector.java b/Mage.Client/src/main/java/mage/client/deckeditor/table/CardTableSelector.java index 6a473077ce..6e38a9ef39 100644 --- a/Mage.Client/src/main/java/mage/client/deckeditor/table/CardTableSelector.java +++ b/Mage.Client/src/main/java/mage/client/deckeditor/table/CardTableSelector.java @@ -46,6 +46,8 @@ import mage.filter.predicate.Predicates; import mage.filter.predicate.mageobject.CardTypePredicate; import mage.filter.predicate.mageobject.ColorPredicate; import mage.filter.predicate.mageobject.ColorlessPredicate; +import mage.filter.predicate.other.CardTextPredicate; +import mage.filter.predicate.other.ExpansionSetPredicate; import mage.sets.Sets; import mage.view.CardsView; @@ -142,12 +144,16 @@ public class CardTableSelector extends javax.swing.JPanel implements ComponentLi filter.add(Predicates.or(predicates)); String name = jTextFieldSearch.getText().trim(); - filter.setText(name); + filter.add(new CardTextPredicate(name)); if (this.cbExpansionSet.getSelectedItem() instanceof ExpansionSet) { - filter.getExpansionSetCode().add(((ExpansionSet) this.cbExpansionSet.getSelectedItem()).getCode()); + filter.add(new ExpansionSetPredicate(((ExpansionSet) this.cbExpansionSet.getSelectedItem()).getCode())); } else if (this.cbExpansionSet.getSelectedItem().equals("-- Standard")) { - filter.getExpansionSetCode().addAll(ConstructedFormats.getSetsByFormat("Standard")); + ArrayList> expansionPredicates = new ArrayList>(); + for(String setCode : ConstructedFormats.getSetsByFormat("Standard")) { + expansionPredicates.add(new ExpansionSetPredicate(setCode)); + } + filter.add(Predicates.or(expansionPredicates)); } } diff --git a/Mage.Sets/src/mage/sets/championsofkamigawa/MyojinOfLifesWeb.java b/Mage.Sets/src/mage/sets/championsofkamigawa/MyojinOfLifesWeb.java index 1c32307d8e..9ee7437826 100644 --- a/Mage.Sets/src/mage/sets/championsofkamigawa/MyojinOfLifesWeb.java +++ b/Mage.Sets/src/mage/sets/championsofkamigawa/MyojinOfLifesWeb.java @@ -51,6 +51,7 @@ import mage.cards.CardImpl; import mage.counters.CounterType; import mage.filter.FilterCard; import mage.filter.predicate.mageobject.CardTypePredicate; +import mage.filter.predicate.other.OwnerPredicate; import mage.target.common.TargetCardInHand; import mage.watchers.common.CastFromHandWatcher; @@ -62,7 +63,7 @@ public class MyojinOfLifesWeb extends CardImpl { private static final FilterCard filter = new FilterCard("any number of creature cards from your hand"); static { filter.add(new CardTypePredicate(CardType.CREATURE)); - filter.setTargetOwner(TargetController.YOU); + filter.add(new OwnerPredicate(TargetController.YOU)); } public MyojinOfLifesWeb(UUID ownerId) { @@ -80,7 +81,8 @@ public class MyojinOfLifesWeb extends CardImpl { // Myojin of Life's Web enters the battlefield with a divinity counter on it if you cast it from your hand. this.addAbility(new EntersBattlefieldAbility(new ConditionalOneShotEffect(new AddCountersSourceEffect(CounterType.DIVINITY.createInstance()), new CastFromHandCondition(), ""), "{this} enters the battlefield with a divinity counter on it if you cast it from your hand")); // Myojin of Life's Web is indestructible as long as it has a divinity counter on it. - this.addAbility(new SimpleStaticAbility(Constants.Zone.BATTLEFIELD, new ConditionalContinousEffect(new GainAbilitySourceEffect(IndestructibleAbility.getInstance(), Constants.Duration.WhileOnBattlefield), + this.addAbility(new SimpleStaticAbility(Constants.Zone.BATTLEFIELD, + new ConditionalContinousEffect(new GainAbilitySourceEffect(IndestructibleAbility.getInstance(), Constants.Duration.WhileOnBattlefield), new HasCounterCondition(CounterType.DIVINITY), "{this} is indestructible as long as it has a divinity counter on it"))); // Remove a divinity counter from Myojin of Life's Web: Put any number of creature cards from your hand onto the battlefield. Ability ability = new SimpleActivatedAbility(Constants.Zone.BATTLEFIELD, new PutOntoBattlefieldTargetEffect(false), new RemoveCountersSourceCost(CounterType.DIVINITY.createInstance())); diff --git a/Mage.Sets/src/mage/sets/innistrad/RunicRepetition.java b/Mage.Sets/src/mage/sets/innistrad/RunicRepetition.java index e9cd8f2491..2935abeaad 100644 --- a/Mage.Sets/src/mage/sets/innistrad/RunicRepetition.java +++ b/Mage.Sets/src/mage/sets/innistrad/RunicRepetition.java @@ -36,6 +36,7 @@ import mage.abilities.keyword.FlashbackAbility; import mage.cards.CardImpl; import mage.filter.FilterCard; import mage.filter.predicate.mageobject.AbilityPredicate; +import mage.filter.predicate.other.OwnerPredicate; import mage.target.common.TargetCardInExile; /** @@ -47,7 +48,7 @@ public class RunicRepetition extends CardImpl { private static final FilterCard filter = new FilterCard("exiled card with flashback you own"); static { - filter.setTargetOwner(TargetController.YOU); + filter.add(new OwnerPredicate(TargetController.YOU)); filter.add(new AbilityPredicate(FlashbackAbility.class)); } diff --git a/Mage/src/mage/filter/FilterCard.java b/Mage/src/mage/filter/FilterCard.java index 0144804e9d..682ac8dffe 100644 --- a/Mage/src/mage/filter/FilterCard.java +++ b/Mage/src/mage/filter/FilterCard.java @@ -1,58 +1,53 @@ /* -* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without modification, are -* permitted provided that the following conditions are met: -* -* 1. Redistributions of source code must retain the above copyright notice, this list of -* conditions and the following disclaimer. -* -* 2. Redistributions in binary form must reproduce the above copyright notice, this list -* of conditions and the following disclaimer in the documentation and/or other materials -* provided with the distribution. -* -* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND -* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR -* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -* -* The views and conclusions contained in the software and documentation are those of the -* authors and should not be interpreted as representing official policies, either expressed -* or implied, of BetaSteward_at_googlemail.com. -*/ - + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ package mage.filter; -import mage.Constants.TargetController; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.UUID; import mage.cards.Card; +import mage.filter.predicate.ObjectPlayer; +import mage.filter.predicate.ObjectPlayerPredicate; +import mage.filter.predicate.Predicates; import mage.game.Game; - -import java.util.*; +import mage.game.permanent.Permanent; /** * * @author BetaSteward_at_googlemail.com + * @author North */ public class FilterCard extends FilterObject { private static final long serialVersionUID = 1L; - - protected List ownerId = new ArrayList(); - protected boolean notOwner; - protected List expansionSetCode = new ArrayList(); - protected boolean notExpansionSetCode; - protected TargetController owner = TargetController.ANY; - - /** - * Text that appears on card. - * At the moment only card name and rules are checked. - */ - protected String text = ""; + protected List>> extraPredicates = new ArrayList>>(); public FilterCard() { super("card"); @@ -64,121 +59,24 @@ public class FilterCard extends FilterObject { public FilterCard(FilterCard filter) { super(filter); - this.ownerId.addAll(filter.ownerId); - this.notOwner = filter.notOwner; - this.expansionSetCode.addAll(filter.expansionSetCode); - this.notExpansionSetCode = filter.notExpansionSetCode; - this.owner = filter.owner; - } - - @Override - public boolean match(Card card, Game game) { - if (!super.match(card, game)) - return notFilter; - - if (ownerId.size() > 0 && ownerId.contains(card.getOwnerId()) == notOwner) - return notFilter; - - if (expansionSetCode.size() > 0 && expansionSetCode.contains(card.getExpansionSetCode()) == notExpansionSetCode) - return notFilter; - - if (text.length() > 0) { - // first check in card name - boolean filterOut = !card.getName().toLowerCase().contains(text.toLowerCase()); - // if couldn't find - if (filterOut) { - //separate by spaces - String[] tokens = text.toLowerCase().split(" "); - int count = 0; - int found = 0; - for (String token : tokens) { - if (!token.isEmpty()) { - count++; - // then try to find in rules - for (String rule : card.getRules()) { - if (rule.toLowerCase().contains(token)) { - found++; - break; - } - } - - if (filterOut) { - for (String subType : card.getSubtype()) { - if (subType.equalsIgnoreCase(token)) { - found++; - break; - } - } - } - } - } - - if (found < count) - return notFilter; - } - - } - - return !notFilter; + this.extraPredicates = new ArrayList>>(filter.extraPredicates); } public boolean match(Card card, UUID playerId, Game game) { - if (!this.match(card, game)) - return notFilter; - - if (owner != TargetController.ANY && playerId != null) { - switch(owner) { - case YOU: - if (!card.getOwnerId().equals(playerId)) - return notFilter; - break; - case OPPONENT: - if (!game.getOpponents(playerId).contains(card.getOwnerId())) - return notFilter; - break; - case NOT_YOU: - if (card.getOwnerId().equals(playerId)) - return notFilter; - break; - } + if (!this.match(card, game)) { + return false; } - return !notFilter; + return Predicates.and(extraPredicates).apply(new ObjectPlayer(card, playerId), game); } - public List getOwnerId() { - return ownerId; - } - - public void setNotOwner(boolean notOwner) { - this.notOwner = notOwner; - } - - public List getExpansionSetCode() { - return expansionSetCode; - } - - public void setNotExpansionSetCode(boolean notExpansionSetCode) { - this.notExpansionSetCode = notExpansionSetCode; - } - - public void setText(String text) { - this.text = text; - } - - public void setTargetOwner(TargetController owner) { - this.owner = owner; - } - - public boolean matchOwner(UUID testOwnerId) { - if (ownerId.size() > 0 && ownerId.contains(testOwnerId) == notOwner) - return false; - return true; + public void add(ObjectPlayerPredicate predicate) { + extraPredicates.add(predicate); } public Set filter(Set cards, Game game) { Set filtered = new HashSet(); - for (Card card: cards) { + for (Card card : cards) { if (match(card, game)) { filtered.add(card); } diff --git a/Mage/src/mage/filter/FilterImpl.java b/Mage/src/mage/filter/FilterImpl.java index 55741ac702..8eec629efa 100644 --- a/Mage/src/mage/filter/FilterImpl.java +++ b/Mage/src/mage/filter/FilterImpl.java @@ -43,7 +43,6 @@ public abstract class FilterImpl implements Filter { protected List> predicates = new ArrayList>(); protected String message; - protected boolean notFilter = false; @Override public abstract FilterImpl copy(); @@ -54,7 +53,6 @@ public abstract class FilterImpl implements Filter { public FilterImpl(FilterImpl filter) { this.message = filter.message; - this.notFilter = filter.notFilter; this.predicates = new ArrayList>(filter.predicates); } @@ -77,9 +75,4 @@ public abstract class FilterImpl implements Filter { public void setMessage(String message) { this.message = message; } - - public void setNotFilter(boolean notFilter) { - this.notFilter = notFilter; - } - } diff --git a/Mage/src/mage/filter/predicate/other/CardTextPredicate.java b/Mage/src/mage/filter/predicate/other/CardTextPredicate.java new file mode 100644 index 0000000000..f36cfacac9 --- /dev/null +++ b/Mage/src/mage/filter/predicate/other/CardTextPredicate.java @@ -0,0 +1,88 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ +package mage.filter.predicate.other; + +import mage.cards.Card; +import mage.filter.predicate.Predicate; +import mage.game.Game; + +/** + * + * @author North + */ +public class CardTextPredicate implements Predicate { + + private final String text; + + public CardTextPredicate(String text) { + this.text = text; + } + + @Override + public boolean apply(Card input, Game game) { + if (text.isEmpty()) { + return true; + } + // first check in card name + if (input.getName().toLowerCase().contains(text.toLowerCase())) { + return true; + } + + //separate by spaces + String[] tokens = text.toLowerCase().split(" "); + for (String token : tokens) { + boolean found = false; + if (!token.isEmpty()) { + // then try to find in rules + for (String rule : input.getRules()) { + if (rule.toLowerCase().contains(token)) { + found = true; + break; + } + } + + for (String subType : input.getSubtype()) { + if (subType.equalsIgnoreCase(token)) { + found = true; + break; + } + } + } + if (!found) { + return false; + } + } + + return true; + } + + @Override + public String toString() { + return "CardText(" + text + ')'; + } +} diff --git a/Mage/src/mage/filter/predicate/other/ExpansionSetPredicate.java b/Mage/src/mage/filter/predicate/other/ExpansionSetPredicate.java new file mode 100644 index 0000000000..fc0cd1d832 --- /dev/null +++ b/Mage/src/mage/filter/predicate/other/ExpansionSetPredicate.java @@ -0,0 +1,55 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ +package mage.filter.predicate.other; + +import mage.cards.Card; +import mage.filter.predicate.Predicate; +import mage.game.Game; + +/** + * + * @author North + */ +public class ExpansionSetPredicate implements Predicate { + + private final String setCode; + + public ExpansionSetPredicate(String setCode) { + this.setCode = setCode; + } + + @Override + public boolean apply(Card input, Game game) { + return input.getExpansionSetCode().equals(setCode); + } + + @Override + public String toString() { + return "ExpansionSet(" + setCode + ')'; + } +} diff --git a/Mage/src/mage/filter/predicate/other/OwnerIdPredicate.java b/Mage/src/mage/filter/predicate/other/OwnerIdPredicate.java new file mode 100644 index 0000000000..c74677b1cc --- /dev/null +++ b/Mage/src/mage/filter/predicate/other/OwnerIdPredicate.java @@ -0,0 +1,56 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ +package mage.filter.predicate.other; + +import java.util.UUID; +import mage.cards.Card; +import mage.filter.predicate.Predicate; +import mage.game.Game; + +/** + * + * @author North + */ +public class OwnerIdPredicate implements Predicate { + + private final UUID ownerId; + + public OwnerIdPredicate(UUID ownerId) { + this.ownerId = ownerId; + } + + @Override + public boolean apply(Card input, Game game) { + return ownerId.equals(input.getOwnerId()); + } + + @Override + public String toString() { + return "OwnerId(" + ownerId + ')'; + } +} diff --git a/Mage/src/mage/filter/predicate/other/OwnerPredicate.java b/Mage/src/mage/filter/predicate/other/OwnerPredicate.java new file mode 100644 index 0000000000..4b600024b4 --- /dev/null +++ b/Mage/src/mage/filter/predicate/other/OwnerPredicate.java @@ -0,0 +1,82 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ +package mage.filter.predicate.other; + +import java.util.UUID; +import mage.Constants.TargetController; +import mage.cards.Card; +import mage.filter.predicate.ObjectPlayer; +import mage.filter.predicate.ObjectPlayerPredicate; +import mage.game.Game; + +/** + * + * @author North + */ +public class OwnerPredicate implements ObjectPlayerPredicate> { + + private TargetController targetOwner; + + public OwnerPredicate(TargetController targetOwner) { + this.targetOwner = targetOwner; + } + + @Override + public boolean apply(ObjectPlayer input, Game game) { + Card card = input.getObject(); + UUID playerId = input.getPlayerId(); + if (card == null || playerId == null) { + return false; + } + + switch (targetOwner) { + case YOU: + if (card.getOwnerId().equals(playerId)) { + return true; + } + break; + case OPPONENT: + if (game.getOpponents(playerId).contains(card.getOwnerId())) { + return true; + } + break; + case NOT_YOU: + if (!card.getOwnerId().equals(playerId)) { + return true; + } + break; + } + + return false; + } + + @Override + public String toString() { + return "Owner(" + targetOwner + ')'; + } +} diff --git a/Mage/src/mage/target/TargetCard.java b/Mage/src/mage/target/TargetCard.java index 240255ffe5..fe90954786 100644 --- a/Mage/src/mage/target/TargetCard.java +++ b/Mage/src/mage/target/TargetCard.java @@ -100,27 +100,29 @@ public class TargetCard> extends TargetObject= this.minNumberOfTargets) - return true; - break; - case GRAVEYARD: - 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; - } + Player player = game.getPlayer(playerId); + if (player != null) { + switch (zone) { + case HAND: + if (player.getHand().count(filter, player.getId(), game) >= this.minNumberOfTargets) { + return true; + } + break; + case GRAVEYARD: + 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; } } } @@ -143,34 +145,34 @@ public class TargetCard> extends TargetObject possibleTargets(UUID sourceControllerId, Game game) { Set possibleTargets = new HashSet(); - for (UUID playerId: game.getPlayer(sourceControllerId).getInRange()) { - if (filter.matchOwner(playerId)) { - Player player = game.getPlayer(playerId); - if (player != null) { - switch (zone) { - case HAND: - for (Card card: player.getHand().getCards(filter, game)) { + for (UUID playerId : game.getPlayer(sourceControllerId).getInRange()) { + Player player = game.getPlayer(playerId); + if (player != null) { + switch (zone) { + case HAND: + for (Card card : player.getHand().getCards(filter, game)) { + possibleTargets.add(card.getId()); + } + break; + case GRAVEYARD: + for (Card card : player.getGraveyard().getCards(filter, game)) { + possibleTargets.add(card.getId()); + } + break; + case LIBRARY: + for (Card card : player.getLibrary().getUniqueCards(game)) { + if (filter.match(card, game)) { possibleTargets.add(card.getId()); } - break; - case GRAVEYARD: - for (Card card: player.getGraveyard().getCards(filter, game)) { + } + break; + case EXILED: + for (Card card : game.getExile().getPermanentExile().getUniqueCards(game)) { + if (filter.match(card, player.getId(), game)) { possibleTargets.add(card.getId()); } - break; - case LIBRARY: - for (Card card: player.getLibrary().getUniqueCards(game)) { - if (filter.match(card, game)) - possibleTargets.add(card.getId()); - } - break; - case EXILED: - for (Card card: game.getExile().getPermanentExile().getUniqueCards(game)) { - if (filter.match(card, player.getId(), game)) - possibleTargets.add(card.getId()); - } - break; - } + } + break; } } } @@ -179,8 +181,9 @@ public class TargetCard> extends TargetObject { @Override public boolean canTarget(UUID id, Ability source, Game game) { Card card = game.getPlayer(source.getControllerId()).getHand().get(id, game); - if (card != null) - return filter.match(card, game); + if (card != null) { + return filter.match(card, source.getControllerId(), game); + } return false; } diff --git a/Mage/src/mage/target/common/TargetDiscard.java b/Mage/src/mage/target/common/TargetDiscard.java index fa08d1ace1..6d449edb5c 100644 --- a/Mage/src/mage/target/common/TargetDiscard.java +++ b/Mage/src/mage/target/common/TargetDiscard.java @@ -36,6 +36,7 @@ import mage.game.Game; import mage.target.TargetCard; import java.util.UUID; +import mage.filter.predicate.other.OwnerIdPredicate; /** * @@ -59,7 +60,7 @@ public class TargetDiscard extends TargetCard { public TargetDiscard(int minNumTargets, int maxNumTargets, FilterCard filter, UUID playerId) { super(minNumTargets, maxNumTargets, Zone.HAND, filter); - this.filter.getOwnerId().add(playerId); + this.filter.add(new OwnerIdPredicate(playerId)); this.playerId = playerId; this.required = true; this.targetName = "card to discard"; @@ -73,8 +74,9 @@ public class TargetDiscard extends TargetCard { @Override public boolean canTarget(UUID id, Ability source, Game game) { Card card = game.getPlayer(playerId).getHand().get(id, game); - if (card != null) - return filter.match(card, game); + if (card != null) { + return filter.match(card, source.getControllerId(), game); + } return false; }