Fixed a bug of TargetSpellOrPermanent.

This commit is contained in:
LevelX2 2015-09-18 15:31:49 +02:00
parent cb629f0228
commit fcbc9ce3a5

View file

@ -51,7 +51,6 @@ import mage.target.TargetImpl;
public class TargetSpellOrPermanent extends TargetImpl {
protected FilterSpellOrPermanent filter;
protected FilterPermanent filterPermanent;
public TargetSpellOrPermanent() {
this(1, 1);
@ -62,28 +61,28 @@ public class TargetSpellOrPermanent extends TargetImpl {
}
public TargetSpellOrPermanent(int minNumTargets, int maxNumTargets) {
this.minNumberOfTargets = minNumTargets;
this.maxNumberOfTargets = maxNumTargets;
this.zone = Zone.ALL;
this.filter = new FilterSpellOrPermanent();
this.targetName = filter.getMessage();
this.filterPermanent = new FilterPermanent();
this(minNumTargets, maxNumTargets, false);
}
public TargetSpellOrPermanent(int minNumTargets, int maxNumTargets, boolean notTarget) {
this(minNumTargets, maxNumTargets);
this(minNumTargets, maxNumTargets, new FilterSpellOrPermanent(), notTarget);
this.notTarget = notTarget;
}
public TargetSpellOrPermanent(int minNumTargets, int maxNumTargets, FilterSpellOrPermanent filter, boolean notTarget) {
this(minNumTargets, maxNumTargets);
super(notTarget);
this.minNumberOfTargets = minNumTargets;
this.maxNumberOfTargets = maxNumTargets;
this.zone = Zone.ALL;
this.targetName = filter.getMessage();
this.notTarget = notTarget;
this.filter = filter;
this.targetName = filter.getMessage();
}
public TargetSpellOrPermanent(final TargetSpellOrPermanent target) {
super(target);
this.filter = target.filter.copy();
this.filterPermanent = target.filterPermanent.copy();
}
@Override
@ -92,7 +91,7 @@ public class TargetSpellOrPermanent extends TargetImpl {
}
public FilterPermanent getPermanentFilter() {
return this.filterPermanent;
return this.filter.getPermanentFilter();
}
public void setFilter(FilterSpellOrPermanent filter) {
@ -136,13 +135,15 @@ public class TargetSpellOrPermanent extends TargetImpl {
}
/**
* Checks if there are enough {@link mage.game.permanent.Permanent} or {@link mage.game.stack.Spell} that can be chosen. Should only be used
* for Ability targets since this checks for protection, shroud etc.
* Checks if there are enough {@link mage.game.permanent.Permanent} or
* {@link mage.game.stack.Spell} that can be chosen. Should only be used for
* Ability targets since this checks for protection, shroud etc.
*
* @param sourceId - the target event source
* @param sourceControllerId - controller of the target event source
* @param game
* @return - true if enough valid {@link mage.game.permanent.Permanent} or {@link mage.game.stack.Spell} exist
* @return - true if enough valid {@link mage.game.permanent.Permanent} or
* {@link mage.game.stack.Spell} exist
*/
@Override
public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) {
@ -157,7 +158,7 @@ public class TargetSpellOrPermanent extends TargetImpl {
}
}
}
for (Permanent permanent: game.getBattlefield().getActivePermanents(filterPermanent, sourceControllerId, game)) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter.getPermanentFilter(), sourceControllerId, game)) {
if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game) && filter.match(permanent, sourceId, sourceControllerId, game)) {
count++;
if (count >= this.minNumberOfTargets) {
@ -169,12 +170,14 @@ public class TargetSpellOrPermanent extends TargetImpl {
}
/**
* Checks if there are enough {@link mage.game.permanent.Permanent} or {@link mage.game.stack.Spell} that can be selected. Should not be used
* Checks if there are enough {@link mage.game.permanent.Permanent} or
* {@link mage.game.stack.Spell} that can be selected. Should not be used
* for Ability targets since this does not check for protection, shroud etc.
*
* @param sourceControllerId - controller of the select event
* @param game
* @return - true if enough valid {@link mage.game.permanent.Permanent} or {@link mage.game.stack.Spell} exist
* @return - true if enough valid {@link mage.game.permanent.Permanent} or
* {@link mage.game.stack.Spell} exist
*/
@Override
public boolean canChoose(UUID sourceControllerId, Game game) {
@ -188,7 +191,7 @@ public class TargetSpellOrPermanent extends TargetImpl {
}
}
}
for (Permanent permanent: game.getBattlefield().getActivePermanents(filterPermanent, sourceControllerId, game)) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter.getPermanentFilter(), sourceControllerId, game)) {
if (filter.match(permanent, null, sourceControllerId, game) && filter.match(permanent, game)) {
count++;
if (count >= this.minNumberOfTargets) {
@ -209,7 +212,7 @@ public class TargetSpellOrPermanent extends TargetImpl {
possibleTargets.add(spell.getId());
}
}
for (Permanent permanent: game.getBattlefield().getActivePermanents(filterPermanent, sourceControllerId, game)) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter.getPermanentFilter(), sourceControllerId, game)) {
if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game) && filter.match(permanent, sourceId, sourceControllerId, game)) {
possibleTargets.add(permanent.getId());
}
@ -226,7 +229,7 @@ public class TargetSpellOrPermanent extends TargetImpl {
possibleTargets.add(spell.getId());
}
}
for (Permanent permanent: game.getBattlefield().getActivePermanents(filterPermanent, sourceControllerId, game)) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter.getPermanentFilter(), sourceControllerId, game)) {
if (filter.match(permanent, null, sourceControllerId, game)) {
possibleTargets.add(permanent.getId());
}
@ -241,8 +244,7 @@ public class TargetSpellOrPermanent extends TargetImpl {
Permanent permanent = game.getPermanent(targetId);
if (permanent != null) {
sb.append(permanent.getLogName()).append(" ");
}
else {
} else {
Spell spell = game.getStack().getSpell(targetId);
sb.append(spell.getLogName()).append(" ");
}