mirror of
https://github.com/magefree/mage.git
synced 2025-12-24 20:41:58 -08:00
refactor: cleanup TargetCardInExile (#12218)
This commit is contained in:
parent
82069ef2e8
commit
2522f712e9
20 changed files with 79 additions and 86 deletions
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue