use of mage.target.TargetCard in project mage by magefree.
the class GiftsUngivenTarget method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Card sourceCard = game.getCard(source.getSourceId());
if (player == null || sourceCard == null) {
return false;
}
Player opponent = game.getPlayer(getTargetPointer().getFirst(game, source));
if (opponent == null) {
return false;
}
GiftsUngivenTarget target = new GiftsUngivenTarget();
if (player.searchLibrary(target, source, game)) {
if (!target.getTargets().isEmpty()) {
Cards cards = new CardsImpl();
for (UUID cardId : target.getTargets()) {
Card card = player.getLibrary().remove(cardId, game);
if (card != null) {
cards.add(card);
}
}
player.revealCards(sourceCard.getIdName(), cards, game);
CardsImpl cardsToKeep = new CardsImpl();
if (cards.size() > 2) {
cardsToKeep.addAll(cards);
TargetCard targetDiscard = new TargetCard(2, Zone.LIBRARY, new FilterCard("cards to put in graveyard"));
if (opponent.choose(Outcome.Discard, cards, targetDiscard, game)) {
cardsToKeep.removeAll(targetDiscard.getTargets());
cards.removeAll(cardsToKeep);
}
}
player.moveCards(cards, Zone.GRAVEYARD, source, game);
player.moveCards(cardsToKeep, Zone.HAND, source, game);
}
player.shuffleLibrary(source, game);
return true;
}
player.shuffleLibrary(source, game);
return false;
}
use of mage.target.TargetCard in project mage by magefree.
the class GrislySalvageEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, 5));
boolean properCardFound = cards.count(filterPutInHand, game) > 0;
if (!cards.isEmpty()) {
controller.revealCards(source, cards, game);
TargetCard target = new TargetCard(Zone.LIBRARY, filterPutInHand);
if (properCardFound && controller.chooseUse(outcome, "Put a creature or land card from the revealed cards into your hand?", source, game) && controller.choose(Outcome.DrawCard, cards, target, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
controller.moveCards(card, Zone.HAND, source, game);
cards.remove(card);
}
}
controller.moveCards(cards, Zone.GRAVEYARD, source, game);
}
return true;
}
return false;
}
use of mage.target.TargetCard in project mage by magefree.
the class HellcarverDemonEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent sourceObject = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (controller != null && sourceObject != null) {
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(source.getControllerId())) {
if (!Objects.equals(permanent, sourceObject)) {
permanent.sacrifice(source, game);
}
}
if (!controller.getHand().isEmpty()) {
int cardsInHand = controller.getHand().size();
controller.discard(cardsInHand, false, false, source, game);
}
// move cards from library to exile
Set<Card> currentExiledCards = new HashSet<>();
currentExiledCards.addAll(controller.getLibrary().getTopCards(game, 6));
controller.moveCardsToExile(currentExiledCards, source, game, true, source.getSourceId(), sourceObject.getIdName());
// cast the possible cards without paying the mana
Cards cardsToCast = new CardsImpl();
cardsToCast.addAll(currentExiledCards);
boolean alreadyCast = false;
while (controller.canRespond() && !cardsToCast.isEmpty()) {
if (!controller.chooseUse(outcome, "Cast a" + (alreadyCast ? "another" : "") + " card exiled with " + sourceObject.getLogName() + " without paying its mana cost?", source, game)) {
break;
}
TargetCard targetCard = new TargetCard(1, Zone.EXILED, new FilterNonlandCard("nonland card to cast for free"));
if (controller.choose(Outcome.PlayForFree, cardsToCast, targetCard, game)) {
alreadyCast = true;
Card card = game.getCard(targetCard.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);
cardsToCast.remove(card);
if (!cardWasCast) {
game.informPlayer(controller, "You're not able to cast " + card.getIdName() + " or you canceled the casting.");
}
}
}
}
return true;
}
return false;
}
use of mage.target.TargetCard in project mage by magefree.
the class MundaAmbushLeaderEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (controller != null && sourceObject != null) {
Cards allCards = new CardsImpl();
allCards.addAll(controller.getLibrary().getTopCards(game, 4));
controller.lookAtCards(sourceObject.getIdName(), allCards, game);
if (!allCards.isEmpty()) {
Cards cardsToReveal = new CardsImpl();
TargetCard target = new TargetCard(0, Integer.MAX_VALUE, Zone.LIBRARY, filter);
controller.chooseTarget(outcome, allCards, target, source, game);
cardsToReveal.addAll(target.getTargets());
if (!cardsToReveal.isEmpty()) {
controller.revealCards(sourceObject.getIdName(), cardsToReveal, game, true);
allCards.removeAll(cardsToReveal);
}
controller.putCardsOnTopOfLibrary(cardsToReveal, game, source, true);
}
if (!allCards.isEmpty()) {
controller.putCardsOnBottomOfLibrary(allCards, game, source, true);
}
return true;
}
return false;
}
use of mage.target.TargetCard in project mage by magefree.
the class OKagachiMadeManifestEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player player = game.getPlayer(getTargetPointer().getFirst(game, source));
if (controller == null || player == null) {
return false;
}
Card card;
switch(controller.getGraveyard().count(StaticFilters.FILTER_CARD_A_NON_LAND, game)) {
case 0:
return false;
case 1:
card = controller.getGraveyard().getCards(StaticFilters.FILTER_CARD_A_NON_LAND, game).stream().findFirst().orElse(null);
break;
default:
TargetCard target = new TargetCardInGraveyard(StaticFilters.FILTER_CARD_A_NON_LAND);
target.setNotTarget(true);
player.choose(Outcome.ReturnToHand, controller.getGraveyard(), target, game);
card = game.getCard(target.getFirstTarget());
}
if (card == null) {
return false;
}
int manaValue = card.getManaValue();
player.moveCards(card, Zone.HAND, source, game);
if (manaValue > 0) {
game.addEffect(new BoostSourceEffect(manaValue, 0, Duration.EndOfTurn), source);
}
return true;
}
Aggregations