refactor: cleanup TargetCardInExile (#12218)

This commit is contained in:
Susucre 2024-05-04 04:15:13 +02:00 committed by GitHub
parent 82069ef2e8
commit 2522f712e9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 79 additions and 86 deletions

View file

@ -137,7 +137,7 @@ class CascadeEffect extends OneShotEffect {
GameEvent event = GameEvent.getEvent(GameEvent.EventType.CASCADE_LAND, source.getSourceId(), source, source.getControllerId(), 0);
game.replaceEvent(event);
if (event.getAmount() > 0) {
TargetCardInExile target = new TargetCardInExile(0, event.getAmount(), StaticFilters.FILTER_CARD_LAND, null, true);
TargetCardInExile target = new TargetCardInExile(0, event.getAmount(), StaticFilters.FILTER_CARD_LAND);
target.withChooseHint("land to put onto battlefield tapped");
controller.choose(Outcome.PutCardInPlay, cardsToExile, target, source, game);
controller.moveCards(

View file

@ -18,41 +18,54 @@ import java.util.UUID;
*/
public class TargetCardInExile extends TargetCard {
// If null, can target any card in exile matching [filter]
// If non-null, can only target
private final UUID zoneId;
private final boolean allExileZones;
/**
* @param filter filter for the card to be a target
*/
public TargetCardInExile(FilterCard filter) {
this(1, 1, filter, null);
this(1, 1, filter);
}
/**
* @param filter
* @param zoneId - if null card can be in ever exile zone
* @param minNumTargets minimum number of targets
* @param maxNumTargets maximum number of targets
* @param filter filter for the card to be a target
*/
public TargetCardInExile(int minNumTargets, int maxNumTargets, FilterCard filter) {
this(minNumTargets, maxNumTargets, filter, null);
}
/**
* @param filter filter for the card to be a target
* @param zoneId if non-null can only target cards in that exileZone. if null card can be in ever exile zone.
*/
public TargetCardInExile(FilterCard filter, UUID zoneId) {
this(1, 1, filter, zoneId);
}
/**
* @param minNumTargets minimum number of targets
* @param maxNumTargets maximum number of targets
* @param filter filter for the card to be a target
* @param zoneId if non-null can only target cards in that exileZone. if null card can be in ever exile zone.
*/
public TargetCardInExile(int minNumTargets, int maxNumTargets, FilterCard filter, UUID zoneId) {
this(minNumTargets, maxNumTargets, filter, zoneId, zoneId == null);
}
public TargetCardInExile(int minNumTargets, int maxNumTargets, FilterCard filter, UUID zoneId, boolean allExileZones) {
super(minNumTargets, maxNumTargets, Zone.EXILED, filter);
this.zoneId = zoneId;
this.allExileZones = zoneId == null || allExileZones;
}
protected TargetCardInExile(final TargetCardInExile target) {
super(target);
this.zoneId = target.zoneId;
this.allExileZones = target.allExileZones;
}
@Override
public Set<UUID> possibleTargets(UUID sourceControllerId, Ability source, Game game) {
Set<UUID> possibleTargets = new HashSet<>();
if (allExileZones) {
if (zoneId == null) { // no specific exile zone
for (Card card : game.getExile().getAllCardsByRange(game, sourceControllerId)) {
if (filter.match(card, sourceControllerId, source, game)) {
possibleTargets.add(card.getId());
@ -73,7 +86,7 @@ public class TargetCardInExile extends TargetCard {
@Override
public boolean canChoose(UUID sourceControllerId, Ability source, Game game) {
if (allExileZones) {
if (zoneId == null) { // no specific exile zone
int numberTargets = 0;
for (ExileZone exileZone : game.getExile().getExileZones()) {
numberTargets += exileZone.count(filter, sourceControllerId, source, game);
@ -96,15 +109,10 @@ public class TargetCardInExile extends TargetCard {
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) {
if (zoneId == null) { // no specific exile zone
return filter.match(card, source.getControllerId(), source, game);
}
ExileZone exile;
if (zoneId != null) {
exile = game.getExile().getExileZone(zoneId);
} else {
exile = game.getExile().getPermanentExile();
}
ExileZone exile = game.getExile().getExileZone(zoneId);
if (exile != null && exile.contains(id)) {
return filter.match(card, source.getControllerId(), source, game);
}