Search in sources :

Example 31 with FilterPermanent

use of mage.filter.FilterPermanent in project mage by magefree.

the class WorldBottlingKitEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        ChooseExpansionSetEffect effect = new ChooseExpansionSetEffect(Outcome.Exile);
        effect.apply(game, source);
        String setChosen = null;
        if (effect.getValue("setchosen") != null) {
            setChosen = (String) effect.getValue("setchosen");
        } else if (game.getState().getValue(this.getId() + "_set") != null) {
            setChosen = (String) game.getState().getValue(this.getId() + "_set");
        }
        if (setChosen != null) {
            game.informPlayers(controller.getLogName() + " has chosen set " + setChosen);
            FilterPermanent filter = new FilterPermanent();
            filter.add(Predicates.not(Predicates.and(CardType.LAND.getPredicate(), SuperType.BASIC.getPredicate())));
            List<Permanent> permanents = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game);
            for (Permanent permanent : permanents) {
                if (permanent.getExpansionSetCode().equals(setChosen)) {
                    controller.moveCardToExileWithInfo(permanent, null, "", source, game, Zone.BATTLEFIELD, true);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) ChooseExpansionSetEffect(mage.abilities.effects.common.ChooseExpansionSetEffect)

Example 32 with FilterPermanent

use of mage.filter.FilterPermanent 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 33 with FilterPermanent

use of mage.filter.FilterPermanent in project mage by magefree.

the class DralnuLichLordFlashbackEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    DamageEvent damageEvent = (DamageEvent) event;
    new SacrificeControllerEffect(new FilterPermanent(), damageEvent.getAmount(), "").apply(game, source);
    return true;
}
Also used : FilterPermanent(mage.filter.FilterPermanent) SacrificeControllerEffect(mage.abilities.effects.common.SacrificeControllerEffect) DamageEvent(mage.game.events.DamageEvent)

Example 34 with FilterPermanent

use of mage.filter.FilterPermanent in project mage by magefree.

the class GoblinVandalTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    Permanent sourcePermanent = game.getPermanent(getSourceId());
    if (sourcePermanent.isAttacking()) {
        for (CombatGroup combatGroup : game.getCombat().getGroups()) {
            if (combatGroup.getBlockers().isEmpty() && combatGroup.getAttackers().contains(getSourceId())) {
                UUID defendingPlayerId = game.getCombat().getDefendingPlayerId(getSourceId(), game);
                FilterPermanent filter = new FilterArtifactPermanent();
                filter.add(new ControllerIdPredicate(defendingPlayerId));
                Target target = new TargetPermanent(filter);
                this.addTarget(target);
                return true;
            }
        }
    }
    return false;
}
Also used : FilterArtifactPermanent(mage.filter.common.FilterArtifactPermanent) Target(mage.target.Target) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterArtifactPermanent(mage.filter.common.FilterArtifactPermanent) TargetPermanent(mage.target.TargetPermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID) CombatGroup(mage.game.combat.CombatGroup)

Example 35 with FilterPermanent

use of mage.filter.FilterPermanent in project mage by magefree.

the class LichsMasteryLoseLifeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    FilterPermanent filter = new FilterPermanent();
    filter.add(new ControllerIdPredicate(controller.getId()));
    for (int i = 0; i < amount; i++) {
        int handCount = controller.getHand().size();
        int graveCount = controller.getGraveyard().size();
        int permCount = game.getBattlefield().getActivePermanents(filter, controller.getId(), game).size();
        if (graveCount + handCount == 0 || (permCount > 0 && controller.chooseUse(Outcome.Exile, "Exile permanent you control? (No = from hand or graveyard)", source, game))) {
            Target target = new TargetControlledPermanent(1, 1, new FilterControlledPermanent(), true);
            controller.choose(outcome, target, source.getSourceId(), game);
            Effect effect = new ExileTargetEffect();
            effect.setTargetPointer(new FixedTarget(target.getFirstTarget(), game));
            effect.apply(game, source);
        } else if (graveCount == 0 || (handCount > 0 && controller.chooseUse(Outcome.Exile, "Exile a card from your hand? (No = from graveyard)", source, game))) {
            Target target = new TargetCardInHand(1, 1, new FilterCard());
            controller.choose(outcome, target, source.getSourceId(), game);
            Card card = controller.getHand().get(target.getFirstTarget(), game);
            if (card != null) {
                controller.moveCards(card, Zone.EXILED, source, game);
            }
        } else if (graveCount > 0) {
            Target target = new TargetCardInYourGraveyard(1, 1, new FilterCard(), true);
            target.choose(Outcome.Exile, source.getControllerId(), source.getSourceId(), game);
            Card card = controller.getGraveyard().get(target.getFirstTarget(), game);
            if (card != null) {
                controller.moveCards(card, Zone.EXILED, source, game);
            }
        }
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) TargetCardInHand(mage.target.common.TargetCardInHand) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) FilterCard(mage.filter.FilterCard) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) DrawCardSourceControllerEffect(mage.abilities.effects.common.DrawCardSourceControllerEffect) ExileTargetEffect(mage.abilities.effects.common.ExileTargetEffect) LoseGameSourceControllerEffect(mage.abilities.effects.common.LoseGameSourceControllerEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) ExileTargetEffect(mage.abilities.effects.common.ExileTargetEffect)

Aggregations

FilterPermanent (mage.filter.FilterPermanent)155 Permanent (mage.game.permanent.Permanent)99 Player (mage.players.Player)99 TargetPermanent (mage.target.TargetPermanent)62 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)49 UUID (java.util.UUID)41 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)30 Target (mage.target.Target)24 PermanentIdPredicate (mage.filter.predicate.permanent.PermanentIdPredicate)18 ColorPredicate (mage.filter.predicate.mageobject.ColorPredicate)17 NamePredicate (mage.filter.predicate.mageobject.NamePredicate)16 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)14 OneShotEffect (mage.abilities.effects.OneShotEffect)13 Card (mage.cards.Card)13 FixedTarget (mage.target.targetpointer.FixedTarget)13 FilterCard (mage.filter.FilterCard)11 FilterNonlandPermanent (mage.filter.common.FilterNonlandPermanent)11 ManaValuePredicate (mage.filter.predicate.mageobject.ManaValuePredicate)11 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)11 CardsImpl (mage.cards.CardsImpl)10