Search in sources :

Example 6 with OwnerIdPredicate

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

the class ShroudedLoreEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player you = game.getPlayer(source.getControllerId());
    Player opponent = game.getPlayer(targetPointer.getFirst(game, source));
    if (you != null && opponent != null) {
        FilterCard filter = new FilterCard();
        filter.add(new OwnerIdPredicate(you.getId()));
        Cost cost = new ManaCostsImpl("{B}");
        TargetCardInGraveyard chosenCard;
        Card card = null;
        boolean done = false;
        do {
            chosenCard = new TargetCardInGraveyard(filter);
            chosenCard.setNotTarget(true);
            if (chosenCard.canChoose(source.getSourceId(), opponent.getId(), game)) {
                opponent.chooseTarget(Outcome.ReturnToHand, chosenCard, source, game);
                card = game.getCard(chosenCard.getFirstTarget());
                if (card != null) {
                    filter.add(Predicates.not(new CardIdPredicate(card.getId())));
                    game.informPlayers("Shrouded Lore: " + opponent.getLogName() + " has chosen " + card.getLogName());
                }
            } else {
                done = true;
            }
            if (!done) {
                done = true;
                if (cost.canPay(source, source, you.getId(), game) && you.chooseUse(Outcome.Benefit, "Pay {B} to choose a different card ?", source, game)) {
                    cost.clearPaid();
                    if (cost.pay(source, game, source, you.getId(), false, null)) {
                        done = false;
                    }
                }
            }
        } while (!done);
        if (card != null) {
            Cards cardsToHand = new CardsImpl();
            cardsToHand.add(card);
            you.moveCards(cardsToHand, Zone.HAND, source, game);
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) Cost(mage.abilities.costs.Cost) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) FilterCard(mage.filter.FilterCard) CardIdPredicate(mage.filter.predicate.mageobject.CardIdPredicate)

Example 7 with OwnerIdPredicate

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

the class CryptChampionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Set<Card> toBattlefield = new HashSet<>();
    if (controller != null) {
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                FilterCard filter = new FilterCreatureCard("creature card with mana value 3 or less from your graveyard");
                filter.add(new OwnerIdPredicate(playerId));
                filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, 4));
                Target target = new TargetCardInGraveyard(filter);
                if (target.canChoose(source.getSourceId(), playerId, game) && player.chooseTarget(outcome, target, source, game)) {
                    Card card = game.getCard(target.getFirstTarget());
                    if (card != null) {
                        toBattlefield.add(card);
                    }
                }
            }
        }
        // must happen simultaneously Rule 101.4
        controller.moveCards(toBattlefield, Zone.BATTLEFIELD, source, game, false, false, true, null);
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) FilterCreatureCard(mage.filter.common.FilterCreatureCard) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) Target(mage.target.Target) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) UUID(java.util.UUID) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) HashSet(java.util.HashSet)

Example 8 with OwnerIdPredicate

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

the class ExhumeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Set<Card> toBattlefield = new HashSet<>();
    if (controller != null) {
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                FilterCreatureCard filterCreatureCard = new FilterCreatureCard("creature card from your graveyard");
                filterCreatureCard.add(new OwnerIdPredicate(playerId));
                TargetCardInGraveyard target = new TargetCardInGraveyard(filterCreatureCard);
                target.setNotTarget(true);
                if (target.canChoose(source.getSourceId(), playerId, game) && player.chooseTarget(outcome, target, source, game)) {
                    Card card = game.getCard(target.getFirstTarget());
                    if (card != null) {
                        toBattlefield.add(card);
                    }
                }
            }
        }
        // must happen simultaneously Rule 101.4
        controller.moveCards(toBattlefield, Zone.BATTLEFIELD, source, game, false, false, true, null);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) FilterCreatureCard(mage.filter.common.FilterCreatureCard) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) UUID(java.util.UUID) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Card(mage.cards.Card) HashSet(java.util.HashSet)

Example 9 with OwnerIdPredicate

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

the class LichsMirrorEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    Player player = game.getPlayer(event.getPlayerId());
    if (player != null) {
        Cards toLib = new CardsImpl();
        FilterControlledPermanent filter = new FilterControlledPermanent();
        filter.add(new OwnerIdPredicate(player.getId()));
        toLib.addAll(player.getHand());
        toLib.addAll(player.getGraveyard());
        for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
            toLib.add(permanent);
        }
        player.shuffleCardsToLibrary(toLib, game, source);
        game.getState().processAction(game);
        // original event is not a draw event, so skip it in params
        player.drawCards(7, source, game);
        player.setLife(20, game, source);
    }
    // replace the loses event
    return true;
}
Also used : Player(mage.players.Player) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 10 with OwnerIdPredicate

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

the class SkullsnatcherTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (((DamagedPlayerEvent) event).isCombatDamage() && event.getSourceId().equals(sourceId)) {
        FilterCard filter = new FilterCard("up to two target cards from that player's graveyard");
        filter.add(new OwnerIdPredicate(event.getPlayerId()));
        filter.setMessage("up to two cards in " + game.getPlayer(event.getTargetId()).getLogName() + "'s graveyard");
        this.getTargets().clear();
        this.addTarget(new TargetCardInOpponentsGraveyard(0, 2, filter));
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) TargetCardInOpponentsGraveyard(mage.target.common.TargetCardInOpponentsGraveyard)

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