diff --git a/Mage.Sets/src/mage/cards/i/IlluminatedFolio.java b/Mage.Sets/src/mage/cards/i/IlluminatedFolio.java index 17c9345c3b..8a1073e8ad 100644 --- a/Mage.Sets/src/mage/cards/i/IlluminatedFolio.java +++ b/Mage.Sets/src/mage/cards/i/IlluminatedFolio.java @@ -1,5 +1,7 @@ package mage.cards.i; +import mage.MageItem; +import mage.ObjectColor; import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.common.RevealTargetFromHandCost; @@ -9,6 +11,7 @@ import mage.abilities.effects.common.DrawCardSourceControllerEffect; import mage.cards.Card; import mage.cards.CardImpl; import mage.cards.CardSetInfo; +import mage.cards.Cards; import mage.constants.CardType; import mage.filter.FilterCard; import mage.filter.predicate.Predicates; @@ -17,7 +20,9 @@ import mage.game.Game; import mage.target.common.TargetCardInHand; import java.util.List; +import java.util.Set; import java.util.UUID; +import java.util.stream.Collectors; /** * @author TheElk801 @@ -62,6 +67,49 @@ class IlluminatedFolioTarget extends TargetCardInHand { super(target); } + @Override + public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) { + return super.canChoose(sourceId, sourceControllerId, game) + && !possibleTargets(sourceId,sourceControllerId, game).isEmpty(); + } + + @Override + public Set possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) { + Set possibleTargets = super.possibleTargets(sourceId,sourceControllerId, game); + if (this.getTargets().size() == 1) { + Card card = game.getCard(this.getTargets().get(0)); + possibleTargets.removeIf( + uuid -> !game + .getCard(uuid) + .getColor(game) + .shares(card.getColor(game)) + ); + return possibleTargets; + } + if (possibleTargets.size() < 2) { + possibleTargets.clear(); + return possibleTargets; + } + Set allTargets = possibleTargets + .stream() + .map(game::getCard) + .collect(Collectors.toSet()); + possibleTargets.clear(); + for (ObjectColor color : ObjectColor.getAllColors()) { + Set inColor = allTargets + .stream() + .filter(card -> card.getColor(game).shares(color)) + .collect(Collectors.toSet()); + if (inColor.size() > 1) { + inColor.stream().map(MageItem::getId).forEach(possibleTargets::add); + } + if (possibleTargets.size() == allTargets.size()) { + break; + } + } + return possibleTargets; + } + @Override public boolean canTarget(UUID id, Game game) { if (!super.canTarget(id, game)) {