use of mage.target.TargetCard in project mage by magefree.
the class InsidiousDreamsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
int amount = GetXValue.instance.calculate(game, source, this);
if (controller != null && sourceObject != null) {
TargetCardInLibrary target = new TargetCardInLibrary(0, amount, new FilterCard());
if (controller.searchLibrary(target, source, game)) {
Cards chosen = new CardsImpl();
for (UUID cardId : target.getTargets()) {
Card card = controller.getLibrary().remove(cardId, game);
chosen.add(card);
}
controller.shuffleLibrary(source, game);
TargetCard targetToLib = new TargetCard(Zone.LIBRARY, new FilterCard(textTop));
while (chosen.size() > 1 && controller.canRespond()) {
controller.choose(Outcome.Neutral, chosen, targetToLib, game);
Card card = chosen.get(targetToLib.getFirstTarget(), game);
if (card != null) {
chosen.remove(card);
controller.moveCardToLibraryWithInfo(card, source, game, Zone.LIBRARY, true, false);
}
targetToLib.clearChosen();
}
if (chosen.size() == 1) {
Card card = chosen.get(chosen.iterator().next(), game);
controller.moveCardToLibraryWithInfo(card, source, game, Zone.LIBRARY, true, false);
}
}
return true;
}
return false;
}
use of mage.target.TargetCard in project mage by magefree.
the class KingNarfisBetrayalSecondEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
UUID controllerId = source.getControllerId();
Player controller = game.getPlayer(controllerId);
if (controller == null) {
return false;
}
millEffect.apply(game, source);
// Controller graveyard
if (controller.getGraveyard().count(filter, game) != 0) {
if (controller.chooseUse(outcome, "Exile a creature or planeswalker card from your graveyard?", source, game)) {
TargetCard target = new TargetCardInYourGraveyard(filter);
target.setNotTarget(true);
if (controller.chooseTarget(outcome, controller.getGraveyard(), target, source, game)) {
controller.moveCardsToExile(game.getCard(target.getFirstTarget()), source, game, true, CardUtil.getCardExileZoneId(game, source), CardUtil.createObjectRealtedWindowTitle(source, game, null));
}
}
}
// Each opponent's graveyard
for (UUID opponentId : game.getOpponents(controllerId)) {
Player opponent = game.getPlayer(opponentId);
if (opponent == null) {
continue;
}
if (opponent.getGraveyard().count(filter, game) != 0) {
if (controller.chooseUse(outcome, "Exile a creature or planeswalker card from " + opponent.getName() + "'s graveyard?", source, game)) {
TargetCard target = new TargetCardInOpponentsGraveyard(1, 1, filter, true);
target.setNotTarget(true);
if (controller.chooseTarget(outcome, opponent.getGraveyard(), target, source, game)) {
controller.moveCardsToExile(game.getCard(target.getFirstTarget()), source, game, true, CardUtil.getCardExileZoneId(game, source), CardUtil.createObjectRealtedWindowTitle(source, game, null));
}
}
}
}
return true;
}
use of mage.target.TargetCard in project mage by magefree.
the class MindleechMassEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player opponent = game.getPlayer(getTargetPointer().getFirst(game, source));
Player controller = game.getPlayer(source.getControllerId());
if (opponent != null && controller != null) {
Cards cardsInHand = new CardsImpl();
cardsInHand.addAll(opponent.getHand());
opponent.revealCards("Opponents hand", cardsInHand, game);
if (!cardsInHand.isEmpty() && !cardsInHand.getCards(new FilterNonlandCard(), game).isEmpty()) {
TargetCard target = new TargetCard(1, Zone.HAND, new FilterNonlandCard());
if (controller.chooseTarget(Outcome.PlayForFree, cardsInHand, target, source, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
}
}
}
return true;
}
return false;
}
use of mage.target.TargetCard in project mage by magefree.
the class MindWarpEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player targetPlayer = game.getPlayer(source.getFirstTarget());
Player you = game.getPlayer(source.getControllerId());
if (targetPlayer == null || you == null) {
return false;
}
int amountToDiscard = source.getManaCostsToPay().getX();
TargetCard target = new TargetCardInHand(amountToDiscard, StaticFilters.FILTER_CARD_CARDS);
you.choose(outcome, targetPlayer.getHand(), target, game);
targetPlayer.discard(new CardsImpl(target.getTargets()), false, source, game);
return true;
}
use of mage.target.TargetCard in project mage by magefree.
the class PhyrexianPortalEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player opponent = game.getPlayer(source.getFirstTarget());
if (controller != null && opponent != null) {
if (controller.getLibrary().size() >= 10) {
Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, 10));
TargetCard target = new TargetCard(0, cards.size(), Zone.LIBRARY, new FilterCard("cards to put in the first pile"));
List<Card> pile1 = new ArrayList<>();
if (opponent.choose(Outcome.Neutral, cards, target, game)) {
List<UUID> targets = target.getTargets();
for (UUID targetId : targets) {
Card card = cards.get(targetId, game);
if (card != null) {
pile1.add(card);
cards.remove(card);
}
}
}
List<Card> pile2 = new ArrayList<>();
pile2.addAll(cards.getCards(game));
game.informPlayers(opponent.getLogName() + " separated the top 10 cards of " + controller.getLogName() + "'s library into two face-down piles (" + pile1.size() + " cards and " + pile2.size() + " cards)");
// it's not viable to turn cards face down here for choosePile (since they're still library cards), this is a workaround
boolean choice = controller.chooseUse(outcome, "Choose pile to search for a card (the other will be exiled):", source.getSourceObject(game).getLogName(), "Pile 1 (" + pile1.size() + " cards)", "Pile 2 (" + pile2.size() + " cards)", source, game);
game.informPlayers(controller.getLogName() + " chooses to search the " + (choice ? "first" : "second") + " pile");
Cards pileToExile = new CardsImpl();
pileToExile.addAll(choice ? pile2 : pile1);
controller.moveCardsToExile(pileToExile.getCards(game), source, game, true, null, "");
Cards chosenPile = new CardsImpl();
chosenPile.addAll(choice ? pile1 : pile2);
TargetCard target2 = new TargetCard(Zone.HAND, new FilterCard("card to put into your hand"));
if (controller.choose(outcome, chosenPile, target2, game)) {
Card card = chosenPile.get(target2.getFirstTarget(), game);
if (card != null) {
controller.moveCards(card, Zone.HAND, source, game);
}
}
controller.shuffleLibrary(source, game);
}
return true;
}
return false;
}
Aggregations