use of mage.target.common.TargetCardInExile in project mage by magefree.
the class OlagLudevicsHubrisCopyApplier method getCard.
private Card getCard(Cards cards, Ability source, Game game) {
if (cards.size() == 1) {
return cards.getRandom(game);
}
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return cards.getRandom(game);
}
TargetCard target = new TargetCardInExile(StaticFilters.FILTER_CARD);
player.choose(outcome, target, source.getSourceId(), game);
return cards.get(target.getFirstTarget(), game);
}
use of mage.target.common.TargetCardInExile in project mage by magefree.
the class ThievesAuctionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
// Exile all nontoken permanents.
Cards exiledCards = new CardsImpl();
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
exiledCards.add(permanent);
controller.moveCardsToExile(permanent, source, game, true, CardUtil.getCardExileZoneId(game, source.getSourceId()), "Thieves' Auction");
}
// Starting with you, each player
PlayerList playerList = game.getState().getPlayersInRange(controller.getId(), game);
Player player = playerList.getCurrent(game);
while (player != null && !exiledCards.isEmpty() && !game.hasEnded()) {
if (player.canRespond()) {
// chooses one of the exiled cards
TargetCard target = new TargetCardInExile(new FilterCard());
if (player.choose(Outcome.PutCardInPlay, exiledCards, target, game)) {
// and puts it onto the battlefield tapped under their control.
Card chosenCard = exiledCards.get(target.getFirstTarget(), game);
if (chosenCard != null) {
player.moveCards(chosenCard, Zone.BATTLEFIELD, source, game, true, false, false, null);
}
exiledCards.remove(chosenCard);
} else {
break;
}
}
// Repeat this process until all cards exiled this way have been chosen.
player = playerList.getNext(game, false);
}
return true;
}
return false;
}
use of mage.target.common.TargetCardInExile in project mage by magefree.
the class VillainousWealthEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject mageObject = game.getObject(source.getSourceId());
if (controller != null && mageObject != null) {
Player player = game.getPlayer(targetPointer.getFirst(game, source));
FilterCard filter = new FilterNonlandCard();
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, source.getManaCostsToPay().getX() + 1));
UUID exileId = CardUtil.getCardExileZoneId(game, source);
if (player != null) {
Cards cardsToExile = new CardsImpl();
cardsToExile.addAll(player.getLibrary().getTopCards(game, source.getManaCostsToPay().getX()));
controller.moveCards(cardsToExile, Zone.EXILED, source, game);
if (controller.chooseUse(Outcome.PlayForFree, "Cast cards exiled with " + mageObject.getLogName() + " without paying its mana cost?", source, game)) {
OuterLoop: while (cardsToExile.count(filter, game) > 0) {
if (!controller.canRespond()) {
return false;
}
TargetCardInExile target = new TargetCardInExile(0, 1, filter, exileId, false);
target.setNotTarget(true);
while (controller.canRespond() && cardsToExile.count(filter, game) > 0 && controller.choose(Outcome.PlayForFree, cardsToExile, target, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
Boolean cardWasCast = controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
if (cardWasCast) {
cardsToExile.remove(card);
}
} else {
break OuterLoop;
}
target.clearChosen();
}
}
}
}
return true;
}
return false;
}
use of mage.target.common.TargetCardInExile in project mage by magefree.
the class CustomTestCard method addCustomEffect_ReturnFromAnyToHand.
/**
* Return target card to hand that can be called by text "return from ..."
*
* @param controller
*/
protected void addCustomEffect_ReturnFromAnyToHand(TestPlayer controller) {
// graveyard
Ability ability = new SimpleActivatedAbility(new ReturnFromGraveyardToHandTargetEffect().setText("return from graveyard"), new ManaCostsImpl(""));
ability.addTarget(new TargetCardInGraveyard(StaticFilters.FILTER_CARD));
addCustomCardWithAbility("return from graveyard for " + controller.getName(), controller, ability);
// exile
ability = new SimpleActivatedAbility(new ReturnFromExileEffect(Zone.HAND).setText("return from exile"), new ManaCostsImpl(""));
ability.addTarget(new TargetCardInExile(StaticFilters.FILTER_CARD));
addCustomCardWithAbility("return from exile for " + controller.getName(), controller, ability);
// library
ability = new SimpleActivatedAbility(new SearchLibraryPutInHandEffect(new TargetCardInLibrary(StaticFilters.FILTER_CARD)).setText("return from library"), new ManaCostsImpl(""));
addCustomCardWithAbility("return from library for " + controller.getName(), controller, ability);
}
use of mage.target.common.TargetCardInExile in project mage by magefree.
the class EtherealForagerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
String keyString = CardUtil.getCardZoneString("delvedCards", source.getSourceId(), game, true);
Cards delvedCards = (Cards) game.getState().getValue(keyString);
if (delvedCards == null || delvedCards.count(StaticFilters.FILTER_CARD_INSTANT_AND_SORCERY, game) < 1) {
return false;
}
TargetCard targetCard = new TargetCardInExile(0, 1, StaticFilters.FILTER_CARD_INSTANT_OR_SORCERY, null, true);
;
player.choose(Outcome.DrawCard, delvedCards, targetCard, game);
Card card = game.getCard(targetCard.getFirstTarget());
if (card == null || !player.moveCards(card, Zone.HAND, source, game)) {
return false;
}
delvedCards.remove(card);
return true;
}
Aggregations