Search in sources :

Example 31 with OwnerIdPredicate

use of mage.filter.predicate.card.OwnerIdPredicate in project mage by magefree.

the class TerminusEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player != null) {
            FilterCreaturePermanent filter = new FilterCreaturePermanent();
            filter.add(new OwnerIdPredicate(player.getId()));
            Cards toLib = new CardsImpl();
            for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
                toLib.add(permanent);
            }
            player.putCardsOnBottomOfLibrary(toLib, game, source, true);
        }
    }
    return true;
}
Also used : Player(mage.players.Player) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) UUID(java.util.UUID) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 32 with OwnerIdPredicate

use of mage.filter.predicate.card.OwnerIdPredicate in project mage by magefree.

the class VirtussManeuverEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    ChooseFriendsAndFoes choice = new ChooseFriendsAndFoes();
    if (controller != null && !choice.chooseFriendOrFoe(controller, source, game)) {
        return false;
    }
    Map<UUID, Card> getBackMap = new HashMap<>();
    for (Player player : choice.getFriends()) {
        if (player == null) {
            continue;
        }
        FilterCard filter = new FilterCreatureCard("creature card in your graveyard");
        filter.add(new OwnerIdPredicate(player.getId()));
        TargetCardInGraveyard target = new TargetCardInGraveyard(filter);
        getBackMap.put(player.getId(), null);
        if (player.choose(Outcome.ReturnToHand, target, source.getSourceId(), game)) {
            getBackMap.put(player.getId(), game.getCard(target.getFirstTarget()));
        }
    }
    for (Player player : choice.getFriends()) {
        if (player == null) {
            continue;
        }
        Card card = getBackMap.getOrDefault(player.getId(), null);
        if (card == null) {
            continue;
        }
        player.moveCards(card, Zone.HAND, source, game);
    }
    List<UUID> perms = new ArrayList<>();
    for (Player player : choice.getFoes()) {
        if (player == null) {
            continue;
        }
        TargetControlledPermanent target = new TargetControlledPermanent(1, 1, StaticFilters.FILTER_CONTROLLED_A_CREATURE, true);
        player.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
        perms.addAll(target.getTargets());
    }
    for (UUID permID : perms) {
        Permanent permanent = game.getPermanent(permID);
        if (permanent != null) {
            permanent.sacrifice(source, game);
        }
    }
    return true;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FilterCard(mage.filter.FilterCard) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterCreatureCard(mage.filter.common.FilterCreatureCard) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) ChooseFriendsAndFoes(mage.choices.ChooseFriendsAndFoes) UUID(java.util.UUID)

Example 33 with OwnerIdPredicate

use of mage.filter.predicate.card.OwnerIdPredicate in project mage by magefree.

the class HeraldOfLeshracLeavesEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
        if (playerId.equals(source.getControllerId())) {
            continue;
        }
        FilterPermanent filter = new FilterLandPermanent();
        filter.add(new OwnerIdPredicate(playerId));
        filter.add(new ControllerIdPredicate(source.getControllerId()));
        for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
            ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfGame, playerId);
            effect.setTargetPointer(new FixedTarget(permanent, game));
            game.addEffect(effect, source);
        }
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) FilterPermanent(mage.filter.FilterPermanent) FilterLandPermanent(mage.filter.common.FilterLandPermanent) FilterPermanent(mage.filter.FilterPermanent) FilterLandPermanent(mage.filter.common.FilterLandPermanent) Permanent(mage.game.permanent.Permanent) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) TargetPermanent(mage.target.TargetPermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect)

Example 34 with OwnerIdPredicate

use of mage.filter.predicate.card.OwnerIdPredicate in project mage by magefree.

the class TasigurTheGoldenFangEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        UUID opponentId = null;
        if (game.getOpponents(controller.getId()).size() > 1) {
            Target target = new TargetOpponent(true);
            if (controller.chooseTarget(outcome, target, source, game)) {
                opponentId = target.getFirstTarget();
            }
        } else {
            opponentId = game.getOpponents(controller.getId()).iterator().next();
        }
        if (opponentId != null) {
            Player opponent = game.getPlayer(opponentId);
            if (opponent != null) {
                FilterNonlandCard filter = new FilterNonlandCard("nonland card from " + controller.getLogName() + " graveyard");
                filter.add(new OwnerIdPredicate(controller.getId()));
                Target target = new TargetCardInGraveyard(filter);
                target.setNotTarget(true);
                opponent.chooseTarget(outcome, target, source, game);
                Card card = game.getCard(target.getFirstTarget());
                if (card != null) {
                    controller.moveCards(card, Zone.HAND, source, game);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) TargetOpponent(mage.target.common.TargetOpponent) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) FilterNonlandCard(mage.filter.common.FilterNonlandCard) UUID(java.util.UUID) FilterNonlandCard(mage.filter.common.FilterNonlandCard) Card(mage.cards.Card)

Aggregations

OwnerIdPredicate (mage.filter.predicate.card.OwnerIdPredicate)34 Player (mage.players.Player)29 TargetCardInGraveyard (mage.target.common.TargetCardInGraveyard)23 FilterCard (mage.filter.FilterCard)19 Card (mage.cards.Card)15 UUID (java.util.UUID)11 FilterCreatureCard (mage.filter.common.FilterCreatureCard)10 Permanent (mage.game.permanent.Permanent)9 Target (mage.target.Target)8 Cards (mage.cards.Cards)5 CardsImpl (mage.cards.CardsImpl)5 HashSet (java.util.HashSet)4 FilterPermanent (mage.filter.FilterPermanent)4 DamagedPlayerEvent (mage.game.events.DamagedPlayerEvent)4 MageObject (mage.MageObject)3 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)3 CardIdPredicate (mage.filter.predicate.mageobject.CardIdPredicate)3 TargetCard (mage.target.TargetCard)3 TargetPlayer (mage.target.TargetPlayer)3 TargetOpponent (mage.target.common.TargetOpponent)3