- Moved check for TargetsWithDefinedController to the right place.

This commit is contained in:
Sloth
2013-08-21 11:57:14 +00:00
parent db8a191afb
commit c1d8cccdb3
2 changed files with 15 additions and 15 deletions

View File

@@ -1021,13 +1021,24 @@ public abstract class SpellAbility implements ISpellAbility, ITargetable {
* @return a boolean. * @return a boolean.
*/ */
public final boolean canTarget(final ITargetable entity) { public final boolean canTarget(final ITargetable entity) {
final TargetRestrictions tr = this.getTargetRestrictions();
// Restriction related to this ability // Restriction related to this ability
if (this.getTargetRestrictions() != null) { if (tr != null) {
if (this.getTargetRestrictions().isUniqueTargets() && this.getUniqueTargets().contains(entity)) if (tr.isUniqueTargets() && this.getUniqueTargets().contains(entity))
return false; return false;
// If the cards must have a specific controller
if (tr.getDefinedController() != null && entity instanceof Card) {
final Card c = (Card) entity;
List<Player> pl = AbilityUtils.getDefinedPlayers(this.getSourceCard(), tr.getDefinedController(), this);
if (pl == null || !pl.contains(c.getController()) ) {
return false;
}
}
String[] validTgt = this.getTargetRestrictions().getValidTgts(); String[] validTgt = tr.getValidTgts();
if (entity instanceof GameEntity && !((GameEntity)entity).isValid(validTgt, this.getActivatingPlayer(), this.getSourceCard())) if (entity instanceof GameEntity && !((GameEntity) entity).isValid(validTgt, this.getActivatingPlayer(), this.getSourceCard()))
return false; return false;
} }

View File

@@ -27,7 +27,6 @@ import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.ITargetable; import forge.ITargetable;
import forge.Singletons; import forge.Singletons;
import forge.card.ability.AbilityUtils;
import forge.game.Game; import forge.game.Game;
import forge.game.player.Player; import forge.game.player.Player;
import forge.game.zone.Zone; import forge.game.zone.Zone;
@@ -241,16 +240,6 @@ public class TargetSelection {
} }
}); });
} }
// If the cards must have a specific controller
if (tgt.getDefinedController() != null) {
List<Player> pl = AbilityUtils.getDefinedPlayers(ability.getSourceCard(), tgt.getDefinedController(), this.ability);
if (pl != null && !pl.isEmpty()) {
Player controller = pl.get(0);
choices = CardLists.filterControlledBy(choices, controller);
} else {
choices.clear();
}
}
return choices; return choices;
} }