Search in sources :

Example 91 with FilterPermanent

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

the class TurnaboutEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null || game.getPlayer(source.getFirstTarget()) == null) {
        return true;
    }
    Choice choiceImpl = new ChoiceImpl(true);
    choiceImpl.setMessage("Choose card type to tap or untap");
    choiceImpl.setChoices(choice);
    if (!controller.choose(Outcome.Neutral, choiceImpl, game)) {
        return false;
    }
    FilterPermanent filter;
    switch(choiceImpl.getChoice()) {
        case "Artifact":
            filter = StaticFilters.FILTER_CONTROLLED_PERMANENT_ARTIFACT;
            break;
        case "Land":
            filter = StaticFilters.FILTER_CONTROLLED_PERMANENT_LAND;
            break;
        case "Creature":
            filter = StaticFilters.FILTER_CONTROLLED_CREATURE;
            break;
        default:
            throw new IllegalArgumentException("Choice is required");
    }
    boolean tap = controller.chooseUse(Outcome.Neutral, "Tap or untap?", null, "Tap", "Untap", source, game);
    for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getFirstTarget(), source.getSourceId(), game)) {
        if (tap) {
            permanent.tap(source, game);
        } else {
            permanent.untap(game);
        }
    }
    return true;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) Choice(mage.choices.Choice) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) ChoiceImpl(mage.choices.ChoiceImpl)

Example 92 with FilterPermanent

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

the class WildMammothEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Permanent sourcePermanent = game.getPermanent(source.getSourceId());
        if (sourcePermanent != null) {
            Player newController = null;
            int maxCreatures = 0;
            boolean tie = false;
            FilterPermanent filter = new FilterPermanent();
            filter.add(CardType.CREATURE.getPredicate());
            for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
                Player player = game.getPlayer(playerId);
                if (player != null) {
                    int value = game.getBattlefield().countAll(filter, playerId, game);
                    if (value > maxCreatures) {
                        maxCreatures = value;
                    }
                }
            }
            for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
                Player player = game.getPlayer(playerId);
                if (player != null) {
                    int value = game.getBattlefield().countAll(filter, playerId, game);
                    if (value == maxCreatures) {
                        if (newController == null) {
                            newController = player;
                        } else {
                            tie = true;
                            break;
                        }
                    }
                }
            }
            if (!controller.equals(newController) && !tie && newController != null) {
                ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, newController.getId());
                effect.setTargetPointer(new FixedTarget(sourcePermanent, game));
                game.addEffect(effect, source);
            }
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect)

Example 93 with FilterPermanent

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

the class OpponentControlsPermanentCondition method apply.

@Override
public boolean apply(Game game, Ability source) {
    boolean conditionApplies = false;
    for (UUID opponentId : game.getOpponents(source.getControllerId())) {
        FilterPermanent localFilter = filter.copy();
        localFilter.add(new ControllerIdPredicate(opponentId));
        if (ComparisonType.compare(game.getBattlefield().count(localFilter, source.getSourceId(), source.getControllerId(), game), type, this.count)) {
            conditionApplies = true;
            break;
        }
    }
    return conditionApplies;
}
Also used : FilterPermanent(mage.filter.FilterPermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) UUID(java.util.UUID)

Example 94 with FilterPermanent

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

the class EmberGaleEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player targetPlayer = game.getPlayer(source.getFirstTarget());
    if (targetPlayer != null) {
        FilterCreaturePermanent filter = new FilterCreaturePermanent();
        filter.add(new ControllerIdPredicate(targetPlayer.getId()));
        RestrictionEffect effect = new CantBlockAllEffect(filter, Duration.EndOfTurn);
        game.addEffect(effect, source);
        FilterPermanent filter2 = new FilterPermanent();
        filter2.add(new ControllerIdPredicate(targetPlayer.getId()));
        filter2.add(Predicates.or(new ColorPredicate(ObjectColor.WHITE), new ColorPredicate(ObjectColor.BLUE)));
        filter2.add(CardType.CREATURE.getPredicate());
        for (Permanent creature : game.getBattlefield().getAllActivePermanents(filter2, targetPlayer.getId(), game)) {
            creature.damage(1, source.getSourceId(), source, game, false, true);
        }
        return true;
    }
    return false;
}
Also used : ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) CantBlockAllEffect(mage.abilities.effects.common.combat.CantBlockAllEffect) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) RestrictionEffect(mage.abilities.effects.RestrictionEffect)

Example 95 with FilterPermanent

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

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