Issue #1311: Cards with 'another target creature or player'

AnotherTargetPredicate: Use MageItem instead of MageObject so it will
now also work with Player objects.

TargetCreatureOrPlayer: Add constructor specifying a filter object, modify
methods to actually use the creature and player filters.

Arc Trail and Cone of Flame: Use AnotherTargetPredicate to specify
multiple different targets
This commit is contained in:
Skyler Sell 2016-01-27 20:08:06 -08:00
parent fa5a098a14
commit 5155f9024e
4 changed files with 70 additions and 28 deletions

View file

@ -27,7 +27,7 @@
*/
package mage.filter.predicate.mageobject;
import mage.MageObject;
import mage.MageItem;
import mage.filter.predicate.ObjectSourcePlayer;
import mage.filter.predicate.ObjectSourcePlayerPredicate;
import mage.game.Game;
@ -42,7 +42,7 @@ import mage.target.Target;
*
* @author LevelX2
*/
public class AnotherTargetPredicate implements ObjectSourcePlayerPredicate<ObjectSourcePlayer<MageObject>> {
public class AnotherTargetPredicate implements ObjectSourcePlayerPredicate<ObjectSourcePlayer<MageItem>> {
private final int targetTag;
@ -51,14 +51,14 @@ public class AnotherTargetPredicate implements ObjectSourcePlayerPredicate<Objec
}
@Override
public boolean apply(ObjectSourcePlayer<MageObject> input, Game game) {
public boolean apply(ObjectSourcePlayer<MageItem> input, Game game) {
StackObject source = game.getStack().getStackObject(input.getSourceId());
if (source != null) {
for (Target target : source.getStackAbility().getTargets()) {
if (target.getTargetTag() > 0 // target is included in the target group to check
&& target.getTargetTag() != targetTag // it's not the target of this predicate
&& target.getTargets().contains(input.getObject().getId())) { // if the uuid already is used for another target in the group it's no allowed here
return false;
&& target.getTargets().contains(input.getObject().getId())) { // if the uuid already is used for another target in the group it's not allowed here
return false;
}
}
}

View file

@ -33,7 +33,6 @@ import mage.MageObject;
import mage.abilities.Ability;
import mage.filter.Filter;
import mage.filter.common.FilterCreatureOrPlayer;
import mage.filter.common.FilterCreaturePermanent;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
@ -52,18 +51,22 @@ public class TargetCreatureOrPlayer extends TargetImpl {
protected FilterCreatureOrPlayer filter;
public TargetCreatureOrPlayer() {
this(1, 1);
this(1, 1, new FilterCreatureOrPlayer());
}
public TargetCreatureOrPlayer(int numTargets) {
this(numTargets, numTargets);
this(numTargets, numTargets, new FilterCreatureOrPlayer());
}
public TargetCreatureOrPlayer(int numTargets, int maxNumTargets) {
this(numTargets, maxNumTargets, new FilterCreatureOrPlayer());
}
public TargetCreatureOrPlayer(int minNumTargets, int maxNumTargets) {
public TargetCreatureOrPlayer(int minNumTargets, int maxNumTargets, FilterCreatureOrPlayer filter) {
this.minNumberOfTargets = minNumTargets;
this.maxNumberOfTargets = maxNumTargets;
this.zone = Zone.ALL;
this.filter = new FilterCreatureOrPlayer();
this.filter = filter;
this.targetName = filter.getMessage();
}
@ -141,7 +144,7 @@ public class TargetCreatureOrPlayer extends TargetImpl {
}
}
}
for (Permanent permanent: game.getBattlefield().getActivePermanents(new FilterCreaturePermanent(), sourceControllerId, game)) {
for (Permanent permanent: game.getBattlefield().getActivePermanents(filter.getCreatureFilter(), sourceControllerId, game)) {
if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game) && filter.match(permanent, sourceId, sourceControllerId, game)) {
count++;
if (count >= this.minNumberOfTargets) {
@ -172,7 +175,7 @@ public class TargetCreatureOrPlayer extends TargetImpl {
}
}
}
for (Permanent permanent: game.getBattlefield().getActivePermanents(new FilterCreaturePermanent(), sourceControllerId, game)) {
for (Permanent permanent: game.getBattlefield().getActivePermanents(filter.getCreatureFilter(), sourceControllerId, game)) {
if (filter.match(permanent, null, sourceControllerId, game)) {
count++;
if (count >= this.minNumberOfTargets) {
@ -189,12 +192,15 @@ public class TargetCreatureOrPlayer extends TargetImpl {
MageObject targetSource = game.getObject(sourceId);
for (UUID playerId: game.getPlayer(sourceControllerId).getInRange()) {
Player player = game.getPlayer(playerId);
if (player != null && player.canBeTargetedBy(targetSource, sourceControllerId, game) && filter.match(player, game)) {
if (player != null
&& player.canBeTargetedBy(targetSource, sourceControllerId, game)
&& filter.getPlayerFilter().match(player, sourceId, sourceControllerId, game)) {
possibleTargets.add(playerId);
}
}
for (Permanent permanent: game.getBattlefield().getActivePermanents(new FilterCreaturePermanent(), sourceControllerId, game)) {
if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game) && filter.match(permanent, sourceId, sourceControllerId, game)) {
for (Permanent permanent: game.getBattlefield().getActivePermanents(filter.getCreatureFilter(), sourceControllerId, game)) {
if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game)
&& filter.getCreatureFilter().match(permanent, sourceId, sourceControllerId, game)) {
possibleTargets.add(permanent.getId());
}
}
@ -206,12 +212,12 @@ public class TargetCreatureOrPlayer extends TargetImpl {
Set<UUID> possibleTargets = new HashSet<>();
for (UUID playerId: game.getPlayer(sourceControllerId).getInRange()) {
Player player = game.getPlayer(playerId);
if (player != null && filter.match(player, game)) {
if (player != null && filter.getPlayerFilter().match(player, game)) {
possibleTargets.add(playerId);
}
}
for (Permanent permanent: game.getBattlefield().getActivePermanents(new FilterCreaturePermanent(), sourceControllerId, game)) {
if (filter.match(permanent, null, sourceControllerId, game)) {
for (Permanent permanent: game.getBattlefield().getActivePermanents(filter.getCreatureFilter(), sourceControllerId, game)) {
if (filter.getCreatureFilter().match(permanent, null, sourceControllerId, game)) {
possibleTargets.add(permanent.getId());
}
}