// reveal hand of target player
targetPlayer.revealCards(sourceObject.getLogName(), targetPlayer.getHand(), game);
// You choose a nonland card from it
TargetCardInHand target = new TargetCardInHand(new FilterNonlandCard());
target.setNotTarget(true);
Card chosenCard = null;
if (controller.choose(Outcome.Benefit, targetPlayer.getHand(), target, game)) {
chosenCard = game.getCard(target.getFirstTarget());
}
// Exile all cards with the same name
// Building a card filter with the name
FilterCard filterNamedCards = new FilterCard();
if (chosenCard != null) {
filterNamedCards.add(new NamePredicate(chosenCard.getName()));
} else {
filterNamedCards.add(new NamePredicate("----")); // so no card matches
}
// The cards you're searching for must be found and exiled if they're in the graveyard because it's a public zone.
// Finding those cards in the hand and library is optional, because those zones are hidden (even if the hand is temporarily revealed).
// search cards in graveyard
if (chosenCard != null) {
for (Card checkCard : targetPlayer.getGraveyard().getCards(game)) {
if (checkCard.getName().equals(chosenCard.getName())) {
controller.moveCardToExileWithInfo(checkCard, null, "", source.getSourceId(), game, Zone.GRAVEYARD);
}
}
// search cards in hand
TargetCardInHand targetCardsHand = new TargetCardInHand(0, Integer.MAX_VALUE, filterNamedCards);
controller.chooseTarget(outcome, targetPlayer.getGraveyard(), targetCardsHand, source, game);
for(UUID cardId: targetCardsHand.getTargets()) {
Card card = game.getCard(cardId);
if (card != null) {
controller.moveCardToExileWithInfo(card, null, "", source.getSourceId(), game, Zone.HAND);
}
}