Search in sources :

Example 51 with TargetCard

use of mage.target.TargetCard in project mage by magefree.

the class WatchersOfTheDeadEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
    if (controller != null) {
        for (UUID opponentId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player opponent = game.getPlayer(opponentId);
            if (opponent != null && !opponent.equals(controller)) {
                TargetCard target = new TargetCardInYourGraveyard(2, 2, new FilterCard());
                target.setNotTarget(true);
                Cards cardsInGraveyard = opponent.getGraveyard();
                if (cardsInGraveyard.size() > 1) {
                    opponent.choose(outcome, cardsInGraveyard, target, game);
                    for (Card cardInGraveyard : cardsInGraveyard.getCards(game)) {
                        if (!target.getTargets().contains(cardInGraveyard.getId())) {
                            opponent.moveCardToExileWithInfo(cardInGraveyard, CardUtil.getCardExileZoneId(game, source.getId()), sourceObject.getLogName(), source, game, Zone.GRAVEYARD, true);
                        }
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) UUID(java.util.UUID) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard)

Example 52 with TargetCard

use of mage.target.TargetCard in project mage by magefree.

the class AttachEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent sourcePermanent = game.getPermanent(source.getSourceId());
    if (sourcePermanent == null) {
        return false;
    }
    // if it activating on the stack then allow +1 zcc
    int zcc = game.getState().getZoneChangeCounter(sourcePermanent.getId());
    if (zcc != CardUtil.getActualSourceObjectZoneChangeCounter(game, source) && zcc != CardUtil.getActualSourceObjectZoneChangeCounter(game, source) + 1) {
        return false;
    }
    UUID targetId = getTargetPointer().getFirst(game, source);
    Permanent permanent = game.getPermanent(targetId);
    if (permanent != null) {
        return permanent.addAttachment(source.getSourceId(), source, game);
    }
    Player player = game.getPlayer(targetId);
    if (player != null) {
        return player.addAttachment(source.getSourceId(), source, game);
    }
    if (source.getTargets().isEmpty() || !(source.getTargets().get(0) instanceof TargetCard)) {
        return false;
    }
    Card card = game.getCard(targetId);
    return card != null && card.addAttachment(source.getSourceId(), source, game);
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCard(mage.target.TargetCard) UUID(java.util.UUID) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 53 with TargetCard

use of mage.target.TargetCard in project mage by magefree.

the class BenefactionOfRhonasEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (sourceObject != null && controller != null) {
        Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, 5));
        boolean creatureCardFound = false;
        boolean enchantmentCardFound = false;
        for (UUID cardId : cards) {
            Card card = game.getCard(cardId);
            if (card != null) {
                cards.add(card);
                if (card.isCreature(game)) {
                    creatureCardFound = true;
                }
                if (card.isEnchantment(game)) {
                    enchantmentCardFound = true;
                }
            }
        }
        if (!cards.isEmpty()) {
            controller.revealCards(sourceObject.getName(), cards, game);
            if ((creatureCardFound || enchantmentCardFound) && controller.chooseUse(Outcome.DrawCard, "Put a creature card and/or enchantment card into your hand?", source, game)) {
                TargetCard target = new TargetCard(Zone.LIBRARY, new FilterCreatureCard("creature card to put into your hand"));
                if (creatureCardFound && controller.chooseTarget(Outcome.DrawCard, cards, target, source, game)) {
                    Card card = cards.get(target.getFirstTarget(), game);
                    if (card != null) {
                        cards.remove(card);
                        controller.moveCards(card, Zone.HAND, source, game);
                    }
                }
                target = new TargetCard(Zone.LIBRARY, new FilterEnchantmentCard("enchantment card to put into your hand"));
                if (enchantmentCardFound && controller.chooseTarget(Outcome.DrawCard, cards, target, source, game)) {
                    Card card = cards.get(target.getFirstTarget(), game);
                    if (card != null) {
                        cards.remove(card);
                        controller.moveCards(card, Zone.HAND, source, game);
                    }
                }
            }
        }
        controller.moveCards(cards, Zone.GRAVEYARD, source, game);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) FilterCreatureCard(mage.filter.common.FilterCreatureCard) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) FilterEnchantmentCard(mage.filter.common.FilterEnchantmentCard) UUID(java.util.UUID) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) FilterEnchantmentCard(mage.filter.common.FilterEnchantmentCard) FilterCreatureCard(mage.filter.common.FilterCreatureCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 54 with TargetCard

use of mage.target.TargetCard in project mage by magefree.

the class BrunaLightOfAlabasterEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    UUID bruna = source.getSourceId();
    Player controller = game.getPlayer(source.getControllerId());
    FilterPermanent filterAura = new FilterPermanent("Aura");
    FilterCard filterAuraCard = new FilterCard("Aura card");
    filterAura.add(CardType.ENCHANTMENT.getPredicate());
    filterAura.add(SubType.AURA.getPredicate());
    filterAura.add(new AuraPermanentCanAttachToPermanentId(bruna));
    filterAuraCard.add(CardType.ENCHANTMENT.getPredicate());
    filterAuraCard.add(SubType.AURA.getPredicate());
    filterAuraCard.add(new AuraCardCanAttachToPermanentId(bruna));
    if (controller == null) {
        return false;
    }
    Permanent sourcePermanent = game.getPermanent(source.getSourceId());
    if (sourcePermanent == null) {
        return false;
    }
    List<Permanent> fromBattlefield = new ArrayList<>();
    List<Card> fromHandGraveyard = new ArrayList<>();
    int countBattlefield = game.getBattlefield().getAllActivePermanents(filterAura, game).size() - sourcePermanent.getAttachments().size();
    while (controller.canRespond() && countBattlefield > 0 && controller.chooseUse(Outcome.Benefit, "Attach an Aura from the battlefield?", source, game)) {
        Target targetAura = new TargetPermanent(filterAura);
        targetAura.setNotTarget(true);
        if (controller.choose(Outcome.Benefit, targetAura, source.getSourceId(), game)) {
            Permanent aura = game.getPermanent(targetAura.getFirstTarget());
            if (aura != null) {
                Target target = aura.getSpellAbility().getTargets().get(0);
                if (target != null) {
                    fromBattlefield.add(aura);
                    filterAura.add(Predicates.not(new CardIdPredicate(aura.getId())));
                }
            }
        }
        countBattlefield = game.getBattlefield().getAllActivePermanents(filterAura, game).size() - sourcePermanent.getAttachments().size();
    }
    int countHand = controller.getHand().count(filterAuraCard, game);
    while (controller.canRespond() && countHand > 0 && controller.chooseUse(Outcome.Benefit, "Attach an Aura from your hand?", source, game)) {
        TargetCard targetAura = new TargetCard(Zone.HAND, filterAuraCard);
        if (controller.choose(Outcome.Benefit, controller.getHand(), targetAura, game)) {
            Card aura = game.getCard(targetAura.getFirstTarget());
            if (aura != null) {
                Target target = aura.getSpellAbility().getTargets().get(0);
                if (target != null) {
                    fromHandGraveyard.add(aura);
                    filterAuraCard.add(Predicates.not(new CardIdPredicate(aura.getId())));
                }
            }
        }
        countHand = controller.getHand().count(filterAuraCard, game);
    }
    int countGraveyard = controller.getGraveyard().count(filterAuraCard, game);
    while (controller.canRespond() && countGraveyard > 0 && controller.chooseUse(Outcome.Benefit, "Attach an Aura from your graveyard?", source, game)) {
        TargetCard targetAura = new TargetCard(Zone.GRAVEYARD, filterAuraCard);
        if (controller.choose(Outcome.Benefit, controller.getGraveyard(), targetAura, game)) {
            Card aura = game.getCard(targetAura.getFirstTarget());
            if (aura != null) {
                Target target = aura.getSpellAbility().getTargets().get(0);
                if (target != null) {
                    fromHandGraveyard.add(aura);
                    filterAuraCard.add(Predicates.not(new CardIdPredicate(aura.getId())));
                }
            }
        }
        countGraveyard = controller.getGraveyard().count(filterAuraCard, game);
    }
    // Move permanents
    for (Permanent aura : fromBattlefield) {
        Permanent attachedTo = game.getPermanent(aura.getAttachedTo());
        if (attachedTo != null) {
            attachedTo.removeAttachment(aura.getId(), source, game);
        }
        sourcePermanent.addAttachment(aura.getId(), source, game);
    }
    // Move cards
    for (Card aura : fromHandGraveyard) {
        if (aura != null) {
            game.getState().setValue("attachTo:" + aura.getId(), sourcePermanent);
            controller.moveCards(aura, Zone.BATTLEFIELD, source, game);
            sourcePermanent.addAttachment(aura.getId(), source, game);
        }
    }
    return true;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) ArrayList(java.util.ArrayList) TargetCard(mage.target.TargetCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) FilterCard(mage.filter.FilterCard) Target(mage.target.Target) AuraCardCanAttachToPermanentId(mage.filter.predicate.card.AuraCardCanAttachToPermanentId) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID) AuraPermanentCanAttachToPermanentId(mage.filter.predicate.permanent.AuraPermanentCanAttachToPermanentId) CardIdPredicate(mage.filter.predicate.mageobject.CardIdPredicate)

