Search in sources :

Example 86 with ControllerIdPredicate

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

the class EquipoiseEffect method phaseOutCardType.

private void phaseOutCardType(Player controller, Player targetPlayer, CardType cardType, Ability source, Game game) {
    FilterPermanent filter = new FilterControlledPermanent();
    filter.add(cardType.getPredicate());
    int numberController = game.getBattlefield().count(filter, source.getSourceId(), controller.getId(), game);
    int numberTargetPlayer = game.getBattlefield().count(filter, source.getSourceId(), targetPlayer.getId(), game);
    int excess = numberTargetPlayer - numberController;
    if (excess > 0) {
        FilterPermanent filterChoose = new FilterPermanent(cardType.toString().toLowerCase(Locale.ENGLISH) + (excess > 1 ? "s" : "") + " of target player");
        filterChoose.add(new ControllerIdPredicate(targetPlayer.getId()));
        filterChoose.add(cardType.getPredicate());
        Target target = new TargetPermanent(excess, excess, filterChoose, true);
        controller.chooseTarget(outcome, target, source, game);
        new PhaseOutAllEffect(target.getTargets()).apply(game, source);
    }
}
Also used : Target(mage.target.Target) FilterPermanent(mage.filter.FilterPermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) PhaseOutAllEffect(mage.abilities.effects.common.PhaseOutAllEffect) TargetPermanent(mage.target.TargetPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent)

Example 87 with ControllerIdPredicate

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

the class FeastOfWormsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanentOrLKIBattlefield(id);
    Player targetPlayer = null;
    if (permanent != null) {
        targetPlayer = game.getPlayer(permanent.getControllerId());
    }
    if (targetPlayer != null && permanent != null && (permanent.isLegendary())) {
        FilterControlledPermanent filter = new FilterControlledLandPermanent("land to sacrifice");
        filter.add(new ControllerIdPredicate(targetPlayer.getId()));
        TargetControlledPermanent target = new TargetControlledPermanent(1, 1, filter, false);
        if (target.canChoose(source.getSourceId(), targetPlayer.getId(), game)) {
            targetPlayer.chooseTarget(Outcome.Sacrifice, target, source, game);
            Permanent land = game.getPermanent(target.getFirstTarget());
            if (land != null) {
                land.sacrifice(source, game);
            }
        }
        return true;
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) TargetLandPermanent(mage.target.common.TargetLandPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent)

Example 88 with ControllerIdPredicate

use of mage.filter.predicate.permanent.ControllerIdPredicate 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)

Example 89 with ControllerIdPredicate

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

the class GuardianProjectEffect method checkCondition.

// This is needed as checkInterveningIfClause can't access trigger event information
static boolean checkCondition(Permanent permanent, UUID controllerId, Game game) {
    Player player = game.getPlayer(controllerId);
    if (player == null) {
        return false;
    }
    if (!permanent.getName().isEmpty()) {
        FilterCard filterCard = new FilterCard();
        filterCard.add(new NamePredicate(permanent.getName()));
        filterCard.add(new OwnerIdPredicate(controllerId));
        if (player.getGraveyard().count(filterCard, game) > 0) {
            return false;
        }
    }
    FilterPermanent filterPermanent = new FilterCreaturePermanent();
    filterPermanent.add(new NamePredicate(permanent.getName()));
    filterPermanent.add(Predicates.not(new CardIdPredicate(permanent.getId())));
    filterPermanent.add(new ControllerIdPredicate(controllerId));
    if (!game.getBattlefield().getActivePermanents(filterPermanent, controllerId, game).isEmpty()) {
        return false;
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) FilterPermanent(mage.filter.FilterPermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) CardIdPredicate(mage.filter.predicate.mageobject.CardIdPredicate)

Example 90 with ControllerIdPredicate

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

the class InvokeJusticeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player player = game.getPlayer(getTargetPointer().getFirst(game, source));
    if (controller == null || player == null) {
        return false;
    }
    FilterPermanent filter = new FilterPermanent("creatures and/or Vehicles controlled by " + player.getName());
    filter.add(new ControllerIdPredicate(player.getId()));
    if (!game.getBattlefield().contains(filter, source, game, 1)) {
        return false;
    }
    TargetAmount target = new TargetPermanentAmount(4, filter);
    target.setNotTarget(true);
    controller.choose(outcome, target, source.getSourceId(), game);
    for (UUID targetId : target.getTargets()) {
        Permanent permanent = game.getPermanent(targetId);
        if (permanent != null) {
            permanent.addCounters(CounterType.P1P1.createInstance(target.getTargetAmount(targetId)), source, game);
        }
    }
    return true;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) UUID(java.util.UUID) TargetPermanentAmount(mage.target.common.TargetPermanentAmount) TargetAmount(mage.target.TargetAmount)

Aggregations

ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)153 Player (mage.players.Player)105 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)87 Permanent (mage.game.permanent.Permanent)70 UUID (java.util.UUID)53 TargetPermanent (mage.target.TargetPermanent)53 FilterPermanent (mage.filter.FilterPermanent)51 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)41 Target (mage.target.Target)29 FixedTarget (mage.target.targetpointer.FixedTarget)21 TargetPlayer (mage.target.TargetPlayer)16 ContinuousEffect (mage.abilities.effects.ContinuousEffect)15 Effect (mage.abilities.effects.Effect)14 OneShotEffect (mage.abilities.effects.OneShotEffect)13 FilterLandPermanent (mage.filter.common.FilterLandPermanent)13 DamagedPlayerEvent (mage.game.events.DamagedPlayerEvent)11 GainControlTargetEffect (mage.abilities.effects.common.continuous.GainControlTargetEffect)9 FilterNonlandPermanent (mage.filter.common.FilterNonlandPermanent)9 MageObject (mage.MageObject)8 HashSet (java.util.HashSet)7