Search in sources :

Example 21 with PermanentIdPredicate

use of mage.filter.predicate.permanent.PermanentIdPredicate in project mage by magefree.

the class OrvarTheAllFormEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Spell spell = (Spell) this.getValue("spellCast");
    if (player == null || spell == null) {
        return false;
    }
    List<Predicate<Permanent>> predicates = spell.getSpellAbility().getModes().values().stream().map(Mode::getTargets).flatMap(Collection::stream).map(Target::getTargets).flatMap(Collection::stream).map(game::getPermanent).filter(Objects::nonNull).map(MageItem::getId).map(PermanentIdPredicate::new).collect(Collectors.toList());
    if (predicates.isEmpty()) {
        return false;
    }
    FilterPermanent filter = new FilterControlledPermanent("a permanent you control targeted by that spell");
    filter.add(Predicates.or(predicates));
    filter.add(Predicates.not(new MageObjectReferencePredicate(new MageObjectReference(source))));
    TargetPermanent target = new TargetPermanent(filter);
    target.setNotTarget(true);
    player.choose(outcome, target, source.getSourceId(), game);
    return new CreateTokenCopyTargetEffect().setTargetPointer(new FixedTarget(target.getFirstTarget(), game)).apply(game, source);
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) Mode(mage.abilities.Mode) MageItem(mage.MageItem) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Spell(mage.game.stack.Spell) PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) Predicate(mage.filter.predicate.Predicate) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) TargetPermanent(mage.target.TargetPermanent) CreateTokenCopyTargetEffect(mage.abilities.effects.common.CreateTokenCopyTargetEffect) MageObjectReference(mage.MageObjectReference)

Example 22 with PermanentIdPredicate

use of mage.filter.predicate.permanent.PermanentIdPredicate in project mage by magefree.

the class PublicExecutionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent target = (Permanent) game.getLastKnownInformation(source.getFirstTarget(), Zone.BATTLEFIELD);
    if (target != null) {
        UUID opponent = target.getControllerId();
        if (opponent != null) {
            FilterCreaturePermanent filter = new FilterCreaturePermanent("each other creature that player controls");
            filter.add(new ControllerIdPredicate(opponent));
            filter.add(Predicates.not(new PermanentIdPredicate(target.getId())));
            ContinuousEffect effect = new BoostAllEffect(-2, 0, Duration.EndOfTurn, filter, false);
            game.addEffect(effect, source);
            return true;
        }
    }
    return false;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) BoostAllEffect(mage.abilities.effects.common.continuous.BoostAllEffect)

Example 23 with PermanentIdPredicate

use of mage.filter.predicate.permanent.PermanentIdPredicate in project mage by magefree.

the class SingleCombatRestrictionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    FilterPermanent filterSac = new FilterCreatureOrPlaneswalkerPermanent();
    for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player == null) {
            continue;
        }
        Target target = new TargetPermanent(filter);
        target.setNotTarget(true);
        if (player.choose(outcome, target, source.getSourceId(), game)) {
            filterSac.add(Predicates.not(new PermanentIdPredicate(target.getFirstTarget())));
        }
    }
    for (Permanent permanent : game.getBattlefield().getActivePermanents(filterSac, source.getControllerId(), game)) {
        permanent.sacrifice(source, game);
    }
    return true;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) Player(mage.players.Player) Target(mage.target.Target) FilterPermanent(mage.filter.FilterPermanent) FilterCreatureOrPlaneswalkerPermanent(mage.filter.common.FilterCreatureOrPlaneswalkerPermanent) FilterPermanent(mage.filter.FilterPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID) FilterCreatureOrPlaneswalkerPermanent(mage.filter.common.FilterCreatureOrPlaneswalkerPermanent)

Example 24 with PermanentIdPredicate

use of mage.filter.predicate.permanent.PermanentIdPredicate in project mage by magefree.

the class GauntletsOfLightEffect method apply.

@Override
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (permanent == null || permanent.getAttachedTo() == null) {
        return false;
    }
    FilterCreaturePermanent filter = new FilterCreaturePermanent();
    filter.add(new PermanentIdPredicate(permanent.getAttachedTo()));
    game.getCombat().setUseToughnessForDamage(true);
    game.getCombat().addUseToughnessForDamageFilter(filter);
    return true;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetPermanent(mage.target.TargetPermanent)

Example 25 with PermanentIdPredicate

use of mage.filter.predicate.permanent.PermanentIdPredicate in project mage by magefree.

