Search in sources :

Example 11 with OwnerIdPredicate

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

the class HarmonicConvergenceEffect 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) {
            FilterEnchantmentPermanent filter = new FilterEnchantmentPermanent();
            filter.add(new OwnerIdPredicate(player.getId()));
            Cards toLib = new CardsImpl();
            for (Permanent enchantment : game.getBattlefield().getActivePermanents(filter, playerId, source.getSourceId(), game)) {
                toLib.add(enchantment);
            }
            player.putCardsOnTopOfLibrary(toLib, game, source, true);
        }
    }
    return true;
}
Also used : Player(mage.players.Player) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) FilterEnchantmentPermanent(mage.filter.common.FilterEnchantmentPermanent) Permanent(mage.game.permanent.Permanent) FilterEnchantmentPermanent(mage.filter.common.FilterEnchantmentPermanent) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 12 with OwnerIdPredicate

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

the class WrexialReplacementEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (!event.getSourceId().equals(this.sourceId) || !((DamagedPlayerEvent) event).isCombatDamage()) {
        return false;
    }
    Player damagedPlayer = game.getPlayer(event.getTargetId());
    if (damagedPlayer == null) {
        return false;
    }
    FilterCard filter = new FilterCard("target instant or sorcery card from " + damagedPlayer.getName() + "'s graveyard");
    filter.add(new OwnerIdPredicate(damagedPlayer.getId()));
    filter.add(Predicates.or(CardType.INSTANT.getPredicate(), CardType.SORCERY.getPredicate()));
    Target target = new TargetCardInGraveyard(filter);
    this.getTargets().clear();
    this.addTarget(target);
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) Target(mage.target.Target) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) DamagedPlayerEvent(mage.game.events.DamagedPlayerEvent)

Example 13 with OwnerIdPredicate

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

