Search in sources :

Example 11 with FilterCreatureCard

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

the class MetathranAerostatEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    int xValue = source.getManaCostsToPay().getX();
    FilterCreatureCard filter = new FilterCreatureCard("a creature with mana value " + xValue);
    filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, xValue));
    if (new PutCardFromHandOntoBattlefieldEffect(filter).apply(game, source)) {
        return new ReturnToHandSourceEffect(true).apply(game, source);
    }
    return false;
}
Also used : Player(mage.players.Player) FilterCreatureCard(mage.filter.common.FilterCreatureCard) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) ReturnToHandSourceEffect(mage.abilities.effects.common.ReturnToHandSourceEffect) PutCardFromHandOntoBattlefieldEffect(mage.abilities.effects.common.PutCardFromHandOntoBattlefieldEffect)

Example 12 with FilterCreatureCard

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

the class OathOfGhoulsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    MageObject sourceObject = game.getObject(source.getSourceId());
    Player firstPlayer = game.getPlayer(game.getActivePlayerId());
    if (sourceObject == null || firstPlayer == null) {
        return false;
    }
    FilterCard filter = new FilterCreatureCard("creature card");
    filter.add(new OwnerIdPredicate(firstPlayer.getId()));
    Target target = new TargetCardInGraveyard(filter);
    target.setNotTarget(true);
    if (target.canChoose(source.getSourceId(), firstPlayer.getId(), game) && firstPlayer.chooseUse(outcome, "Return a creature card from your graveyard to your hand?", source, game) && firstPlayer.chooseTarget(Outcome.ReturnToHand, target, source, game)) {
        Card card = game.getCard(target.getFirstTarget());
        if (card != null) {
            firstPlayer.moveCards(card, Zone.HAND, source, game);
        }
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ObjectSourcePlayer(mage.filter.predicate.ObjectSourcePlayer) TargetPlayer(mage.target.TargetPlayer) FilterPlayer(mage.filter.FilterPlayer) FilterCreatureCard(mage.filter.common.FilterCreatureCard) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) Target(mage.target.Target) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) MageObject(mage.MageObject) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Example 13 with FilterCreatureCard

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

the class PatriarchsBiddingEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (controller != null && sourceObject != null) {
        Set<String> chosenTypes = new HashSet<>();
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            Choice typeChoice = new ChoiceCreatureType(sourceObject);
            if (!player.choose(Outcome.PutCreatureInPlay, typeChoice, game)) {
                continue;
            }
            String chosenType = typeChoice.getChoice();
            game.informPlayers(sourceObject.getLogName() + ": " + player.getLogName() + " has chosen " + chosenType);
            chosenTypes.add(chosenType);
        }
        List<SubType.SubTypePredicate> predicates = new ArrayList<>();
        for (String type : chosenTypes) {
            predicates.add(SubType.byDescription(type).getPredicate());
        }
        FilterCard filter = new FilterCreatureCard();
        filter.add(Predicates.or(predicates));
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                player.moveCards(player.getGraveyard().getCards(filter, game), Zone.BATTLEFIELD, source, game);
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) MageObject(mage.MageObject) FilterCard(mage.filter.FilterCard) FilterCreatureCard(mage.filter.common.FilterCreatureCard) ChoiceCreatureType(mage.choices.ChoiceCreatureType)

Example 14 with FilterCreatureCard

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

