Search in sources :

Example 1 with AuraCardCanAttachToPermanentId

use of mage.filter.predicate.card.AuraCardCanAttachToPermanentId in project mage by magefree.

the class AcademyResearchersEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    FilterCard filterCardInHand = new FilterCard();
    filterCardInHand.add(SubType.AURA.getPredicate());
    Player controller = game.getPlayer(source.getControllerId());
    Permanent academyResearchers = game.getPermanent(source.getSourceId());
    if (controller != null && academyResearchers != null) {
        filterCardInHand.add(new AuraCardCanAttachToPermanentId(academyResearchers.getId()));
        TargetCardInHand target = new TargetCardInHand(0, 1, filterCardInHand);
        if (controller.choose(Outcome.PutCardInPlay, target, source.getSourceId(), game)) {
            Card auraInHand = game.getCard(target.getFirstTarget());
            if (auraInHand != null) {
                game.getState().setValue("attachTo:" + auraInHand.getId(), academyResearchers);
                controller.moveCards(auraInHand, Zone.BATTLEFIELD, source, game);
                if (academyResearchers.addAttachment(auraInHand.getId(), source, game)) {
                    game.informPlayers(controller.getLogName() + " put " + auraInHand.getLogName() + " on the battlefield attached to " + academyResearchers.getLogName() + '.');
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) AuraCardCanAttachToPermanentId(mage.filter.predicate.card.AuraCardCanAttachToPermanentId) TargetCardInHand(mage.target.common.TargetCardInHand) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 2 with AuraCardCanAttachToPermanentId

use of mage.filter.predicate.card.AuraCardCanAttachToPermanentId in project mage by magefree.

the class SovereignsOfLostAlaraEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent attackingCreature = game.getPermanent(getTargetPointer().getFirst(game, source));
    if (controller != null && attackingCreature != null) {
        FilterCard filter = new FilterCard("aura that could enchant the lone attacking creature");
        filter.add(SubType.AURA.getPredicate());
        filter.add(new AuraCardCanAttachToPermanentId(attackingCreature.getId()));
        if (controller.chooseUse(Outcome.Benefit, "Search your library?", source, game)) {
            TargetCardInLibrary target = new TargetCardInLibrary(filter);
            target.setNotTarget(true);
            if (controller.searchLibrary(target, source, game)) {
                if (target.getFirstTarget() != null) {
                    Card aura = game.getCard(target.getFirstTarget());
                    game.getState().setValue("attachTo:" + aura.getId(), attackingCreature);
                    controller.moveCards(aura, Zone.BATTLEFIELD, source, game);
                    attackingCreature.addAttachment(aura.getId(), source, game);
                }
            }
        }
        controller.shuffleLibrary(source, game);
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) AuraCardCanAttachToPermanentId(mage.filter.predicate.card.AuraCardCanAttachToPermanentId) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 3 with AuraCardCanAttachToPermanentId

use of mage.filter.predicate.card.AuraCardCanAttachToPermanentId 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 4 with AuraCardCanAttachToPermanentId

use of mage.filter.predicate.card.AuraCardCanAttachToPermanentId in project mage by magefree.

the class HakimLoreweaverPredicate method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent hakimLoreweaver = game.getPermanent(source.getSourceId());
    Card targetAuraCard = game.getCard(source.getFirstTarget());
    if (controller != null && hakimLoreweaver != null && controller.canRespond() && targetAuraCard != null && new AuraCardCanAttachToPermanentId(hakimLoreweaver.getId()).apply(targetAuraCard, game)) {
        Target target = targetAuraCard.getSpellAbility().getTargets().get(0);
        if (target != null) {
            game.getState().setValue("attachTo:" + targetAuraCard.getId(), hakimLoreweaver);
            controller.moveCards(targetAuraCard, Zone.BATTLEFIELD, source, game);
            return hakimLoreweaver.addAttachment(targetAuraCard.getId(), source, game);
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) AuraCardCanAttachToPermanentId(mage.filter.predicate.card.AuraCardCanAttachToPermanentId) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Example 5 with AuraCardCanAttachToPermanentId

use of mage.filter.predicate.card.AuraCardCanAttachToPermanentId in project mage by magefree.

the class AuraSwapEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    FilterCard filterCardToCheck = new FilterCard();
    filterCardToCheck.add(SubType.AURA.getPredicate());
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Permanent auraSourcePermanent = game.getPermanent(source.getSourceId());
        if (auraSourcePermanent != null && auraSourcePermanent.hasSubtype(SubType.AURA, game) && auraSourcePermanent.isOwnedBy(source.getControllerId())) {
            Permanent enchantedPermanent = game.getPermanent(auraSourcePermanent.getAttachedTo());
            filterCardToCheck.add(new AuraCardCanAttachToPermanentId(enchantedPermanent.getId()));
            TargetCardInHand target = new TargetCardInHand(filterCardToCheck);
            if (controller.choose(Outcome.PutCardInPlay, target, source.getSourceId(), game)) {
                Card auraInHand = game.getCard(target.getFirstTarget());
                if (auraInHand != null) {
                    game.getState().setValue("attachTo:" + auraInHand.getId(), enchantedPermanent);
                    controller.moveCards(auraInHand, Zone.BATTLEFIELD, source, game);
                    enchantedPermanent.addAttachment(auraInHand.getId(), source, game);
                    game.informPlayers(controller.getLogName() + " put " + auraInHand.getLogName() + " on the battlefield attached to " + enchantedPermanent.getLogName() + '.');
                    enchantedPermanent.removeAttachment(auraSourcePermanent.getId(), source, game);
                    return controller.moveCards(auraSourcePermanent, Zone.HAND, source, game);
                }
            }
        }
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) AuraCardCanAttachToPermanentId(mage.filter.predicate.card.AuraCardCanAttachToPermanentId) TargetCardInHand(mage.target.common.TargetCardInHand) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Aggregations

Card (mage.cards.Card)9 FilterCard (mage.filter.FilterCard)9 AuraCardCanAttachToPermanentId (mage.filter.predicate.card.AuraCardCanAttachToPermanentId)9 Permanent (mage.game.permanent.Permanent)9 Player (mage.players.Player)9 FilterPermanent (mage.filter.FilterPermanent)3 Target (mage.target.Target)3 TargetCardInHand (mage.target.common.TargetCardInHand)3 ManaValuePredicate (mage.filter.predicate.mageobject.ManaValuePredicate)2 TargetCard (mage.target.TargetCard)2 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)2 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)1 ObjectSourcePlayer (mage.filter.predicate.ObjectSourcePlayer)1 CardIdPredicate (mage.filter.predicate.mageobject.CardIdPredicate)1 AuraPermanentCanAttachToPermanentId (mage.filter.predicate.permanent.AuraPermanentCanAttachToPermanentId)1 TargetPermanent (mage.target.TargetPermanent)1