mirror of
https://github.com/correl/mage.git
synced 2024-12-24 11:50:45 +00:00
[filters] converted FilterCard conditions to Predicates
This commit is contained in:
parent
c2c04e6a56
commit
1542ba9ab6
13 changed files with 410 additions and 215 deletions
|
@ -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<Predicate<Card>> expansionPredicates = new ArrayList<Predicate<Card>>();
|
||||
for (String setCode : ConstructedFormats.getSetsByFormat("Standard")) {
|
||||
expansionPredicates.add(new ExpansionSetPredicate(setCode));
|
||||
}
|
||||
filter.add(Predicates.or(expansionPredicates));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -228,16 +234,18 @@ 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);
|
||||
this.cardCount.setText(String.valueOf(filteredCards.size()));
|
||||
}
|
||||
|
|
|
@ -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<Predicate<Card>> expansionPredicates = new ArrayList<Predicate<Card>>();
|
||||
for(String setCode : ConstructedFormats.getSetsByFormat("Standard")) {
|
||||
expansionPredicates.add(new ExpansionSetPredicate(setCode));
|
||||
}
|
||||
filter.add(Predicates.or(expansionPredicates));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<MyojinOfLifesWeb> {
|
|||
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<MyojinOfLifesWeb> {
|
|||
// 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()));
|
||||
|
|
|
@ -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<RunicRepetition> {
|
|||
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));
|
||||
}
|
||||
|
||||
|
|
|
@ -25,34 +25,29 @@
|
|||
* 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<Card> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
protected List<UUID> ownerId = new ArrayList<UUID>();
|
||||
protected boolean notOwner;
|
||||
protected List<String> expansionSetCode = new ArrayList<String>();
|
||||
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<ObjectPlayerPredicate<ObjectPlayer<Permanent>>> extraPredicates = new ArrayList<ObjectPlayerPredicate<ObjectPlayer<Permanent>>>();
|
||||
|
||||
public FilterCard() {
|
||||
super("card");
|
||||
|
@ -64,116 +59,19 @@ public class FilterCard extends FilterObject<Card> {
|
|||
|
||||
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<ObjectPlayerPredicate<ObjectPlayer<Permanent>>>(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;
|
||||
}
|
||||
}
|
||||
|
||||
return !notFilter;
|
||||
}
|
||||
|
||||
public List<UUID> getOwnerId() {
|
||||
return ownerId;
|
||||
}
|
||||
|
||||
public void setNotOwner(boolean notOwner) {
|
||||
this.notOwner = notOwner;
|
||||
}
|
||||
|
||||
public List<String> 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)
|
||||
if (!this.match(card, game)) {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
return Predicates.and(extraPredicates).apply(new ObjectPlayer(card, playerId), game);
|
||||
}
|
||||
|
||||
public void add(ObjectPlayerPredicate predicate) {
|
||||
extraPredicates.add(predicate);
|
||||
}
|
||||
|
||||
public Set<Card> filter(Set<Card> cards, Game game) {
|
||||
|
|
|
@ -43,7 +43,6 @@ public abstract class FilterImpl<E> implements Filter<E> {
|
|||
|
||||
protected List<Predicate<Object>> predicates = new ArrayList<Predicate<Object>>();
|
||||
protected String message;
|
||||
protected boolean notFilter = false;
|
||||
|
||||
@Override
|
||||
public abstract FilterImpl<E> copy();
|
||||
|
@ -54,7 +53,6 @@ public abstract class FilterImpl<E> implements Filter<E> {
|
|||
|
||||
public FilterImpl(FilterImpl filter) {
|
||||
this.message = filter.message;
|
||||
this.notFilter = filter.notFilter;
|
||||
this.predicates = new ArrayList<Predicate<Object>>(filter.predicates);
|
||||
}
|
||||
|
||||
|
@ -77,9 +75,4 @@ public abstract class FilterImpl<E> implements Filter<E> {
|
|||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public void setNotFilter(boolean notFilter) {
|
||||
this.notFilter = notFilter;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
88
Mage/src/mage/filter/predicate/other/CardTextPredicate.java
Normal file
88
Mage/src/mage/filter/predicate/other/CardTextPredicate.java
Normal file
|
@ -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<Card> {
|
||||
|
||||
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 + ')';
|
||||
}
|
||||
}
|
|
@ -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<Card> {
|
||||
|
||||
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 + ')';
|
||||
}
|
||||
}
|
56
Mage/src/mage/filter/predicate/other/OwnerIdPredicate.java
Normal file
56
Mage/src/mage/filter/predicate/other/OwnerIdPredicate.java
Normal file
|
@ -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<Card> {
|
||||
|
||||
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 + ')';
|
||||
}
|
||||
}
|
82
Mage/src/mage/filter/predicate/other/OwnerPredicate.java
Normal file
82
Mage/src/mage/filter/predicate/other/OwnerPredicate.java
Normal file
|
@ -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<ObjectPlayer<Card>> {
|
||||
|
||||
private TargetController targetOwner;
|
||||
|
||||
public OwnerPredicate(TargetController targetOwner) {
|
||||
this.targetOwner = targetOwner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(ObjectPlayer<Card> 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 + ')';
|
||||
}
|
||||
}
|
|
@ -100,27 +100,29 @@ public class TargetCard<T extends TargetCard<T>> extends TargetObject<TargetCard
|
|||
@Override
|
||||
public boolean canChoose(UUID sourceControllerId, Game game) {
|
||||
for (UUID playerId: game.getPlayer(sourceControllerId).getInRange()) {
|
||||
if (filter.matchOwner(playerId)) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player != null) {
|
||||
switch (zone) {
|
||||
case HAND:
|
||||
if (player.getHand().count(filter, player.getId(), game) >= this.minNumberOfTargets)
|
||||
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)
|
||||
if (player.getGraveyard().count(filter, player.getId(), game) >= this.minNumberOfTargets) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case LIBRARY:
|
||||
if (player.getLibrary().count(filter, game) >= this.minNumberOfTargets)
|
||||
if (player.getLibrary().count(filter, game) >= this.minNumberOfTargets) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case EXILED:
|
||||
if (game.getExile().getPermanentExile().count(filter, player.getId(), game) >= this.minNumberOfTargets)
|
||||
if (game.getExile().getPermanentExile().count(filter, player.getId(), game) >= this.minNumberOfTargets) {
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -144,7 +146,6 @@ public class TargetCard<T extends TargetCard<T>> extends TargetObject<TargetCard
|
|||
public Set<UUID> possibleTargets(UUID sourceControllerId, Game game) {
|
||||
Set<UUID> possibleTargets = new HashSet<UUID>();
|
||||
for (UUID playerId : game.getPlayer(sourceControllerId).getInRange()) {
|
||||
if (filter.matchOwner(playerId)) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player != null) {
|
||||
switch (zone) {
|
||||
|
@ -160,17 +161,18 @@ public class TargetCard<T extends TargetCard<T>> extends TargetObject<TargetCard
|
|||
break;
|
||||
case LIBRARY:
|
||||
for (Card card : player.getLibrary().getUniqueCards(game)) {
|
||||
if (filter.match(card, 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))
|
||||
if (filter.match(card, player.getId(), game)) {
|
||||
possibleTargets.add(card.getId());
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -179,8 +181,9 @@ public class TargetCard<T extends TargetCard<T>> extends TargetObject<TargetCard
|
|||
|
||||
public boolean canTarget(UUID id, Cards cards, Game game) {
|
||||
Card card = cards.get(id, game);
|
||||
if (card != null)
|
||||
if (card != null) {
|
||||
return filter.match(card, game);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -66,8 +66,9 @@ public class TargetCardInHand extends TargetCard<TargetCardInHand> {
|
|||
@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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<TargetDiscard> {
|
|||
|
||||
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<TargetDiscard> {
|
|||
@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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue