Search in sources :

Example 41 with FilterPermanent

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

the class SameNameAsExiledCountValue method calculate.

@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
    int value = 0;
    Permanent permanent = game.getPermanent(sourceAbility.getSourceId());
    if (permanent != null && !permanent.getImprinted().isEmpty()) {
        FilterPermanent filterPermanent = new FilterPermanent();
        filterPermanent.add(new NamePredicate(game.getCard(permanent.getImprinted().get(0)).getName()));
        value = game.getBattlefield().count(filterPermanent, sourceAbility.getSourceId(), sourceAbility.getControllerId(), game);
    }
    return value;
}
Also used : NamePredicate(mage.filter.predicate.mageobject.NamePredicate) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent)

Example 42 with FilterPermanent

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

the class TariffEffect method getPermanentsWithTheHighestCMC.

private List<Permanent> getPermanentsWithTheHighestCMC(Game game, UUID playerId, FilterPermanent filter) {
    List<Permanent> permanents = game.getBattlefield().getAllActivePermanents(filter, playerId, game);
    int highestCMC = -1;
    for (Permanent permanent : permanents) {
        if (highestCMC < permanent.getManaValue()) {
            highestCMC = permanent.getManaValue();
        }
    }
    List<Permanent> result = new ArrayList<>();
    for (Permanent permanent : permanents) {
        if (permanent.getManaValue() == highestCMC) {
            result.add(permanent);
        }
    }
    return result;
}
Also used : FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) ArrayList(java.util.ArrayList)

Example 43 with FilterPermanent

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

the class TormentOfVenomEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent targetCreature = game.getPermanent(getTargetPointer().getFirst(game, source));
    if (targetCreature != null) {
        new AddCountersTargetEffect(CounterType.M1M1.createInstance(3)).apply(game, source);
        Player controllingPlayer = game.getPlayer(targetCreature.getControllerId());
        if (controllingPlayer != null) {
            int permanents = game.getBattlefield().countAll(StaticFilters.FILTER_PERMANENT_NON_LAND, controllingPlayer.getId(), game);
            if (permanents > 0 && controllingPlayer.chooseUse(outcome, "Sacrifices a nonland permanent?", "Otherwise you have to discard a card or lose 3 life.", "Sacrifice", "Discard or life loss", source, game)) {
                FilterPermanent filter = new FilterControlledPermanent("another nonland permanent");
                filter.add(Predicates.not(CardType.LAND.getPredicate()));
                filter.add(Predicates.not(new PermanentIdPredicate(targetCreature.getId())));
                Target target = new TargetPermanent(filter);
                if (controllingPlayer.choose(outcome, target, source.getSourceId(), game)) {
                    Permanent permanent = game.getPermanent(target.getFirstTarget());
                    if (permanent != null) {
                        permanent.sacrifice(source, game);
                        return true;
                    }
                }
            }
            if (!controllingPlayer.getHand().isEmpty() && controllingPlayer.chooseUse(outcome, "Discard a card?", "Otherwise you lose 3 life.", "Discard", "Lose 3 life", source, game)) {
                controllingPlayer.discardOne(false, false, source, game);
                return true;
            }
            controllingPlayer.loseLife(3, game, source, false);
            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) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect)

Example 44 with FilterPermanent

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

the class AshiokSculptorOfFearsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    FilterPermanent filter = new FilterCreaturePermanent();
    filter.add(new ControllerIdPredicate(source.getFirstTarget()));
    new GainControlAllEffect(Duration.Custom, filter).apply(game, source);
    return true;
}
Also used : FilterPermanent(mage.filter.FilterPermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) GainControlAllEffect(mage.abilities.effects.common.continuous.GainControlAllEffect)

Example 45 with FilterPermanent

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

the class CausticWaspsTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (event.getSourceId().equals(this.sourceId) && ((DamagedPlayerEvent) event).isCombatDamage()) {
        Player player = game.getPlayer(event.getTargetId());
        if (player != null) {
            FilterPermanent filter = new FilterPermanent("an artifact controlled by " + player.getLogName());
            filter.add(CardType.ARTIFACT.getPredicate());
            filter.add(new ControllerIdPredicate(event.getTargetId()));
            this.getTargets().clear();
            this.addTarget(new TargetPermanent(filter));
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) TargetPermanent(mage.target.TargetPermanent)

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