diff --git a/Mage/src/mage/filter/FilterImpl.java b/Mage/src/mage/filter/FilterImpl.java index e243e0bb0fa..55741ac7028 100644 --- a/Mage/src/mage/filter/FilterImpl.java +++ b/Mage/src/mage/filter/FilterImpl.java @@ -31,6 +31,7 @@ package mage.filter; import java.util.ArrayList; import java.util.List; import mage.filter.predicate.Predicate; +import mage.filter.predicate.Predicates; import mage.game.Game; /** @@ -40,7 +41,7 @@ import mage.game.Game; */ public abstract class FilterImpl implements Filter { - protected List predicates = new ArrayList(); + protected List> predicates = new ArrayList>(); protected String message; protected boolean notFilter = false; @@ -54,17 +55,12 @@ public abstract class FilterImpl implements Filter { public FilterImpl(FilterImpl filter) { this.message = filter.message; this.notFilter = filter.notFilter; - this.predicates = new ArrayList(filter.predicates); + this.predicates = new ArrayList>(filter.predicates); } @Override public boolean match(E e, Game game) { - for (int i = 0; i < predicates.size(); i++) { - if (!predicates.get(i).apply(e, game)) { - return false; - } - } - return true; + return Predicates.and(predicates).apply(e, game); } @Override diff --git a/Mage/src/mage/filter/FilterPermanent.java b/Mage/src/mage/filter/FilterPermanent.java index f878d050833..343e246d8fe 100644 --- a/Mage/src/mage/filter/FilterPermanent.java +++ b/Mage/src/mage/filter/FilterPermanent.java @@ -28,19 +28,22 @@ package mage.filter; -import mage.Constants.TargetController; -import mage.game.Game; -import mage.game.permanent.Permanent; - import java.util.ArrayList; import java.util.List; 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 */ public class FilterPermanent extends FilterObject { + protected List>> extraPredicates = new ArrayList>>(); protected List controllerId = new ArrayList(); protected boolean notController; protected TargetController controller = TargetController.ANY; @@ -58,6 +61,7 @@ public class FilterPermanent extends FilterObject { this.controller = filter.controller; this.owner = filter.owner; this.another = filter.another; + this.extraPredicates = new ArrayList>>(extraPredicates); } public FilterPermanent(String name) { @@ -120,7 +124,11 @@ public class FilterPermanent extends FilterObject { } } - return !notFilter; + return Predicates.and(extraPredicates).apply(new ObjectSourcePlayer(permanent, sourceId, playerId), game); + } + + public void add(ObjectSourcePlayerPredicate predicate) { + extraPredicates.add(predicate); } public List getControllerId() { diff --git a/Mage/src/mage/filter/FilterStackObject.java b/Mage/src/mage/filter/FilterStackObject.java index d96ac3e6e8b..1a9b80b18f2 100644 --- a/Mage/src/mage/filter/FilterStackObject.java +++ b/Mage/src/mage/filter/FilterStackObject.java @@ -28,20 +28,24 @@ package mage.filter; -import mage.Constants.TargetController; -import mage.game.Game; -import mage.game.stack.StackObject; - import java.util.ArrayList; import java.util.List; 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 North */ public class FilterStackObject extends FilterObject { + protected List>> extraPredicates = new ArrayList>>(); protected List controllerId = new ArrayList(); protected boolean notController = false; protected TargetController controller = TargetController.ANY; @@ -59,6 +63,7 @@ public class FilterStackObject extends FilterObject { this.controllerId.addAll(filter.controllerId); this.notController = filter.notController; this.controller = filter.controller; + this.extraPredicates = new ArrayList>>(extraPredicates); } @Override @@ -97,6 +102,10 @@ public class FilterStackObject extends FilterObject { return !notFilter; } + public void add(ObjectPlayerPredicate predicate) { + extraPredicates.add(predicate); + } + public List getControllerId() { return controllerId; } diff --git a/Mage/src/mage/filter/predicate/ObjectPlayer.java b/Mage/src/mage/filter/predicate/ObjectPlayer.java new file mode 100644 index 00000000000..7cb609a331c --- /dev/null +++ b/Mage/src/mage/filter/predicate/ObjectPlayer.java @@ -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 { + + 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; + } +} diff --git a/Mage/src/mage/filter/predicate/ObjectPlayerPredicate.java b/Mage/src/mage/filter/predicate/ObjectPlayerPredicate.java new file mode 100644 index 00000000000..5fddeed0138 --- /dev/null +++ b/Mage/src/mage/filter/predicate/ObjectPlayerPredicate.java @@ -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 extends Predicate { +} diff --git a/Mage/src/mage/filter/predicate/ObjectSourcePlayer.java b/Mage/src/mage/filter/predicate/ObjectSourcePlayer.java new file mode 100644 index 00000000000..2a7493da431 --- /dev/null +++ b/Mage/src/mage/filter/predicate/ObjectSourcePlayer.java @@ -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 extends ObjectPlayer { + + protected UUID sourceId; + + public ObjectSourcePlayer(T object, UUID sourceId, UUID playerId) { + super(object, playerId); + this.sourceId = sourceId; + } + + public UUID getSourceId() { + return sourceId; + } +} diff --git a/Mage/src/mage/filter/predicate/ObjectSourcePlayerPredicate.java b/Mage/src/mage/filter/predicate/ObjectSourcePlayerPredicate.java new file mode 100644 index 00000000000..32e7a771547 --- /dev/null +++ b/Mage/src/mage/filter/predicate/ObjectSourcePlayerPredicate.java @@ -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 extends Predicate { +}