[filters] Replaced Another condition with Predicate

This commit is contained in:
North 2012-07-15 17:18:33 +03:00
parent d66c172952
commit 021e2b59df
22 changed files with 100 additions and 49 deletions

View file

@ -48,7 +48,6 @@ public class FilterPermanent extends FilterObject<Permanent> {
protected boolean notController;
protected TargetController controller = TargetController.ANY;
protected TargetController owner = TargetController.ANY;
protected boolean another;
public FilterPermanent() {
super("permanent");
@ -60,7 +59,6 @@ public class FilterPermanent extends FilterObject<Permanent> {
this.notController = filter.notController;
this.controller = filter.controller;
this.owner = filter.owner;
this.another = filter.another;
this.extraPredicates = new ArrayList<ObjectSourcePlayerPredicate<ObjectSourcePlayer<Permanent>>>(extraPredicates);
}
@ -117,13 +115,6 @@ public class FilterPermanent extends FilterObject<Permanent> {
}
}
if (another) {
// filter out itself
if (permanent.getId().equals(sourceId)) {
return notFilter;
}
}
return Predicates.and(extraPredicates).apply(new ObjectSourcePlayer(permanent, sourceId, playerId), game);
}
@ -147,14 +138,6 @@ public class FilterPermanent extends FilterObject<Permanent> {
this.owner = owner;
}
public boolean isAnother() {
return another;
}
public void setAnother(boolean another) {
this.another = another;
}
public boolean matchController(UUID testControllerId) {
if (controllerId.size() > 0 && controllerId.contains(testControllerId) == notController)
return false;

View file

@ -0,0 +1,50 @@
/*
* 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.permanent;
import mage.filter.predicate.ObjectSourcePlayer;
import mage.filter.predicate.ObjectSourcePlayerPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
/**
*
* @author North
*/
public class AnotherPredicate implements ObjectSourcePlayerPredicate<ObjectSourcePlayer<Permanent>> {
@Override
public boolean apply(ObjectSourcePlayer<Permanent> input, Game game) {
return !input.getObject().getId().equals(input.getSourceId());
}
@Override
public String toString() {
return "Another";
}
}

View file

@ -34,6 +34,7 @@ import mage.abilities.keyword.SoulbondAbility;
import mage.cards.Cards;
import mage.cards.CardsImpl;
import mage.filter.common.FilterNotPairedControlledCreaturePermanent;
import mage.filter.predicate.permanent.AnotherPredicate;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent;
@ -49,10 +50,10 @@ import mage.watchers.WatcherImpl;
*/
public class SoulbondWatcher extends WatcherImpl<SoulbondWatcher> {
private static FilterNotPairedControlledCreaturePermanent filter = new FilterNotPairedControlledCreaturePermanent("another not paired creature you control");
private static final FilterNotPairedControlledCreaturePermanent filter = new FilterNotPairedControlledCreaturePermanent("another not paired creature you control");
static {
filter.setAnother(true);
filter.add(new AnotherPredicate());
}
public SoulbondWatcher() {