refactored ControllerPredicate

This commit is contained in:
Evan Kranzler 2020-01-06 20:04:56 -05:00
parent c14a079cc5
commit 9c3b923b3f
783 changed files with 829 additions and 1689 deletions

View file

@ -7,7 +7,6 @@ import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
import mage.constants.TargetController;
import mage.filter.FilterPermanent;
import mage.filter.predicate.permanent.ControllerPredicate;
import mage.filter.predicate.permanent.TokenPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
@ -35,7 +34,7 @@ public class PopulateEffect extends OneShotEffect {
static {
filter.add(TokenPredicate.instance);
filter.add(new ControllerPredicate(TargetController.YOU));
filter.add(TargetController.YOU.getControllerPredicate());
}
public PopulateEffect() {

View file

@ -10,7 +10,6 @@ import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
import mage.constants.TargetController;
import mage.filter.FilterPermanent;
import mage.filter.predicate.permanent.ControllerPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
@ -39,7 +38,7 @@ public class SacrificeOpponentsEffect extends OneShotEffect {
super(Outcome.Sacrifice);
this.amount = amount;
this.filter = filter.copy();
this.filter.add(new ControllerPredicate(TargetController.YOU));
this.filter.add(TargetController.YOU.getControllerPredicate());
setText();
}

View file

@ -10,7 +10,6 @@ import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
import mage.constants.TargetController;
import mage.filter.FilterPermanent;
import mage.filter.predicate.permanent.ControllerPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
@ -99,7 +98,7 @@ public class SacrificeOpponentsUnlessPayEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
List<UUID> permsToSacrifice = new ArrayList<>();
filter.add(new ControllerPredicate(TargetController.YOU));
filter.add(TargetController.YOU.getControllerPredicate());
for (UUID playerId : game.getOpponents(source.getControllerId())) {
Player player = game.getPlayer(playerId);

View file

@ -10,7 +10,6 @@ import mage.abilities.effects.Effect;
import mage.constants.TargetController;
import mage.counters.CounterType;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.permanent.ControllerPredicate;
import mage.filter.predicate.permanent.CounterPredicate;
/**
@ -22,7 +21,7 @@ public class BountyAbility extends DiesCreatureTriggeredAbility {
private static final FilterCreaturePermanent bountyCounterFilter = new FilterCreaturePermanent("creature an opponent controls with a bounty counter on it");
static {
bountyCounterFilter.add(new ControllerPredicate(TargetController.OPPONENT));
bountyCounterFilter.add(TargetController.OPPONENT.getControllerPredicate());
bountyCounterFilter.add(new CounterPredicate(CounterType.BOUNTY));
}

View file

@ -15,7 +15,6 @@ import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.Predicate;
import mage.filter.predicate.Predicates;
import mage.filter.predicate.permanent.AnotherPredicate;
import mage.filter.predicate.permanent.ControllerPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
@ -172,7 +171,7 @@ class SoulbondEntersOtherAbility extends EntersBattlefieldAllTriggeredAbility {
static {
soulbondFilter.add(Predicates.not(new PairedPredicate()));
soulbondFilter.add(new ControllerPredicate(TargetController.YOU));
soulbondFilter.add(TargetController.YOU.getControllerPredicate());
soulbondFilter.add(AnotherPredicate.instance);
}

View file

@ -73,7 +73,7 @@ class AnyColorLandsProduceManaEffect extends ManaEffect {
this.filter = filter.copy();
}
this.onlyColors = onlyColors;
this.filter.add(new ControllerPredicate(targetController));
this.filter.add(targetController.getControllerPredicate());
String text = targetController == TargetController.OPPONENT ? "an opponent controls" : "you control";
staticText = "Add one mana of any " + (this.onlyColors ? "color" : "type") + " that a "
+ (filter == null ? "land " : filter.getMessage() + " ") + text + " could produce";

View file

@ -16,7 +16,6 @@ import mage.constants.ColoredManaSymbol;
import mage.constants.TargetController;
import mage.constants.Zone;
import mage.filter.FilterPermanent;
import mage.filter.predicate.permanent.ControllerPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
@ -69,7 +68,7 @@ class AnyColorPermanentTypesManaEffect extends ManaEffect {
super();
filter = permanentTypes;
this.onlyColors = onlyColors;
filter.add(new ControllerPredicate(targetController));
filter.add(targetController.getControllerPredicate());
String text = targetController == TargetController.OPPONENT ? "an opponent controls." : "you control.";
staticText = "Add one mana of any " + (this.onlyColors ? "color" : "type") + " among " + permanentTypes.getMessage() + " " + text;
}

View file

@ -36,7 +36,7 @@ public enum TargetController {
TargetController() {
this.ownerPredicate = this.getOwnerPredicate();
this.playerPredicate = new PlayerPredicate(this);
this.controllerPredicate = new ControllerPredicate(this);
this.controllerPredicate = this.getControllerPredicate();
this.damagedPlayerThisTurnPredicate = new DamagedPlayerThisTurnPredicate(this);
}

View file

@ -14,7 +14,6 @@ import mage.filter.predicate.Predicates;
import mage.filter.predicate.mageobject.MulticoloredPredicate;
import mage.filter.predicate.permanent.AnotherPredicate;
import mage.filter.predicate.permanent.AttackingPredicate;
import mage.filter.predicate.permanent.ControllerPredicate;
import mage.filter.predicate.permanent.TokenPredicate;
/**
@ -304,21 +303,21 @@ public final class StaticFilters {
public static final FilterPermanent FILTER_OPPONENTS_PERMANENT = new FilterPermanent("permanent an opponent controls");
static {
FILTER_OPPONENTS_PERMANENT.add(new ControllerPredicate(TargetController.OPPONENT));
FILTER_OPPONENTS_PERMANENT.add(TargetController.OPPONENT.getControllerPredicate());
FILTER_OPPONENTS_PERMANENT.setLockedFilter(true);
}
public static final FilterCreaturePermanent FILTER_OPPONENTS_PERMANENT_CREATURE = new FilterCreaturePermanent("creature an opponent controls");
static {
FILTER_OPPONENTS_PERMANENT_CREATURE.add(new ControllerPredicate(TargetController.OPPONENT));
FILTER_OPPONENTS_PERMANENT_CREATURE.add(TargetController.OPPONENT.getControllerPredicate());
FILTER_OPPONENTS_PERMANENT_CREATURE.setLockedFilter(true);
}
public static final FilterPermanent FILTER_OPPONENTS_PERMANENT_ARTIFACT = new FilterPermanent("artifact an opponent controls");
static {
FILTER_OPPONENTS_PERMANENT_ARTIFACT.add(new ControllerPredicate(TargetController.OPPONENT));
FILTER_OPPONENTS_PERMANENT_ARTIFACT.add(TargetController.OPPONENT.getControllerPredicate());
FILTER_OPPONENTS_PERMANENT_ARTIFACT.add(CardType.ARTIFACT.getPredicate());
FILTER_OPPONENTS_PERMANENT_ARTIFACT.setLockedFilter(true);
}
@ -326,7 +325,7 @@ public final class StaticFilters {
public static final FilterPermanent FILTER_OPPONENTS_PERMANENT_ARTIFACT_OR_CREATURE = new FilterPermanent("artifact or creature an opponent controls");
static {
FILTER_OPPONENTS_PERMANENT_ARTIFACT_OR_CREATURE.add(new ControllerPredicate(TargetController.OPPONENT));
FILTER_OPPONENTS_PERMANENT_ARTIFACT_OR_CREATURE.add(TargetController.OPPONENT.getControllerPredicate());
FILTER_OPPONENTS_PERMANENT_ARTIFACT_OR_CREATURE.add(Predicates.or(
CardType.ARTIFACT.getPredicate(),
CardType.CREATURE.getPredicate()
@ -435,7 +434,7 @@ public final class StaticFilters {
public static final FilterCreaturePermanent FILTER_PERMANENT_CREATURE_CONTROLLED = new FilterCreaturePermanent("creature you control");
static {
FILTER_PERMANENT_CREATURE_CONTROLLED.add(new ControllerPredicate(TargetController.YOU));
FILTER_PERMANENT_CREATURE_CONTROLLED.add(TargetController.YOU.getControllerPredicate());
FILTER_PERMANENT_CREATURE_CONTROLLED.setLockedFilter(true);
}
@ -448,7 +447,7 @@ public final class StaticFilters {
public static final FilterCreaturePermanent FILTER_PERMANENT_CREATURES_CONTROLLED = new FilterCreaturePermanent("creatures you control");
static {
FILTER_PERMANENT_CREATURES_CONTROLLED.add(new ControllerPredicate(TargetController.YOU));
FILTER_PERMANENT_CREATURES_CONTROLLED.add(TargetController.YOU.getControllerPredicate());
FILTER_PERMANENT_CREATURES_CONTROLLED.setLockedFilter(true);
}
@ -491,7 +490,7 @@ public final class StaticFilters {
public static final FilterStackObject FILTER_SPELL_OR_ABILITY_OPPONENTS = new FilterStackObject("spell or ability and opponent controls");
static {
FILTER_SPELL_OR_ABILITY_OPPONENTS.add(new ControllerPredicate(TargetController.OPPONENT));
FILTER_SPELL_OR_ABILITY_OPPONENTS.add(TargetController.OPPONENT.getControllerPredicate());
FILTER_SPELL_OR_ABILITY_OPPONENTS.setLockedFilter(true);
}

View file

@ -5,7 +5,6 @@ import java.util.UUID;
import mage.constants.TargetController;
import mage.filter.FilterImpl;
import mage.filter.FilterInPlay;
import mage.filter.predicate.permanent.ControllerPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
@ -24,7 +23,7 @@ public class FilterControlledCreatureInPlay extends FilterImpl<Object> implement
public FilterControlledCreatureInPlay(String name) {
super(name);
creatureFilter = new FilterCreaturePermanent();
creatureFilter.add(new ControllerPredicate(TargetController.YOU));
creatureFilter.add(TargetController.YOU.getControllerPredicate());
}
@Override

View file

@ -3,7 +3,6 @@ package mage.filter.common;
import mage.constants.SubType;
import mage.constants.TargetController;
import mage.filter.FilterPermanent;
import mage.filter.predicate.permanent.ControllerPredicate;
/**
* @author BetaSteward_at_googlemail.com
@ -24,7 +23,7 @@ public class FilterControlledPermanent extends FilterPermanent {
public FilterControlledPermanent(SubType subtype, String name) {
super(name);
this.add(new ControllerPredicate(TargetController.YOU));
this.add(TargetController.YOU.getControllerPredicate());
if (subtype != null) {
this.add(subtype.getPredicate());
}

View file

@ -2,7 +2,6 @@ package mage.filter.common;
import mage.constants.SubType;
import mage.constants.TargetController;
import mage.filter.predicate.permanent.ControllerPredicate;
/*
* To change this license header, choose License Headers in Project Properties.
@ -21,13 +20,13 @@ public class FilterOpponentsCreaturePermanent extends FilterCreaturePermanent {
public FilterOpponentsCreaturePermanent(String name) {
super(name);
this.add(new ControllerPredicate(TargetController.OPPONENT));
this.add(TargetController.OPPONENT.getControllerPredicate());
}
public FilterOpponentsCreaturePermanent(SubType subtype, String name) {
super(subtype, name);
this.add(new ControllerPredicate(TargetController.OPPONENT));
this.add(TargetController.OPPONENT.getControllerPredicate());
}
public FilterOpponentsCreaturePermanent(final FilterOpponentsCreaturePermanent filter) {

View file

@ -2,7 +2,6 @@ package mage.filter.common;
import mage.constants.SubType;
import mage.constants.TargetController;
import mage.filter.predicate.permanent.ControllerPredicate;
/*
* To change this license header, choose License Headers in Project Properties.
@ -21,13 +20,13 @@ public class FilterTeamCreaturePermanent extends FilterCreaturePermanent {
public FilterTeamCreaturePermanent(String name) {
super(name);
this.add(new ControllerPredicate(TargetController.TEAM));
this.add(TargetController.TEAM.getControllerPredicate());
}
public FilterTeamCreaturePermanent(SubType subtype, String name) {
super(subtype, name);
this.add(new ControllerPredicate(TargetController.TEAM));
this.add(TargetController.TEAM.getControllerPredicate());
}
public FilterTeamCreaturePermanent(final FilterTeamCreaturePermanent filter) {

View file

@ -3,7 +3,6 @@ package mage.filter.common;
import mage.constants.SubType;
import mage.constants.TargetController;
import mage.filter.FilterPermanent;
import mage.filter.predicate.permanent.ControllerPredicate;
/*
* To change this license header, choose License Headers in Project Properties.
@ -22,13 +21,13 @@ public class FilterTeamPermanent extends FilterPermanent {
public FilterTeamPermanent(String name) {
super(name);
this.add(new ControllerPredicate(TargetController.TEAM));
this.add(TargetController.TEAM.getControllerPredicate());
}
public FilterTeamPermanent(SubType subtype, String name) {
super(subtype, name);
this.add(new ControllerPredicate(TargetController.TEAM));
this.add(TargetController.TEAM.getControllerPredicate());
}
public FilterTeamPermanent(final FilterTeamPermanent filter) {

View file

@ -1,67 +0,0 @@
package mage.filter.predicate.permanent;
import mage.constants.TargetController;
import mage.filter.predicate.ObjectPlayer;
import mage.filter.predicate.ObjectPlayerPredicate;
import mage.game.Controllable;
import mage.game.Game;
import java.util.UUID;
/**
*
* @author North
*/
public class ControllerPredicate implements ObjectPlayerPredicate<ObjectPlayer<Controllable>> {
private final TargetController controller;
public ControllerPredicate(TargetController controller) {
this.controller = controller;
}
@Override
public boolean apply(ObjectPlayer<Controllable> input, Game game) {
Controllable object = input.getObject();
UUID playerId = input.getPlayerId();
switch (controller) {
case YOU:
if (object.isControlledBy(playerId)) {
return true;
}
break;
case TEAM:
if (!game.getPlayer(playerId).hasOpponent(object.getControllerId(), game)) {
return true;
}
break;
case OPPONENT:
if (!object.isControlledBy(playerId)
&& game.getPlayer(playerId).hasOpponent(object.getControllerId(), game)) {
return true;
}
break;
case NOT_YOU:
if (!object.isControlledBy(playerId)) {
return true;
}
break;
case ACTIVE:
if (object.isControlledBy(game.getActivePlayerId())) {
return true;
}
break;
case ANY:
return true;
}
return false;
}
@Override
public String toString() {
return "TargetController(" + controller.toString() + ')';
}
}

View file

@ -10,7 +10,6 @@ import mage.abilities.effects.common.DamageTargetEffect;
import mage.constants.*;
import mage.filter.common.FilterLandPermanent;
import mage.filter.predicate.permanent.ControllerPredicate;
import mage.game.Game;
import mage.game.command.Emblem;
import mage.game.permanent.Permanent;
@ -35,7 +34,7 @@ class KothOfTheHammerThirdEffect extends ContinuousEffectImpl {
static {
mountains.add(SubType.MOUNTAIN.getPredicate());
mountains.add(new ControllerPredicate(TargetController.YOU));
mountains.add(TargetController.YOU.getControllerPredicate());
}
public KothOfTheHammerThirdEffect() {

View file

@ -11,7 +11,6 @@ import mage.abilities.effects.common.ExileTargetEffect;
import mage.constants.TargetController;
import mage.constants.Zone;
import mage.filter.FilterPermanent;
import mage.filter.predicate.permanent.ControllerPredicate;
import mage.game.command.Emblem;
import mage.target.TargetPermanent;
@ -26,7 +25,7 @@ public final class TeferiHeroOfDominariaEmblem extends Emblem {
this.setName("Emblem Teferi");
Ability ability = new DrawCardControllerTriggeredAbility(Zone.COMMAND, new ExileTargetEffect(), false);
FilterPermanent filter = new FilterPermanent("permanent an opponent controls");
filter.add(new ControllerPredicate(TargetController.OPPONENT));
filter.add(TargetController.OPPONENT.getControllerPredicate());
ability.addTarget(new TargetPermanent(filter));
this.getAbilities().add(ability);
}

View file

@ -10,7 +10,6 @@ import mage.constants.Duration;
import mage.constants.SubType;
import mage.constants.TargetController;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.permanent.ControllerPredicate;
/**
* @author TheElk801
@ -21,7 +20,7 @@ public final class DoomedArtisanToken extends TokenImpl {
= new FilterCreaturePermanent(SubType.SCULPTURE, "Sculptures you control");
static {
filter.add(new ControllerPredicate(TargetController.YOU));
filter.add(TargetController.YOU.getControllerPredicate());
}
private static final DynamicValue xValue = new PermanentsOnBattlefieldCount(filter);

View file

@ -11,7 +11,6 @@ import mage.constants.Duration;
import mage.constants.TargetController;
import mage.constants.Zone;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.permanent.ControllerPredicate;
/**
*
@ -22,7 +21,7 @@ public final class SpyMasterGoblinToken extends TokenImpl {
private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("Creatures you control");
static {
filter.add(new ControllerPredicate(TargetController.YOU));
filter.add(TargetController.YOU.getControllerPredicate());
}
public SpyMasterGoblinToken() {