Search in sources :

Example 11 with FilterNonlandPermanent

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

the class ScrambleverseEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    PlayerList players = game.getState().getPlayersInRange(source.getControllerId(), game);
    int count = players.size();
    for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterNonlandPermanent(), source.getControllerId(), source.getSourceId(), game)) {
        ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, true, players.get(RandomUtil.nextInt(count)));
        effect.setTargetPointer(new FixedTarget(permanent, game));
        game.addEffect(effect, source);
        permanent.untap(game);
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) Permanent(mage.game.permanent.Permanent) PlayerList(mage.players.PlayerList) ContinuousEffect(mage.abilities.effects.ContinuousEffect) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect)

Example 12 with FilterNonlandPermanent

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

the class FortunateFewEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Map<Permanent, Integer> chosenCards = new HashMap<>(2);
        int maxCount = 0;
        // Players each choose a legal permanent
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                FilterNonlandPermanent filter = new FilterNonlandPermanent("a nonland permanent you don't control");
                filter.add(Predicates.not(new ControllerIdPredicate(player.getId())));
                for (Permanent chosenPerm : chosenCards.keySet()) {
                    filter.add(Predicates.not(new PermanentIdPredicate(chosenPerm.getId())));
                }
                Target target = new TargetNonlandPermanent(filter);
                target.setNotTarget(true);
                if (player.choose(Outcome.Exile, target, source.getSourceId(), game)) {
                    Permanent permanent = game.getPermanent(target.getFirstTarget());
                    if (permanent != null) {
                        chosenCards.put(permanent, 1);
                        game.informPlayers(player.getLogName() + " has chosen: " + permanent.getName());
                    }
                }
            }
        }
        for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterNonlandPermanent(), source.getControllerId(), source.getSourceId(), game)) {
            if (!chosenCards.containsKey(permanent)) {
                permanent.destroy(source, game, false);
            }
        }
        return true;
    }
    return false;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) Player(mage.players.Player) Target(mage.target.Target) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) Permanent(mage.game.permanent.Permanent) TargetNonlandPermanent(mage.target.common.TargetNonlandPermanent) TargetNonlandPermanent(mage.target.common.TargetNonlandPermanent) HashMap(java.util.HashMap) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) UUID(java.util.UUID) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent)

Example 13 with FilterNonlandPermanent

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

the class SarulfRealmEaterEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent permanent = source.getSourcePermanentIfItStillExists(game);
    if (player == null || permanent == null) {
        return false;
    }
    int counterCount = permanent.getCounters(game).getCount(CounterType.P1P1);
    permanent.removeCounters(CounterType.P1P1.createInstance(counterCount), source, game);
    FilterPermanent filter = new FilterNonlandPermanent();
    filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, counterCount + 1));
    filter.add(AnotherPredicate.instance);
    Cards cards = new CardsImpl();
    game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game).stream().filter(Objects::nonNull).map(MageItem::getId).forEach(cards::add);
    return player.moveCards(cards, Zone.EXILED, source, game);
}
Also used : Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) FilterPermanent(mage.filter.FilterPermanent) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) Objects(java.util.Objects) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 14 with FilterNonlandPermanent

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

the class DeputyOfDetentionExileEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanent(source.getSourceId());
    Permanent targeted = game.getPermanent(source.getFirstTarget());
    if (permanent == null || controller == null || targeted == null) {
        return false;
    }
    FilterPermanent filter = new FilterNonlandPermanent();
    filter.add(new ControllerIdPredicate(targeted.getControllerId()));
    filter.add(new NamePredicate(targeted.getName()));
    Set<Card> toExile = new LinkedHashSet<>();
    for (Permanent creature : game.getBattlefield().getActivePermanents(filter, controller.getId(), game)) {
        toExile.add(creature);
    }
    if (!toExile.isEmpty()) {
        controller.moveCardsToExile(toExile, source, game, true, CardUtil.getCardExileZoneId(game, source), permanent.getIdName());
        new CreateDelayedTriggeredAbilityEffect(new OnLeaveReturnExiledToBattlefieldAbility()).apply(game, source);
    }
    return true;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) 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) TargetPermanent(mage.target.TargetPermanent) CreateDelayedTriggeredAbilityEffect(mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) OnLeaveReturnExiledToBattlefieldAbility(mage.abilities.common.delayed.OnLeaveReturnExiledToBattlefieldAbility) Card(mage.cards.Card)

Example 15 with FilterNonlandPermanent

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

the class AminatouUltimateEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Choice choice = new ChoiceLeftOrRight();
        if (!controller.choose(Outcome.Neutral, choice, game)) {
            return false;
        }
        boolean left = choice.getChoice().equals("Left");
        PlayerList playerList = game.getState().getPlayerList().copy();
        // set playerlist to controller
        while (!playerList.get().equals(source.getControllerId())) {
            playerList.getNext();
        }
        UUID currentPlayer = playerList.get();
        UUID nextPlayer;
        UUID firstNextPlayer = null;
        while (!getNextPlayerInDirection(left, playerList, game).equals(firstNextPlayer)) {
            nextPlayer = playerList.get();
            if (nextPlayer == null) {
                return false;
            }
            // skip players out of range
            if (!game.getState().getPlayersInRange(controller.getId(), game).contains(nextPlayer)) {
                continue;
            }
            // save first next player to check for iteration stop
            if (firstNextPlayer == null) {
                firstNextPlayer = nextPlayer;
            }
            FilterNonlandPermanent nextPlayerNonlandPermanentsFilter = new FilterNonlandPermanent();
            nextPlayerNonlandPermanentsFilter.add(new ControllerIdPredicate(nextPlayer));
            for (Permanent permanent : game.getBattlefield().getAllActivePermanents(nextPlayerNonlandPermanentsFilter, game)) {
                if (permanent.getId().equals(source.getSourceId())) {
                    continue;
                }
                ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfGame, currentPlayer);
                effect.setTargetPointer(new FixedTarget(permanent, game));
                game.addEffect(effect, source);
            }
            currentPlayer = nextPlayer;
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Choice(mage.choices.Choice) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) PlayerList(mage.players.PlayerList) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) ChoiceLeftOrRight(mage.choices.ChoiceLeftOrRight) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect)

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