mirror of
https://github.com/correl/mage.git
synced 2024-11-15 19:19:33 +00:00
[filters] Added support for Predicates with sourceId and PlayerId
This commit is contained in:
parent
faa106b3c3
commit
cd37b8c3ba
7 changed files with 201 additions and 17 deletions
|
@ -31,6 +31,7 @@ package mage.filter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import mage.filter.predicate.Predicate;
|
import mage.filter.predicate.Predicate;
|
||||||
|
import mage.filter.predicate.Predicates;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -40,7 +41,7 @@ import mage.game.Game;
|
||||||
*/
|
*/
|
||||||
public abstract class FilterImpl<E> implements Filter<E> {
|
public abstract class FilterImpl<E> implements Filter<E> {
|
||||||
|
|
||||||
protected List<Predicate> predicates = new ArrayList<Predicate>();
|
protected List<Predicate<Object>> predicates = new ArrayList<Predicate<Object>>();
|
||||||
protected String message;
|
protected String message;
|
||||||
protected boolean notFilter = false;
|
protected boolean notFilter = false;
|
||||||
|
|
||||||
|
@ -54,17 +55,12 @@ public abstract class FilterImpl<E> implements Filter<E> {
|
||||||
public FilterImpl(FilterImpl filter) {
|
public FilterImpl(FilterImpl filter) {
|
||||||
this.message = filter.message;
|
this.message = filter.message;
|
||||||
this.notFilter = filter.notFilter;
|
this.notFilter = filter.notFilter;
|
||||||
this.predicates = new ArrayList<Predicate>(filter.predicates);
|
this.predicates = new ArrayList<Predicate<Object>>(filter.predicates);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean match(E e, Game game) {
|
public boolean match(E e, Game game) {
|
||||||
for (int i = 0; i < predicates.size(); i++) {
|
return Predicates.and(predicates).apply(e, game);
|
||||||
if (!predicates.get(i).apply(e, game)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -28,19 +28,22 @@
|
||||||
|
|
||||||
package mage.filter;
|
package mage.filter;
|
||||||
|
|
||||||
import mage.Constants.TargetController;
|
|
||||||
import mage.game.Game;
|
|
||||||
import mage.game.permanent.Permanent;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import mage.Constants.TargetController;
|
||||||
|
import mage.filter.predicate.ObjectSourcePlayer;
|
||||||
|
import mage.filter.predicate.ObjectSourcePlayerPredicate;
|
||||||
|
import mage.filter.predicate.Predicates;
|
||||||
|
import mage.game.Game;
|
||||||
|
import mage.game.permanent.Permanent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
*/
|
*/
|
||||||
public class FilterPermanent extends FilterObject<Permanent> {
|
public class FilterPermanent extends FilterObject<Permanent> {
|
||||||
|
protected List<ObjectSourcePlayerPredicate<ObjectSourcePlayer<Permanent>>> extraPredicates = new ArrayList<ObjectSourcePlayerPredicate<ObjectSourcePlayer<Permanent>>>();
|
||||||
protected List<UUID> controllerId = new ArrayList<UUID>();
|
protected List<UUID> controllerId = new ArrayList<UUID>();
|
||||||
protected boolean notController;
|
protected boolean notController;
|
||||||
protected TargetController controller = TargetController.ANY;
|
protected TargetController controller = TargetController.ANY;
|
||||||
|
@ -58,6 +61,7 @@ public class FilterPermanent extends FilterObject<Permanent> {
|
||||||
this.controller = filter.controller;
|
this.controller = filter.controller;
|
||||||
this.owner = filter.owner;
|
this.owner = filter.owner;
|
||||||
this.another = filter.another;
|
this.another = filter.another;
|
||||||
|
this.extraPredicates = new ArrayList<ObjectSourcePlayerPredicate<ObjectSourcePlayer<Permanent>>>(extraPredicates);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FilterPermanent(String name) {
|
public FilterPermanent(String name) {
|
||||||
|
@ -120,7 +124,11 @@ public class FilterPermanent extends FilterObject<Permanent> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return !notFilter;
|
return Predicates.and(extraPredicates).apply(new ObjectSourcePlayer(permanent, sourceId, playerId), game);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(ObjectSourcePlayerPredicate predicate) {
|
||||||
|
extraPredicates.add(predicate);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<UUID> getControllerId() {
|
public List<UUID> getControllerId() {
|
||||||
|
|
|
@ -28,20 +28,24 @@
|
||||||
|
|
||||||
package mage.filter;
|
package mage.filter;
|
||||||
|
|
||||||
import mage.Constants.TargetController;
|
|
||||||
import mage.game.Game;
|
|
||||||
import mage.game.stack.StackObject;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import mage.Constants.TargetController;
|
||||||
|
import mage.filter.predicate.ObjectPlayer;
|
||||||
|
import mage.filter.predicate.ObjectPlayerPredicate;
|
||||||
|
import mage.game.Game;
|
||||||
|
import mage.game.permanent.Permanent;
|
||||||
|
import mage.game.stack.StackObject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
|
* @author North
|
||||||
*/
|
*/
|
||||||
public class FilterStackObject extends FilterObject<StackObject> {
|
public class FilterStackObject extends FilterObject<StackObject> {
|
||||||
|
|
||||||
|
protected List<ObjectPlayerPredicate<ObjectPlayer<Permanent>>> extraPredicates = new ArrayList<ObjectPlayerPredicate<ObjectPlayer<Permanent>>>();
|
||||||
protected List<UUID> controllerId = new ArrayList<UUID>();
|
protected List<UUID> controllerId = new ArrayList<UUID>();
|
||||||
protected boolean notController = false;
|
protected boolean notController = false;
|
||||||
protected TargetController controller = TargetController.ANY;
|
protected TargetController controller = TargetController.ANY;
|
||||||
|
@ -59,6 +63,7 @@ public class FilterStackObject extends FilterObject<StackObject> {
|
||||||
this.controllerId.addAll(filter.controllerId);
|
this.controllerId.addAll(filter.controllerId);
|
||||||
this.notController = filter.notController;
|
this.notController = filter.notController;
|
||||||
this.controller = filter.controller;
|
this.controller = filter.controller;
|
||||||
|
this.extraPredicates = new ArrayList<ObjectPlayerPredicate<ObjectPlayer<Permanent>>>(extraPredicates);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -97,6 +102,10 @@ public class FilterStackObject extends FilterObject<StackObject> {
|
||||||
return !notFilter;
|
return !notFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void add(ObjectPlayerPredicate predicate) {
|
||||||
|
extraPredicates.add(predicate);
|
||||||
|
}
|
||||||
|
|
||||||
public List<UUID> getControllerId() {
|
public List<UUID> getControllerId() {
|
||||||
return controllerId;
|
return controllerId;
|
||||||
}
|
}
|
||||||
|
|
53
Mage/src/mage/filter/predicate/ObjectPlayer.java
Normal file
53
Mage/src/mage/filter/predicate/ObjectPlayer.java
Normal file
|
@ -0,0 +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.
|
||||||
|
*/
|
||||||
|
package mage.filter.predicate;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author North
|
||||||
|
*/
|
||||||
|
public class ObjectPlayer<T> {
|
||||||
|
|
||||||
|
protected T object;
|
||||||
|
protected UUID playerId;
|
||||||
|
|
||||||
|
public ObjectPlayer(T object, UUID playerId) {
|
||||||
|
this.object = object;
|
||||||
|
this.playerId = playerId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T getObject() {
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getPlayerId() {
|
||||||
|
return playerId;
|
||||||
|
}
|
||||||
|
}
|
35
Mage/src/mage/filter/predicate/ObjectPlayerPredicate.java
Normal file
35
Mage/src/mage/filter/predicate/ObjectPlayerPredicate.java
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author North
|
||||||
|
*/
|
||||||
|
public interface ObjectPlayerPredicate<T extends ObjectPlayer> extends Predicate<T> {
|
||||||
|
}
|
48
Mage/src/mage/filter/predicate/ObjectSourcePlayer.java
Normal file
48
Mage/src/mage/filter/predicate/ObjectSourcePlayer.java
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author North
|
||||||
|
*/
|
||||||
|
public class ObjectSourcePlayer<T> extends ObjectPlayer<T> {
|
||||||
|
|
||||||
|
protected UUID sourceId;
|
||||||
|
|
||||||
|
public ObjectSourcePlayer(T object, UUID sourceId, UUID playerId) {
|
||||||
|
super(object, playerId);
|
||||||
|
this.sourceId = sourceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getSourceId() {
|
||||||
|
return sourceId;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author North
|
||||||
|
*/
|
||||||
|
public interface ObjectSourcePlayerPredicate<T extends ObjectSourcePlayer> extends Predicate<T> {
|
||||||
|
}
|
Loading…
Reference in a new issue