Merge pull request #6152 from magefree/refactorTargetController

Refactored TargetController predicates
This commit is contained in:
Evan Kranzler 2020-01-06 21:56:26 -05:00 committed by GitHub
commit 48a43a8360
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
847 changed files with 1128 additions and 1994 deletions

View file

@ -8,7 +8,6 @@ import mage.constants.SetTargetPointer;
import mage.constants.TargetController;
import mage.constants.Zone;
import mage.filter.FilterCard;
import mage.filter.predicate.other.OwnerPredicate;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent;
@ -40,7 +39,7 @@ public class PutCardIntoGraveFromAnywhereAllTriggeredAbility extends TriggeredAb
super(zone, effect, optional);
this.filter = filter.copy();
this.setTargetPointer = setTargetPointer;
this.filter.add(new OwnerPredicate(targetController));
this.filter.add(targetController.getOwnerPredicate());
StringBuilder sb = new StringBuilder("Whenever ");
sb.append(filter.getMessage());
sb.append(" is put into ");

View file

@ -14,7 +14,6 @@ import mage.constants.Outcome;
import mage.constants.TargetController;
import mage.constants.Zone;
import mage.filter.FilterCard;
import mage.filter.predicate.other.OwnerPredicate;
import mage.game.Game;
import mage.players.Player;
import mage.target.Target;
@ -43,7 +42,7 @@ public class ExileOpponentsCardFromExileToGraveyardCost extends CostImpl {
Player controller = game.getPlayer(controllerId);
if (controller != null) {
FilterCard filter = new FilterCard();
filter.add(new OwnerPredicate(TargetController.OPPONENT));
filter.add(TargetController.OPPONENT.getOwnerPredicate());
Target target = new TargetCardInExile(filter);
if (controller.chooseTarget(Outcome.Damage, target, ability, game)) {
Card card = game.getCard(target.getFirstTarget());

View file

@ -14,7 +14,6 @@ import mage.constants.Outcome;
import mage.constants.TargetController;
import mage.filter.FilterPlayer;
import mage.filter.predicate.other.PlayerCanGainLifePredicate;
import mage.filter.predicate.other.PlayerPredicate;
import mage.game.Game;
import mage.players.Player;
import mage.target.TargetPlayer;
@ -28,7 +27,7 @@ public class GainLifeOpponentCost extends CostImpl {
private static final FilterPlayer filter = new FilterPlayer("opponent that can gain life");
static {
filter.add(new PlayerPredicate(TargetController.OPPONENT));
filter.add(TargetController.OPPONENT.getPlayerPredicate());
filter.add(new PlayerCanGainLifePredicate()); // you can't pay the costs by letting a player gain life that can't get life by rule changing effect
}

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.costs.mana.ManaCost;
import mage.abilities.effects.OneShotEffect;
import mage.constants.*;
import mage.filter.FilterPlayer;
import mage.filter.predicate.other.PlayerPredicate;
import mage.game.Game;
import mage.players.ManaPool;
import mage.players.Player;
@ -26,7 +25,7 @@ public class AssistAbility extends SimpleStaticAbility implements AlternateManaP
private static final FilterPlayer filter = new FilterPlayer("another player");
static {
filter.add(new PlayerPredicate(TargetController.NOT_YOU));
filter.add(TargetController.NOT_YOU.getPlayerPredicate());
}
public AssistAbility() {

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

@ -12,7 +12,6 @@ import mage.constants.TargetController;
import mage.constants.Zone;
import mage.filter.FilterPermanent;
import mage.filter.common.FilterLandPermanent;
import mage.filter.predicate.permanent.ControllerPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
@ -73,7 +72,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

@ -1,10 +1,197 @@
package mage.constants;
import mage.cards.Card;
import mage.filter.predicate.ObjectPlayer;
import mage.filter.predicate.ObjectPlayerPredicate;
import mage.filter.predicate.ObjectSourcePlayer;
import mage.filter.predicate.ObjectSourcePlayerPredicate;
import mage.game.Controllable;
import mage.game.Game;
import mage.players.Player;
import java.util.UUID;
/**
*
* @author North
*/
public enum TargetController {
ACTIVE, ANY, YOU, NOT_YOU, OPPONENT, TEAM, OWNER, CONTROLLER_ATTACHED_TO, NEXT, EACH_PLAYER
ACTIVE,
ANY,
YOU,
NOT_YOU,
OPPONENT,
TEAM,
OWNER,
CONTROLLER_ATTACHED_TO,
NEXT,
EACH_PLAYER;
private OwnerPredicate ownerPredicate = null;
private PlayerPredicate playerPredicate = null;
private ControllerPredicate controllerPredicate = null;
public OwnerPredicate getOwnerPredicate() {
if (this.ownerPredicate == null) {
this.ownerPredicate = new OwnerPredicate(this);
}
return this.ownerPredicate;
}
public PlayerPredicate getPlayerPredicate() {
if (this.playerPredicate == null) {
this.playerPredicate = new PlayerPredicate(this);
}
return this.playerPredicate;
}
public ControllerPredicate getControllerPredicate() {
if (this.controllerPredicate == null) {
this.controllerPredicate = new ControllerPredicate(this);
}
return this.controllerPredicate;
}
public static class OwnerPredicate implements ObjectPlayerPredicate<ObjectPlayer<Card>> {
private final TargetController targetOwner;
private 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.isOwnedBy(playerId)) {
return true;
}
break;
case OPPONENT:
if (!card.isOwnedBy(playerId)
&& game.getPlayer(playerId).hasOpponent(card.getOwnerId(), game)) {
return true;
}
break;
case NOT_YOU:
if (!card.isOwnedBy(playerId)) {
return true;
}
break;
case ANY:
return true;
}
return false;
}
@Override
public String toString() {
return "Owner(" + targetOwner + ')';
}
}
public static class PlayerPredicate implements ObjectSourcePlayerPredicate<ObjectSourcePlayer<Player>> {
private final TargetController targetPlayer;
private PlayerPredicate(TargetController player) {
this.targetPlayer = player;
}
@Override
public boolean apply(ObjectSourcePlayer<Player> input, Game game) {
Player player = input.getObject();
UUID playerId = input.getPlayerId();
if (player == null || playerId == null) {
return false;
}
switch (targetPlayer) {
case YOU:
if (player.getId().equals(playerId)) {
return true;
}
break;
case OPPONENT:
if (!player.getId().equals(playerId) &&
game.getPlayer(playerId).hasOpponent(player.getId(), game)) {
return true;
}
break;
case NOT_YOU:
if (!player.getId().equals(playerId)) {
return true;
}
break;
}
return false;
}
@Override
public String toString() {
return "Player(" + targetPlayer + ')';
}
}
public static class ControllerPredicate implements ObjectPlayerPredicate<ObjectPlayer<Controllable>> {
private final TargetController controller;
private 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

@ -2,7 +2,6 @@
package mage.filter;
import mage.constants.TargetController;
import mage.filter.predicate.other.PlayerPredicate;
/**
*
@ -16,7 +15,7 @@ public class FilterOpponent extends FilterPlayer {
public FilterOpponent(String text) {
super(text);
add(new PlayerPredicate(TargetController.OPPONENT));
add(TargetController.OPPONENT.getPlayerPredicate());
}
public FilterOpponent(final FilterOpponent filter) {

View file

@ -12,10 +12,8 @@ import mage.constants.TargetController;
import mage.filter.common.*;
import mage.filter.predicate.Predicates;
import mage.filter.predicate.mageobject.MulticoloredPredicate;
import mage.filter.predicate.other.PlayerPredicate;
import mage.filter.predicate.permanent.AnotherPredicate;
import mage.filter.predicate.permanent.AttackingPredicate;
import mage.filter.predicate.permanent.ControllerPredicate;
import mage.filter.predicate.permanent.TokenPredicate;
/**
@ -305,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);
}
@ -327,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()
@ -436,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);
}
@ -449,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);
}
@ -492,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);
}
@ -633,7 +631,7 @@ public final class StaticFilters {
public static final FilterPlayer FILTER_PLAYER_CONTROLLER = new FilterPlayer("you");
static {
FILTER_PLAYER_CONTROLLER.add(new PlayerPredicate(TargetController.YOU));
FILTER_PLAYER_CONTROLLER.add(TargetController.YOU.getPlayerPredicate());
FILTER_PLAYER_CONTROLLER.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

@ -4,7 +4,6 @@ package mage.filter.common;
import mage.constants.TargetController;
import mage.filter.FilterCard;
import mage.filter.predicate.other.OwnerPredicate;
/**
*
@ -18,7 +17,7 @@ public class FilterOwnedCard extends FilterCard {
public FilterOwnedCard(String name) {
super(name);
this.add(new OwnerPredicate(TargetController.YOU));
this.add(TargetController.YOU.getOwnerPredicate());
}
public FilterOwnedCard(final FilterOwnedCard 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,59 +0,0 @@
package mage.filter.predicate.other;
import java.util.UUID;
import mage.cards.Card;
import mage.constants.TargetController;
import mage.filter.predicate.ObjectPlayer;
import mage.filter.predicate.ObjectPlayerPredicate;
import mage.game.Game;
/**
*
* @author North
*/
public class OwnerPredicate implements ObjectPlayerPredicate<ObjectPlayer<Card>> {
private final 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.isOwnedBy(playerId)) {
return true;
}
break;
case OPPONENT:
if (!card.isOwnedBy(playerId)
&& game.getPlayer(playerId).hasOpponent(card.getOwnerId(), game)) {
return true;
}
break;
case NOT_YOU:
if (!card.isOwnedBy(playerId)) {
return true;
}
break;
case ANY:
return true;
}
return false;
}
@Override
public String toString() {
return "Owner(" + targetOwner + ')';
}
}

View file

@ -1,57 +0,0 @@
package mage.filter.predicate.other;
import java.util.UUID;
import mage.constants.TargetController;
import mage.filter.predicate.ObjectSourcePlayer;
import mage.filter.predicate.ObjectSourcePlayerPredicate;
import mage.game.Game;
import mage.players.Player;
/**
*
* @author North
*/
public class PlayerPredicate implements ObjectSourcePlayerPredicate<ObjectSourcePlayer<Player>> {
private final TargetController targetPlayer;
public PlayerPredicate(TargetController player) {
this.targetPlayer = player;
}
@Override
public boolean apply(ObjectSourcePlayer<Player> input, Game game) {
Player player = input.getObject();
UUID playerId = input.getPlayerId();
if (player == null || playerId == null) {
return false;
}
switch (targetPlayer) {
case YOU:
if (player.getId().equals(playerId)) {
return true;
}
break;
case OPPONENT:
if (!player.getId().equals(playerId) &&
game.getPlayer(playerId).hasOpponent(player.getId(), game)) {
return true;
}
break;
case NOT_YOU:
if (!player.getId().equals(playerId)) {
return true;
}
break;
}
return false;
}
@Override
public String toString() {
return "Player(" + targetPlayer + ')';
}
}

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

@ -1,7 +1,5 @@
package mage.filter.predicate.permanent;
import java.util.UUID;
import mage.constants.TargetController;
import mage.filter.predicate.ObjectPlayer;
import mage.filter.predicate.ObjectPlayerPredicate;
@ -9,8 +7,9 @@ import mage.game.Controllable;
import mage.game.Game;
import mage.watchers.common.PlayerDamagedBySourceWatcher;
import java.util.UUID;
/**
*
* @author LevelX2
*/
public class DamagedPlayerThisTurnPredicate implements ObjectPlayerPredicate<ObjectPlayer<Controllable>> {

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() {