the class AmplifyEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    Permanent sourceCreature = ((EntersTheBattlefieldEvent) event).getTarget();
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null || sourceCreature == null) {
        return false;
    }
    FilterCreatureCard filter = new FilterCreatureCard("creatures cards to reveal");
    filter.add(new AmplifyPredicate(sourceCreature));
    // You can’t reveal this card or any other cards that are entering the battlefield at the same time as this card.
    filter.add(Predicates.not(new CardIdPredicate(source.getSourceId())));
    for (Permanent enteringPermanent : game.getPermanentsEntering().values()) {
        filter.add(Predicates.not(new CardIdPredicate(enteringPermanent.getId())));
    }
    if (controller.getHand().count(filter, source.getSourceId(), source.getControllerId(), game) <= 0) {
        return false;
    }
    if (!controller.chooseUse(outcome, "Reveal cards to Amplify?", source, game)) {
        return false;
    }
    TargetCardInHand target = new TargetCardInHand(0, Integer.MAX_VALUE, filter);
    if (controller.chooseTarget(outcome, target, source, game) && !target.getTargets().isEmpty()) {
        Cards cards = new CardsImpl();
        cards.addAll(target.getTargets());
        int amountCounters = cards.size() * amplifyFactor.getFactor();
        sourceCreature.addCounters(CounterType.P1P1.createInstance(amountCounters), source.getControllerId(), source, game);
        controller.revealCards(sourceCreature.getIdName(), cards, game);
    }
    return false;
}
Also used : Player(mage.players.Player) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Permanent(mage.game.permanent.Permanent) EntersTheBattlefieldEvent(mage.game.events.EntersTheBattlefieldEvent) TargetCardInHand(mage.target.common.TargetCardInHand) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) CardIdPredicate(mage.filter.predicate.mageobject.CardIdPredicate)

Example 15 with FilterCreatureCard

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

the class BenefactionOfRhonasEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (sourceObject != null && controller != null) {
        Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, 5));
        boolean creatureCardFound = false;
        boolean enchantmentCardFound = false;
        for (UUID cardId : cards) {
            Card card = game.getCard(cardId);
            if (card != null) {
                cards.add(card);
                if (card.isCreature(game)) {
                    creatureCardFound = true;
                }
                if (card.isEnchantment(game)) {
                    enchantmentCardFound = true;
                }
            }
        }
        if (!cards.isEmpty()) {
            controller.revealCards(sourceObject.getName(), cards, game);
            if ((creatureCardFound || enchantmentCardFound) && controller.chooseUse(Outcome.DrawCard, "Put a creature card and/or enchantment card into your hand?", source, game)) {
                TargetCard target = new TargetCard(Zone.LIBRARY, new FilterCreatureCard("creature card to put into your hand"));
                if (creatureCardFound && controller.chooseTarget(Outcome.DrawCard, cards, target, source, game)) {
                    Card card = cards.get(target.getFirstTarget(), game);
                    if (card != null) {
                        cards.remove(card);
                        controller.moveCards(card, Zone.HAND, source, game);
                    }
                }
                target = new TargetCard(Zone.LIBRARY, new FilterEnchantmentCard("enchantment card to put into your hand"));
                if (enchantmentCardFound && controller.chooseTarget(Outcome.DrawCard, cards, target, source, game)) {
                    Card card = cards.get(target.getFirstTarget(), game);
                    if (card != null) {
                        cards.remove(card);
                        controller.moveCards(card, Zone.HAND, source, game);
                    }
                }
            }
        }
        controller.moveCards(cards, Zone.GRAVEYARD, source, game);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) FilterCreatureCard(mage.filter.common.FilterCreatureCard) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) FilterEnchantmentCard(mage.filter.common.FilterEnchantmentCard) UUID(java.util.UUID) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) FilterEnchantmentCard(mage.filter.common.FilterEnchantmentCard) FilterCreatureCard(mage.filter.common.FilterCreatureCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Aggregations

FilterCreatureCard (mage.filter.common.FilterCreatureCard)69 Player (mage.players.Player)58 Card (mage.cards.Card)31 FilterCard (mage.filter.FilterCard)26 Permanent (mage.game.permanent.Permanent)22 UUID (java.util.UUID)17 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)17 TargetCard (mage.target.TargetCard)16 CardsImpl (mage.cards.CardsImpl)15 ManaValuePredicate (mage.filter.predicate.mageobject.ManaValuePredicate)15 TargetCardInGraveyard (mage.target.common.TargetCardInGraveyard)14 MageObject (mage.MageObject)13 OwnerIdPredicate (mage.filter.predicate.card.OwnerIdPredicate)10 Target (mage.target.Target)10 HashSet (java.util.HashSet)8 Cards (mage.cards.Cards)8 TargetCardInYourGraveyard (mage.target.common.TargetCardInYourGraveyard)7 Ability (mage.abilities.Ability)6 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)6 OneShotEffect (mage.abilities.effects.OneShotEffect)4