Added a mode to allow TargetCardInExile in all exile zones.

This commit is contained in:
LevelX2 2013-06-22 01:57:21 +02:00
parent 0ab055c0f8
commit 3e1b0f5fce

View file

@ -27,15 +27,17 @@
*/
package mage.target.common;
import mage.constants.Zone;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import mage.abilities.Ability;
import mage.cards.Card;
import mage.constants.Zone;
import mage.filter.FilterCard;
import mage.game.ExileZone;
import mage.game.Game;
import mage.target.TargetCard;
import java.util.UUID;
/**
*
@ -44,26 +46,67 @@ import java.util.UUID;
public class TargetCardInExile extends TargetCard<TargetCardInExile> {
private UUID zoneId;
private boolean allExileZones;
public TargetCardInExile(FilterCard filter, UUID zoneId) {
this(1, 1, filter, zoneId);
}
public TargetCardInExile(int minNumTargets, int maxNumTargets, FilterCard filter, UUID zoneId) {
this(minNumTargets, maxNumTargets, filter, zoneId, false);
}
public TargetCardInExile(int minNumTargets, int maxNumTargets, FilterCard filter, UUID zoneId, boolean allExileZones) {
super(minNumTargets, maxNumTargets, Zone.EXILED, filter);
this.zoneId = zoneId;
this.allExileZones = allExileZones;
this.targetName = filter.getMessage();
}
public TargetCardInExile(final TargetCardInExile target) {
super(target);
this.zoneId = target.zoneId;
this.allExileZones = target.allExileZones;
}
@Override
@Override
public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) {
if (allExileZones) {
Set<UUID> possibleTargets = new HashSet<UUID>();
for (Card card : game.getExile().getAllCards(game)) {
if (filter.match(card, sourceControllerId, game)) {
possibleTargets.add(card.getId());
}
}
return possibleTargets;
} else {
return super.possibleTargets(sourceId, sourceControllerId, game);
}
}
@Override
public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) {
if (allExileZones) {
int numberTargets = 0;
for(ExileZone exileZone : game.getExile().getExileZones()) {
numberTargets += exileZone.count(filter, sourceId, sourceControllerId, game);
if (numberTargets >= this.minNumberOfTargets) {
return true;
}
}
return false;
} else {
return super.canChoose(sourceControllerId, game);
}
}
@Override
public boolean canTarget(UUID id, Ability source, Game game) {
Card card = game.getCard(id);
if (card != null && game.getState().getZone(card.getId()) == Zone.EXILED) {
if (allExileZones) {
return filter.match(card, source.getControllerId(), game);
}
ExileZone exile;
if (zoneId != null) {
exile = game.getExile().getExileZone(zoneId);