Search in sources :

Example 71 with FilterPermanent

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

the class PowderKegEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (sourcePermanent == null) {
        return false;
    }
    int count = sourcePermanent.getCounters(game).getCount(CounterType.FUSE);
    FilterPermanent filter = new FilterPermanent();
    filter.add(Predicates.or(CardType.ARTIFACT.getPredicate(), CardType.CREATURE.getPredicate()));
    filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, count));
    for (Permanent perm : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
        perm.destroy(source, game, false);
    }
    return true;
}
Also used : ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent)

Example 72 with FilterPermanent

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

the class ReinsOfTheVinesteedEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Card aura = game.getCard(source.getSourceId());
    if (aura != null && game.getState().getZone(aura.getId()) == Zone.GRAVEYARD) {
        Player controller = game.getPlayer(source.getControllerId());
        Permanent lastStateAura = (Permanent) game.getLastKnownInformation(aura.getId(), Zone.BATTLEFIELD);
        Permanent lastStateCreature = game.getPermanentOrLKIBattlefield(lastStateAura.getAttachedTo());
        if (lastStateCreature == null) {
            return false;
        }
        FilterPermanent FILTER = new FilterCreaturePermanent("creature that shares a creature type with " + lastStateCreature.getName());
        FILTER.add(new SharesCreatureTypePredicate(lastStateCreature));
        TargetPermanent target = new TargetPermanent(FILTER);
        target.setNotTarget(true);
        if (controller != null && controller.choose(Outcome.PutCardInPlay, target, source.getSourceId(), game)) {
            Permanent targetPermanent = game.getPermanent(target.getFirstTarget());
            if (!targetPermanent.cantBeAttachedBy(aura, source, game, false)) {
                game.getState().setValue("attachTo:" + aura.getId(), targetPermanent);
                controller.moveCards(aura, Zone.BATTLEFIELD, source, game);
                return targetPermanent.addAttachment(aura.getId(), source, game);
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) SharesCreatureTypePredicate(mage.filter.predicate.mageobject.SharesCreatureTypePredicate) TargetPermanent(mage.target.TargetPermanent) Card(mage.cards.Card)

Example 73 with FilterPermanent

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

the class SphereOfAnnihilationEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent permanent = source.getSourcePermanentOrLKI(game);
    if (player == null || permanent == null) {
        return false;
    }
    Cards cards = new CardsImpl(permanent);
    int counters = permanent.getCounters(game).getCount(CounterType.VOID);
    FilterPermanent filter = StaticFilters.FILTER_PERMANENT_CREATURE_OR_PLANESWALKER.copy();
    filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, counters + 1));
    cards.addAll(game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game));
    game.getState().getPlayersInRange(source.getControllerId(), game).stream().map(game::getPlayer).filter(Objects::nonNull).map(Player::getGraveyard).map(g -> g.getCards(game)).flatMap(Collection::stream).filter(card -> card.isCreature(game) || card.isPlaneswalker(game)).filter(card -> card.getManaValue() <= counters).forEach(cards::add);
    return player.moveCards(cards, Zone.EXILED, source, game);
}
Also used : StaticFilters(mage.filter.StaticFilters) EntersBattlefieldWithXCountersEffect(mage.abilities.effects.common.EntersBattlefieldWithXCountersEffect) Collection(java.util.Collection) Cards(mage.cards.Cards) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) CardsImpl(mage.cards.CardsImpl) EntersBattlefieldAbility(mage.abilities.common.EntersBattlefieldAbility) FilterPermanent(mage.filter.FilterPermanent) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) Objects(java.util.Objects) BeginningOfUpkeepTriggeredAbility(mage.abilities.common.BeginningOfUpkeepTriggeredAbility) Game(mage.game.Game) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) mage.constants(mage.constants) CounterType(mage.counters.CounterType) Ability(mage.abilities.Ability) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) Objects(java.util.Objects) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 74 with FilterPermanent

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

the class TrygonPredatorTriggeredAbility 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 or enchantment controlled by " + player.getLogName());
            filter.add(Predicates.or(CardType.ARTIFACT.getPredicate(), CardType.ENCHANTMENT.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)

Example 75 with FilterPermanent

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

the class WeightOfConscienceTarget method canTarget.

@Override
public boolean canTarget(UUID id, Ability source, Game game) {
    if (!super.canTarget(id, game)) {
        return false;
    }
    Permanent targetPermanent = game.getPermanent(id);
    if (targetPermanent == null) {
        return false;
    }
    if (this.getTargets().isEmpty()) {
        List<Permanent> permanentList = game.getBattlefield().getActivePermanents(filterUntapped, source.getControllerId(), source.getSourceId(), game);
        if (permanentList.size() < 2) {
            return false;
        }
        for (Permanent permanent : permanentList) {
            if (permanent.isAllCreatureTypes(game)) {
                return true;
            }
            FilterPermanent filter = filterUntapped.copy();
            filter.add(new SharesCreatureTypePredicate(permanent));
            if (game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game) > 1) {
                return true;
            }
        }
    } else {
        Permanent firstTarget = game.getPermanent(this.getTargets().get(0));
        return firstTarget != null && firstTarget.shareCreatureTypes(game, targetPermanent);
    }
    return false;
}
Also used : FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) SharesCreatureTypePredicate(mage.filter.predicate.mageobject.SharesCreatureTypePredicate)

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