[SHM] reworked Illuminated Folio (fixes #8111)

This commit is contained in:
Evan Kranzler 2021-10-26 09:01:26 -04:00
parent a30c2f4a8b
commit c8d94c5571

View file

@ -1,44 +1,42 @@
package mage.cards.i; package mage.cards.i;
import java.util.HashSet; import mage.MageItem;
import java.util.Map; import mage.ObjectColor;
import java.util.Set;
import java.util.UUID;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.common.RevealTargetFromHandCost; import mage.abilities.costs.common.RevealTargetFromHandCost;
import mage.abilities.costs.common.TapSourceCost; import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.costs.mana.GenericManaCost;
import mage.abilities.effects.common.DrawCardSourceControllerEffect; import mage.abilities.effects.common.DrawCardSourceControllerEffect;
import mage.cards.Card; import mage.cards.Card;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.CardSetInfo; import mage.cards.CardSetInfo;
import mage.cards.Cards;
import mage.cards.CardsImpl;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Zone;
import mage.filter.FilterCard; import mage.filter.FilterCard;
import mage.filter.predicate.mageobject.ColorPredicate; import mage.filter.predicate.Predicates;
import mage.filter.predicate.mageobject.ColorlessPredicate;
import mage.game.Game; import mage.game.Game;
import mage.players.Player;
import mage.target.common.TargetCardInHand; import mage.target.common.TargetCardInHand;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
/** /**
* * @author TheElk801
* @author jeffwadsworth
*/ */
public final class IlluminatedFolio extends CardImpl { public final class IlluminatedFolio extends CardImpl {
public IlluminatedFolio(UUID ownerId, CardSetInfo setInfo) { public IlluminatedFolio(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.ARTIFACT},"{5}"); super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{5}");
// {1}, {tap}, Reveal two cards from your hand that share a color: Draw a card. // {1}, {tap}, Reveal two cards from your hand that share a color: Draw a card.
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new DrawCardSourceControllerEffect(1), new ManaCostsImpl("{1}")); Ability ability = new SimpleActivatedAbility(
new DrawCardSourceControllerEffect(1), new GenericManaCost(1)
);
ability.addCost(new TapSourceCost()); ability.addCost(new TapSourceCost());
ability.addCost(new RevealTwoCardsSharedColorFromHandCost()); ability.addCost(new RevealTargetFromHandCost(new IlluminatedFolioTarget()));
this.addAbility(ability); this.addAbility(ability);
} }
private IlluminatedFolio(final IlluminatedFolio card) { private IlluminatedFolio(final IlluminatedFolio card) {
@ -51,111 +49,75 @@ public final class IlluminatedFolio extends CardImpl {
} }
} }
class RevealTwoCardsSharedColorFromHandCost extends RevealTargetFromHandCost { class IlluminatedFolioTarget extends TargetCardInHand {
public RevealTwoCardsSharedColorFromHandCost() { private static final FilterCard filter = new FilterCard("two cards from your hand that share a color");
super(new TargetTwoCardsWithTheSameColorInHand());
static {
filter.add(Predicates.not(ColorlessPredicate.instance));
} }
public RevealTwoCardsSharedColorFromHandCost(RevealTwoCardsSharedColorFromHandCost cost) { public IlluminatedFolioTarget() {
super(cost); super(2, 2, filter);
} }
@Override private IlluminatedFolioTarget(final IlluminatedFolioTarget target) {
public RevealTwoCardsSharedColorFromHandCost copy() {
return new RevealTwoCardsSharedColorFromHandCost(this);
}
}
class TargetTwoCardsWithTheSameColorInHand extends TargetCardInHand {
public TargetTwoCardsWithTheSameColorInHand() {
super(2, 2, new FilterCard("two cards from your hand that share a color"));
}
public TargetTwoCardsWithTheSameColorInHand(final TargetTwoCardsWithTheSameColorInHand target) {
super(target); super(target);
} }
@Override @Override
public Set<UUID> possibleTargets(UUID sourceControllerId, Game game) { public Set<UUID> possibleTargets(UUID sourceControllerId, Game game) {
Set<UUID> newPossibleTargets = new HashSet<>(); Set<UUID> possibleTargets = super.possibleTargets(sourceControllerId, game);
Set<UUID> possibleTargets = new HashSet<>(); if (this.getTargets().size() == 1) {
Player player = game.getPlayer(sourceControllerId); Card card = game.getCard(this.getTargets().get(0));
for (Card card : player.getHand().getCards(filter, game)) { possibleTargets.removeIf(
possibleTargets.add(card.getId()); uuid -> game
.getCard(uuid)
.getColor(game)
.shares(card.getColor(game))
);
return possibleTargets;
} }
if (possibleTargets.size() < 2) {
Cards cardsToCheck = new CardsImpl(); possibleTargets.clear();
cardsToCheck.addAll(possibleTargets); return possibleTargets;
if (targets.size() == 1) { }
// first target is already choosen, now only targets with the shared color are selectable Set<Card> allTargets = possibleTargets
for (Map.Entry<UUID, Integer> entry : targets.entrySet()) { .stream()
Card chosenCard = cardsToCheck.get(entry.getKey(), game); .map(game::getCard)
if (chosenCard != null) { .collect(Collectors.toSet());
for (UUID cardToCheck : cardsToCheck) { possibleTargets.clear();
if (!cardToCheck.equals(chosenCard.getId()) && chosenCard.getColor(game).equals(game.getCard(cardToCheck).getColor(game))) { for (ObjectColor color : ObjectColor.getAllColors()) {
newPossibleTargets.add(cardToCheck); Set<Card> 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;
}
} else {
for (UUID cardToCheck : cardsToCheck) {
FilterCard colorFilter = new FilterCard();
colorFilter.add(new ColorPredicate(game.getCard(cardToCheck).getColor(game)));
if (cardsToCheck.count(colorFilter, game) > 1) {
newPossibleTargets.add(cardToCheck);
}
}
}
return newPossibleTargets;
}
@Override
public boolean canChoose(UUID sourceControllerId, Game game) {
Cards cardsToCheck = new CardsImpl();
Player player = game.getPlayer(sourceControllerId);
for (Card card : player.getHand().getCards(filter, game)) {
cardsToCheck.add(card.getId());
}
int possibleCards = 0;
for (UUID cardToCheck : cardsToCheck) {
FilterCard colorFilter = new FilterCard();
colorFilter.add(new ColorPredicate(game.getCard(cardToCheck).getColor(game)));
if (cardsToCheck.count(colorFilter, game) > 1) {
++possibleCards;
}
}
return possibleCards > 0;
} }
@Override @Override
public boolean canTarget(UUID id, Game game) { public boolean canTarget(UUID id, Game game) {
if (super.canTarget(id, game)) { if (!super.canTarget(id, game)) {
Card card = game.getCard(id);
if (card != null) {
if (targets.size() == 1) {
Card card2 = game.getCard(targets.entrySet().iterator().next().getKey());
if (card2 != null && card2.getColor(game).equals(card.getColor(game))) {
return true;
}
} else {
FilterCard colorFilter = new FilterCard();
colorFilter.add(new ColorPredicate(card.getColor(game)));
Player player = game.getPlayer(card.getOwnerId());
if (player.getHand().getCards(colorFilter, game).size() > 1) {
return true;
}
}
}
}
return false; return false;
} }
Card card = game.getCard(id);
return card != null
&& this
.getTargets()
.stream()
.map(game::getCard)
.anyMatch(c -> c.getColor(game).shares(card.getColor(game)));
}
@Override @Override
public TargetTwoCardsWithTheSameColorInHand copy() { public IlluminatedFolioTarget copy() {
return new TargetTwoCardsWithTheSameColorInHand(this); return new IlluminatedFolioTarget(this);
} }
} }