Example 55 with TargetCard

use of mage.target.TargetCard in project mage by magefree.

the class BrowseEffect 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));
        if (!cards.isEmpty()) {
            controller.lookAtCards(source, null, cards, game);
            TargetCard target = new TargetCard(Zone.LIBRARY, new FilterCard("card to put in your hand"));
            if (controller.choose(Outcome.Benefit, cards, target, game)) {
                Card card = cards.get(target.getFirstTarget(), game);
                if (card != null) {
                    controller.moveCards(card, Zone.HAND, source, game);
                    cards.remove(card);
                }
            }
            controller.moveCards(cards, Zone.EXILED, source, game);
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard)

Aggregations

TargetCard (mage.target.TargetCard)309 Player (mage.players.Player)297 FilterCard (mage.filter.FilterCard)177 Card (mage.cards.Card)130 CardsImpl (mage.cards.CardsImpl)96 UUID (java.util.UUID)83 Cards (mage.cards.Cards)81 MageObject (mage.MageObject)80 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)52 Permanent (mage.game.permanent.Permanent)49 TargetCardInYourGraveyard (mage.target.common.TargetCardInYourGraveyard)30 ApprovingObject (mage.ApprovingObject)26 TargetPlayer (mage.target.TargetPlayer)25 FilterCreatureCard (mage.filter.common.FilterCreatureCard)22 TargetOpponent (mage.target.common.TargetOpponent)22 TargetCardInHand (mage.target.common.TargetCardInHand)21 Target (mage.target.Target)19 FilterNonlandCard (mage.filter.common.FilterNonlandCard)18 FixedTarget (mage.target.targetpointer.FixedTarget)18 ArrayList (java.util.ArrayList)16