Search in sources :

Example 6 with AuraCardCanAttachToPermanentId

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

the class LightPawsEmperorsVoiceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent aura = (Permanent) getValue("permanentEnteringBattlefield");
    if (player == null || aura == null || !player.chooseUse(outcome, "Search for an Aura?", source, game)) {
        return false;
    }
    FilterCard filter = new FilterCard("Aura card with mana value less than or equal to " + aura.getManaValue());
    filter.add(SubType.AURA.getPredicate());
    filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, aura.getManaValue() + 1));
    filter.add(LightPawsEmperorsVoiceEffectPredicate.instance);
    TargetCardInLibrary target = new TargetCardInLibrary(filter);
    player.searchLibrary(target, source, game);
    Card card = player.getLibrary().getCard(target.getFirstTarget(), game);
    Permanent permanent = source.getSourcePermanentIfItStillExists(game);
    if (card != null && permanent != null && new AuraCardCanAttachToPermanentId(permanent.getId()).apply(card, game)) {
        game.getState().setValue("attachTo:" + card.getId(), permanent);
        player.moveCards(card, Zone.BATTLEFIELD, source, game);
        permanent.addAttachment(card.getId(), source, game);
    }
    player.shuffleLibrary(source, game);
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ObjectSourcePlayer(mage.filter.predicate.ObjectSourcePlayer) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) FilterPermanent(mage.filter.FilterPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) 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 7 with AuraCardCanAttachToPermanentId

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

the class HolyAvengerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = source.getSourcePermanentOrLKI(game);
    if (player == null || sourcePermanent == null) {
        return false;
    }
    Permanent permanent = game.getPermanent(sourcePermanent.getAttachedTo());
    if (permanent == null) {
        return false;
    }
    FilterCard filter = new FilterCard("an Aura than can enchant " + permanent.getName());
    filter.add(SubType.AURA.getPredicate());
    filter.add(new AuraCardCanAttachToPermanentId(permanent.getId()));
    TargetCardInHand target = new TargetCardInHand(0, 1, filter);
    player.choose(Outcome.PutCardInPlay, player.getHand(), target, game);
    Card card = game.getCard(target.getFirstTarget());
    if (card == null) {
        return false;
    }
    game.getState().setValue("attachTo:" + card.getId(), permanent);
    player.moveCards(card, Zone.BATTLEFIELD, source, game);
    if (!permanent.addAttachment(card.getId(), source, game)) {
        return false;
    }
    game.informPlayers(player.getLogName() + " put " + card.getLogName() + " on the battlefield attached to " + permanent.getLogName() + '.');
    return true;
}
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 8 with AuraCardCanAttachToPermanentId

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

the class EvershrikeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Card evershrikeCard = game.getCard(source.getSourceId());
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null || evershrikeCard == null) {
        return false;
    }
    int xAmount = source.getManaCostsToPay().getX();
    controller.moveCards(evershrikeCard, Zone.BATTLEFIELD, source, game);
    Permanent evershrikePermanent = game.getPermanent(evershrikeCard.getId());
    if (evershrikePermanent == null) {
        if (game.getState().getZone(evershrikeCard.getId()) != Zone.EXILED) {
            controller.moveCards(evershrikeCard, Zone.EXILED, source, game);
        }
        return false;
    }
    boolean exileSource = true;
    FilterCard filterAuraCard = new FilterCard("Aura card with mana value X or less from your hand");
    filterAuraCard.add(CardType.ENCHANTMENT.getPredicate());
    filterAuraCard.add(SubType.AURA.getPredicate());
    filterAuraCard.add(new AuraCardCanAttachToPermanentId(evershrikePermanent.getId()));
    filterAuraCard.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, xAmount + 1));
    int count = controller.getHand().count(filterAuraCard, game);
    if (count > 0 && controller.chooseUse(Outcome.Benefit, "Put an Aura card from your hand onto the battlefield attached to " + evershrikeCard.getIdName() + "?", 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) {
                game.getState().setValue("attachTo:" + aura.getId(), evershrikePermanent);
                if (controller.moveCards(aura, Zone.BATTLEFIELD, source, game)) {
                    evershrikePermanent.addAttachment(aura.getId(), source, game);
                }
                exileSource = false;
            }
        }
    }
    if (exileSource) {
        controller.moveCards(evershrikeCard, Zone.EXILED, source, game);
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) Permanent(mage.game.permanent.Permanent) AuraCardCanAttachToPermanentId(mage.filter.predicate.card.AuraCardCanAttachToPermanentId) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 9 with AuraCardCanAttachToPermanentId

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

the class IridescentDrakeEffect method apply.

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