Search in sources :

Example 1 with FilterNonlandPermanent

use of mage.filter.common.FilterNonlandPermanent in project mage by magefree.

the class DispersalEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Set<PermanentIdPredicate> permsToReturn = new HashSet<>();
    for (UUID opponentId : game.getOpponents(player.getId())) {
        Player opponent = game.getPlayer(opponentId);
        if (opponent == null) {
            continue;
        }
        int highestCMC = 0;
        for (Permanent permanent : game.getBattlefield().getAllActivePermanents(opponentId)) {
            if (permanent != null) {
                highestCMC = Math.max(highestCMC, permanent.getManaValue());
            }
        }
        FilterPermanent filter = new FilterNonlandPermanent("permanent you control with mana value " + highestCMC);
        filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, highestCMC));
        filter.add(new ControllerIdPredicate(opponentId));
        Target target = new TargetPermanent(1, 1, filter, true);
        if (opponent.choose(outcome, target, source.getSourceId(), game)) {
            if (target.getFirstTarget() == null) {
                continue;
            }
            permsToReturn.add(new PermanentIdPredicate(target.getFirstTarget()));
        }
    }
    FilterPermanent filter = new FilterPermanent();
    filter.add(Predicates.or(permsToReturn));
    new ReturnToHandFromBattlefieldAllEffect(filter).apply(game, source);
    new DiscardEachPlayerEffect(StaticValue.get(1), false, TargetController.OPPONENT).apply(game, source);
    return true;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) ReturnToHandFromBattlefieldAllEffect(mage.abilities.effects.common.ReturnToHandFromBattlefieldAllEffect) DiscardEachPlayerEffect(mage.abilities.effects.common.discard.DiscardEachPlayerEffect) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) Target(mage.target.Target) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) HashSet(java.util.HashSet)

Example 2 with FilterNonlandPermanent

use of mage.filter.common.FilterNonlandPermanent in project mage by magefree.

the class ZzzyxassAbyssEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        List<String> permanentNames = new ArrayList<>();
        FilterPermanent filter = new FilterNonlandPermanent();
        for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, controller.getId(), game)) {
            permanentNames.add(permanent.getName());
        }
        if (permanentNames.isEmpty()) {
            return true;
        }
        Collections.sort(permanentNames);
        filter.add(new NamePredicate(permanentNames.get(0)));
        return new DestroyAllEffect(filter).apply(game, source);
    }
    return false;
}
Also used : Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) FilterPermanent(mage.filter.FilterPermanent) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) ArrayList(java.util.ArrayList) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) DestroyAllEffect(mage.abilities.effects.common.DestroyAllEffect)

Example 3 with FilterNonlandPermanent

use of mage.filter.common.FilterNonlandPermanent in project mage by magefree.

the class OKagachiVengefulKamiWatcher method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    Player player = game.getPlayer(event.getTargetId());
    if (player == null || !((DamagedPlayerEvent) event).isCombatDamage() || !event.getSourceId().equals(getSourceId())) {
        return false;
    }
    this.getEffects().setValue("damagedPlayer", event.getTargetId());
    FilterPermanent filter = new FilterNonlandPermanent("nonland permanent controlled by " + player.getName());
    filter.add(new ControllerIdPredicate(event.getTargetId()));
    this.getTargets().clear();
    this.addTarget(new TargetPermanent(filter));
    return true;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) TargetPermanent(mage.target.TargetPermanent) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent)

Example 4 with FilterNonlandPermanent

use of mage.filter.common.FilterNonlandPermanent in project mage by magefree.

the class MythosOfSnapdaxEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    boolean conditionMet = condition.apply(game, source);
    List<Player> playerList = game.getState().getPlayersInRange(source.getControllerId(), game).stream().map(game::getPlayer).filter(Objects::nonNull).collect(Collectors.toList());
    Set<UUID> toKeep = new HashSet();
    for (Player player : playerList) {
        for (CardType cardType : cardTypes) {
            String message = cardType.toString().equals("Artifact") ? "an " : "a ";
            message += cardType.toString().toLowerCase(Locale.ENGLISH);
            message += (conditionMet && player != controller) ? " controlled by " + player.getName() : " you control";
            FilterPermanent filter = new FilterNonlandPermanent(message);
            filter.add(cardType.getPredicate());
            filter.add(new ControllerIdPredicate(player.getId()));
            if (game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game) == 0) {
                continue;
            }
            TargetPermanent target = new TargetPermanent(filter);
            target.setNotTarget(true);
            if (conditionMet) {
                controller.choose(outcome, target, source.getSourceId(), game);
            } else {
                player.choose(outcome, target, source.getSourceId(), game);
            }
            toKeep.add(target.getFirstTarget());
        }
    }
    for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_NON_LAND, source.getControllerId(), game)) {
        if (permanent == null || toKeep.contains(permanent.getId())) {
            continue;
        }
        permanent.sacrifice(source, game);
    }
    return true;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) CardType(mage.constants.CardType) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) TargetPermanent(mage.target.TargetPermanent) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent)

Example 5 with FilterNonlandPermanent

use of mage.filter.common.FilterNonlandPermanent in project mage by magefree.

the class BlastZoneEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    int xValue = permanent.getCounters(game).getCount(CounterType.CHARGE);
    FilterPermanent filter = new FilterNonlandPermanent();
    filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, xValue));
    return new DestroyAllEffect(filter).apply(game, source);
}
Also used : ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) FilterPermanent(mage.filter.FilterPermanent) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) DestroyAllEffect(mage.abilities.effects.common.DestroyAllEffect)

Aggregations

FilterNonlandPermanent (mage.filter.common.FilterNonlandPermanent)17 Permanent (mage.game.permanent.Permanent)13 FilterPermanent (mage.filter.FilterPermanent)11 Player (mage.players.Player)11 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)8 TargetPermanent (mage.target.TargetPermanent)7 ManaValuePredicate (mage.filter.predicate.mageobject.ManaValuePredicate)5 UUID (java.util.UUID)3 DestroyAllEffect (mage.abilities.effects.common.DestroyAllEffect)3 Target (mage.target.Target)3 HashMap (java.util.HashMap)2 ContinuousEffect (mage.abilities.effects.ContinuousEffect)2 GainControlTargetEffect (mage.abilities.effects.common.continuous.GainControlTargetEffect)2 NamePredicate (mage.filter.predicate.mageobject.NamePredicate)2 PermanentIdPredicate (mage.filter.predicate.permanent.PermanentIdPredicate)2 PlayerList (mage.players.PlayerList)2 FixedTarget (mage.target.targetpointer.FixedTarget)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1