the class DawnbreakReclaimerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    /**
     * 04.11.2015 If any opponent has a creature card in their graveyard as
     * Dawnbreak Reclaimer's ability resolves, then you must choose one of
     * those cards. You can't choose a different opponent with no creature
     * cards in their graveyard to avoid returning one of those cards.
     *
     * 04.11.2015 If there are no creature cards in any opponent's graveyard
     * as Dawnbreak Reclaimer's ability resolves, you'll still have the
     * option to return a creature card from your graveyard to the
     * battlefield. You choose which opponent will choose a creature card in
     * your graveyard.
     */
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (controller != null && sourceObject != null) {
        FilterCreatureCard filter = new FilterCreatureCard("a creature card in an opponent's graveyard");
        filter.add(TargetController.OPPONENT.getOwnerPredicate());
        TargetCard chosenCreatureOpponentGraveyard = new TargetCard(Zone.GRAVEYARD, filter);
        Player opponent = null;
        Card cardOpponentGraveyard = null;
        chosenCreatureOpponentGraveyard.setNotTarget(true);
        if (chosenCreatureOpponentGraveyard.canChoose(source.getSourceId(), source.getControllerId(), game)) {
            controller.choose(Outcome.Detriment, chosenCreatureOpponentGraveyard, source.getSourceId(), game);
            cardOpponentGraveyard = game.getCard(chosenCreatureOpponentGraveyard.getFirstTarget());
            if (cardOpponentGraveyard != null) {
                opponent = game.getPlayer(cardOpponentGraveyard.getOwnerId());
                game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " has chosen " + cardOpponentGraveyard.getIdName() + " of " + opponent.getLogName());
            }
        }
        if (opponent == null) {
            // if no card from opponent was available controller has to chose an opponent to select a creature card in controllers graveyard
            TargetOpponent targetOpponent = new TargetOpponent(true);
            controller.choose(outcome, targetOpponent, source.getSourceId(), game);
            opponent = game.getPlayer(targetOpponent.getFirstTarget());
            if (opponent != null) {
                game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " has chosen " + opponent.getLogName() + " to select a creature card from their graveyard");
            }
        }
        if (opponent != null) {
            FilterCreatureCard filterCreatureCard = new FilterCreatureCard("a creature card in " + controller.getName() + "'s the graveyard");
            filterCreatureCard.add(new OwnerIdPredicate(controller.getId()));
            TargetCardInGraveyard targetControllerGaveyard = new TargetCardInGraveyard(filterCreatureCard);
            targetControllerGaveyard.setNotTarget(true);
            Card controllerCreatureCard = null;
            if (targetControllerGaveyard.canChoose(source.getSourceId(), opponent.getId(), game) && opponent.choose(outcome, targetControllerGaveyard, source.getSourceId(), game)) {
                controllerCreatureCard = game.getCard(targetControllerGaveyard.getFirstTarget());
                if (controllerCreatureCard != null) {
                    game.informPlayers(sourceObject.getLogName() + ": " + opponent.getLogName() + " has chosen " + controllerCreatureCard.getIdName() + " of " + controller.getLogName());
                }
            }
            Set<Card> cards = new HashSet<>();
            if (cardOpponentGraveyard != null) {
                cards.add(cardOpponentGraveyard);
            }
            if (controllerCreatureCard != null) {
                cards.add(controllerCreatureCard);
            }
            if (!cards.isEmpty()) {
                if (controller.chooseUse(outcome, "Return those cards to the battlefield under their owners' control?", "Opponent's creature card: " + (cardOpponentGraveyard == null ? "none" : cardOpponentGraveyard.getLogName()) + ", your creature card: " + (controllerCreatureCard == null ? "none" : controllerCreatureCard.getLogName()), null, null, source, game)) {
                    controller.moveCards(cards, Zone.BATTLEFIELD, source, game, false, false, true, null);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) FilterCreatureCard(mage.filter.common.FilterCreatureCard) TargetOpponent(mage.target.common.TargetOpponent) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) FilterCreatureCard(mage.filter.common.FilterCreatureCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card) HashSet(java.util.HashSet)

Example 14 with OwnerIdPredicate

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

the class OblivionSowerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    /*
        8/25/2015: Oblivion Sower's ability allows you to put any land cards the player owns from exile onto the battlefield, regardless of how those cards were exiled.
        8/25/2015: Cards that are face down in exile have no characteristics. Such cards can't be put onto the battlefield with Oblivion Sower's ability.
         */
    Player controller = game.getPlayer(source.getControllerId());
    Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
    if (controller != null && targetPlayer != null) {
        FilterLandCard filter = new FilterLandCard();
        filter.add(new OwnerIdPredicate(targetPlayer.getId()));
        filter.add(Predicates.not(FaceDownPredicate.instance));
        Cards exiledCards = new CardsImpl();
        exiledCards.addAll(game.getExile().getAllCards(game));
        Cards exiledLands = new CardsImpl();
        exiledLands.addAll(exiledCards.getCards(filter, source.getSourceId(), controller.getId(), game));
        if (!exiledLands.isEmpty() && controller.chooseUse(outcome, "Put lands into play?", source, game)) {
            FilterCard filterToPlay = new FilterCard("land" + (exiledLands.size() > 1 ? "s" : "") + " from exile owned by " + targetPlayer.getName() + " to put into play under your control");
            TargetCard targetCards = new TargetCard(0, exiledLands.size(), Zone.EXILED, filterToPlay);
            if (controller.chooseTarget(outcome, exiledLands, targetCards, source, game)) {
                controller.moveCards(new CardsImpl(targetCards.getTargets()), Zone.BATTLEFIELD, source, game);
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) FilterLandCard(mage.filter.common.FilterLandCard) TargetCard(mage.target.TargetCard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 15 with OwnerIdPredicate

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

the class ScroungeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player opponent = game.getPlayer(targetPointer.getFirst(game, source));
    if (controller != null && opponent != null) {
        FilterArtifactCard filter = new FilterArtifactCard();
        filter.add(new OwnerIdPredicate(opponent.getId()));
        TargetCardInGraveyard chosenCard = new TargetCardInGraveyard(filter);
        chosenCard.setNotTarget(true);
        if (chosenCard.canChoose(source.getSourceId(), opponent.getId(), game)) {
            opponent.chooseTarget(Outcome.ReturnToHand, chosenCard, source, game);
            Card card = game.getCard(chosenCard.getFirstTarget());
            if (card != null) {
                game.informPlayers("Scrounge: " + opponent.getLogName() + " has chosen " + card.getLogName());
                Cards cardsToMove = new CardsImpl();
                cardsToMove.add(card);
                controller.moveCards(cardsToMove, Zone.BATTLEFIELD, source, game);
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) FilterArtifactCard(mage.filter.common.FilterArtifactCard) FilterArtifactCard(mage.filter.common.FilterArtifactCard)

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