the class GlamerSpinnersEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    /*
         5/1/2008 	When Glamer Spinners enters the battlefield, you target only one permanent: the one that will be losing its Auras. You don't choose the permanent that will be receiving the Auras until the ability resolves.
         5/1/2008 	You may target a permanent that has no Auras enchanting it.
         5/1/2008 	When the ability resolves, you choose the permanent that will be receiving the Auras. It can't be the targeted permanent, it must have the same controller as the targeted permanent, and it must be able to be enchanted by all the Auras attached to the targeted permanent. If you can't choose a permanent that meets all those criteria, the Auras won't move.
         */
    Permanent targetPermanent = game.getPermanent(getTargetPointer().getFirst(game, source));
    Player controller = game.getPlayer(source.getControllerId());
    Permanent glamerSpinners = game.getPermanent(source.getSourceId());
    if (targetPermanent != null && controller != null && glamerSpinners != null) {
        boolean passed = true;
        FilterPermanent filterChoice = new FilterPermanent("a different permanent with the same controller as the target to attach the enchantments to");
        filterChoice.add(new ControllerIdPredicate(targetPermanent.getControllerId()));
        filterChoice.add(Predicates.not(new PermanentIdPredicate(targetPermanent.getId())));
        Target chosenPermanentToAttachAuras = new TargetPermanent(filterChoice);
        chosenPermanentToAttachAuras.setNotTarget(true);
        LinkedList<UUID> auras = new LinkedList<>();
        auras.addAll(targetPermanent.getAttachments());
        if (// not blinked
        source.getSourceObjectZoneChangeCounter() == glamerSpinners.getZoneChangeCounter(game) && chosenPermanentToAttachAuras.canChoose(source.getSourceId(), source.getControllerId(), game) && controller.choose(Outcome.Neutral, chosenPermanentToAttachAuras, source.getSourceId(), game)) {
            Permanent permanentToAttachAuras = game.getPermanent(chosenPermanentToAttachAuras.getFirstTarget());
            if (permanentToAttachAuras != null) {
                for (UUID auraId : auras) {
                    Permanent aura = game.getPermanent(auraId);
                    if (aura != null && passed) {
                        // Check the target filter
                        Target target = aura.getSpellAbility().getTargets().get(0);
                        if (target instanceof TargetPermanent) {
                            if (!target.getFilter().match(permanentToAttachAuras, game)) {
                                passed = false;
                            }
                        }
                        // Check for protection
                        MageObject auraObject = game.getObject(auraId);
                        if (auraObject != null) {
                            if (permanentToAttachAuras.cantBeAttachedBy(auraObject, source, game, true)) {
                                passed = false;
                            }
                        }
                    }
                }
                if (passed) {
                    LinkedList<UUID> aurasToAttach = new LinkedList<>();
                    aurasToAttach.addAll(auras);
                    for (UUID auraId : aurasToAttach) {
                        Permanent auraToAttachToPermanent = game.getPermanent(auraId);
                        targetPermanent.removeAttachment(auraToAttachToPermanent.getId(), source, game);
                        permanentToAttachAuras.addAttachment(auraToAttachToPermanent.getId(), source, game);
                    }
                    return true;
                }
                game.informPlayers("Glamer Spinners" + ": No enchantments were moved from the target permanent.");
            }
        }
        return true;
    }
    return false;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) Player(mage.players.Player) Target(mage.target.Target) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) MageObject(mage.MageObject) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID) LinkedList(java.util.LinkedList)

Aggregations

PermanentIdPredicate (mage.filter.predicate.permanent.PermanentIdPredicate)45 Permanent (mage.game.permanent.Permanent)38 Player (mage.players.Player)26 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)24 FilterPermanent (mage.filter.FilterPermanent)19 TargetPermanent (mage.target.TargetPermanent)19 Target (mage.target.Target)17 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)17 UUID (java.util.UUID)14 NamePredicate (mage.filter.predicate.mageobject.NamePredicate)9 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)7 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)5 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)5 MageObject (mage.MageObject)4 Predicate (mage.filter.predicate.Predicate)4 ContinuousEffect (mage.abilities.effects.ContinuousEffect)3 BecomesFaceDownCreatureAllEffect (mage.abilities.effects.common.continuous.BecomesFaceDownCreatureAllEffect)3 BoostAllEffect (mage.abilities.effects.common.continuous.BoostAllEffect)3 AbilityPredicate (mage.filter.predicate.mageobject.AbilityPredicate)3 ArrayList (java.util.ArrayList)2