Search in sources :

Example 6 with FilterArtifactCard

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

the class ScrapMasteryEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Map<UUID, Set<Card>> exiledCards = new HashMap<>();
        // exile artifacts from graveyard
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                Set<Card> cards = player.getGraveyard().getCards(new FilterArtifactCard(), game);
                controller.moveCards(cards, Zone.EXILED, source, game);
                exiledCards.put(player.getId(), cards);
            }
        }
        // sacrifice all artifacts
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                for (Permanent permanent : game.getBattlefield().getAllActivePermanents(new FilterArtifactPermanent(), playerId, game)) {
                    permanent.sacrifice(source, game);
                }
            }
        }
        // puts all cards they exiled this way onto the battlefield
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                player.moveCards(exiledCards.get(playerId), Zone.BATTLEFIELD, source, game);
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) FilterArtifactPermanent(mage.filter.common.FilterArtifactPermanent) Set(java.util.Set) Permanent(mage.game.permanent.Permanent) FilterArtifactPermanent(mage.filter.common.FilterArtifactPermanent) HashMap(java.util.HashMap) FilterArtifactCard(mage.filter.common.FilterArtifactCard) UUID(java.util.UUID) Card(mage.cards.Card) FilterArtifactCard(mage.filter.common.FilterArtifactCard)

Example 7 with FilterArtifactCard

use of mage.filter.common.FilterArtifactCard 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)

Example 8 with FilterArtifactCard

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

the class OswaldFiddlebenderEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent sacrificed = source.getCosts().stream().filter(SacrificeTargetCost.class::isInstance).map(SacrificeTargetCost.class::cast).map(SacrificeTargetCost::getPermanents).flatMap(Collection::stream).findFirst().orElse(null);
    if (player == null || sacrificed == null) {
        return false;
    }
    FilterCard filterCard = new FilterArtifactCard("artifact card with mana value " + (sacrificed.getManaValue() + 1));
    filterCard.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, sacrificed.getManaValue() + 1));
    TargetCardInLibrary target = new TargetCardInLibrary(filterCard);
    player.searchLibrary(target, source, game);
    Card card = player.getLibrary().getCard(target.getFirstTarget(), game);
    player.moveCards(card, Zone.BATTLEFIELD, source, game);
    player.shuffleLibrary(source, game);
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Collection(java.util.Collection) FilterArtifactCard(mage.filter.common.FilterArtifactCard) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card) FilterArtifactCard(mage.filter.common.FilterArtifactCard)

Example 9 with FilterArtifactCard

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

the class ThadaAdelPlayFromExileEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player damagedPlayer = game.getPlayer(targetPointer.getFirst(game, source));
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (controller == null || damagedPlayer == null || sourceObject == null) {
        return false;
    }
    TargetCardInLibrary target = new TargetCardInLibrary(new FilterArtifactCard());
    if (controller.searchLibrary(target, source, game, damagedPlayer.getId())) {
        if (!target.getTargets().isEmpty()) {
            Card card = damagedPlayer.getLibrary().remove(target.getFirstTarget(), game);
            if (card != null) {
                controller.moveCardToExileWithInfo(card, source.getSourceId(), sourceObject.getIdName(), source, game, Zone.LIBRARY, true);
                ContinuousEffect effect = new ThadaAdelPlayFromExileEffect();
                effect.setTargetPointer(new FixedTarget(card.getId()));
                game.addEffect(effect, source);
            }
        }
    }
    damagedPlayer.shuffleLibrary(source, game);
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) MageObject(mage.MageObject) FilterArtifactCard(mage.filter.common.FilterArtifactCard) ContinuousEffect(mage.abilities.effects.ContinuousEffect) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Card(mage.cards.Card) FilterArtifactCard(mage.filter.common.FilterArtifactCard)

Example 10 with FilterArtifactCard

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

the class ScrapTrawlerTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (((ZoneChangeEvent) event).getToZone() == Zone.GRAVEYARD && ((ZoneChangeEvent) event).getFromZone() == Zone.BATTLEFIELD) {
        Permanent permanent = ((ZoneChangeEvent) event).getTarget();
        if (permanent != null && permanent.isControlledBy(this.getControllerId()) && permanent.isArtifact(game)) {
            FilterCard filter = new FilterArtifactCard("artifact card in your graveyard with mana value less than " + permanent.getManaCost().manaValue());
            filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, permanent.getManaCost().manaValue()));
            TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(filter);
            getTargets().clear();
            addTarget(target);
            return true;
        }
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) ZoneChangeEvent(mage.game.events.ZoneChangeEvent) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) Permanent(mage.game.permanent.Permanent) FilterArtifactCard(mage.filter.common.FilterArtifactCard) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard)

Aggregations

FilterArtifactCard (mage.filter.common.FilterArtifactCard)11 Player (mage.players.Player)9 Card (mage.cards.Card)5 ManaValuePredicate (mage.filter.predicate.mageobject.ManaValuePredicate)5 Permanent (mage.game.permanent.Permanent)5 FilterCard (mage.filter.FilterCard)4 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)3 UUID (java.util.UUID)2 Cards (mage.cards.Cards)2 CardsImpl (mage.cards.CardsImpl)2 FilterArtifactPermanent (mage.filter.common.FilterArtifactPermanent)2 TargetCard (mage.target.TargetCard)2 TargetCardInYourGraveyard (mage.target.common.TargetCardInYourGraveyard)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Set (java.util.Set)1 MageObject (mage.MageObject)1 Cost (mage.abilities.costs.Cost)1 PayVariableLoyaltyCost (mage.abilities.costs.common.PayVariableLoyaltyCost)1